Setting number of samples for pwm averaging
-
Hello all,
I would like to know how many data points or what length of time the PWM output for a heater is being averaged over and how we can change that. I did see in another post that 20 seconds was mentioned as the running average period, but then I saw a few seconds being mentioned. It would be nice to have a more instantaneous PWM output that can be recorded.
For reference, I am talking about the "heat.heaters[].avgPWM" command.
I am using a Duet 2 Wifi running RRF 3.4.2rc1
Thanks in advance!
-
@badoobadoop the code is in file src/Heating/LocalHeater.cpp around line 480:
constexpr float avgFactor = HeatSampleIntervalMillis/(HeatPwmAverageTime * SecondsToMillis); averagePWM = (averagePWM * (1.0 - avgFactor)) + (lastPwm * avgFactor);
The two constants are defined in CANlib/src/RRF3Common.h like this:
constexpr uint32_t HeatSampleIntervalMillis = 250; // interval between taking temperature samples constexpr float HeatPwmAverageTime = 5.0; // Seconds
The intention is that the value reported for averagePWM is the instantaneous PWM value fed through a low pass filter with a time constant of 5 seconds.
-
@dc42 Thank you! That definitely makes sense. I appreciate the help!
-