When converting a fan speed percentage to an LSB byte written to the EMC2101 controller, the conversion should translate 100% to 2*PWM_F because the chip determines the PWM duty cycle that way.
The changes in this PR calculate and cache the byte value to use for 100% fan speed in the function _calculate_full_speed(). This cached full speed value is recomputed whenever emc.pwm_frequency or emc.dac_output_enabled are changed — these are the two registers affecting the value.
When setting emc.manual_fan_speed or one of the LUT values, the cached full speed value is used to compute the byte to be programmed into the chip. This means that emc.pwm_frequency should always be set before programming the LUT or manual speed setting.
My new oscilloscope arrived today (yay!), so I was able to test this code by measuring the duty cycle on the FAN pin. I tested 10% fan speed increments both with the default PWM frequency, and with PWM_F=5 which produces a 35 kHz PWM signal.
Both PWM frequencies plot as a straight line. At 35 kHz, I measured a duty cycle about 0.75% less that the programmed value. I think this is caused by the 1 µs rise time on the open drain FAN pin.
When converting a fan speed percentage to an LSB byte written to the EMC2101 controller, the conversion should translate 100% to 2*PWM_F because the chip determines the PWM duty cycle that way.
The changes in this PR calculate and cache the byte value to use for 100% fan speed in the function
_calculate_full_speed()
. This cached full speed value is recomputed wheneveremc.pwm_frequency
oremc.dac_output_enabled
are changed — these are the two registers affecting the value.When setting
emc.manual_fan_speed
or one of the LUT values, the cached full speed value is used to compute the byte to be programmed into the chip. This means thatemc.pwm_frequency
should always be set before programming the LUT or manual speed setting.My new oscilloscope arrived today (yay!), so I was able to test this code by measuring the duty cycle on the FAN pin. I tested 10% fan speed increments both with the default PWM frequency, and with
PWM_F=5
which produces a 35 kHz PWM signal.Both PWM frequencies plot as a straight line. At 35 kHz, I measured a duty cycle about 0.75% less that the programmed value. I think this is caused by the 1 µs rise time on the open drain FAN pin.