adafruit / Adafruit_CircuitPython_EMC2101

CircuitPython driver for EMC2101 brushless fan controller
MIT License
3 stars 9 forks source link

Scale fan setting to match `PWM_F` #20

Closed stoklund closed 2 years ago

stoklund commented 2 years ago

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.

pwm_f5.pdf

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.

ladyada commented 2 years ago

thanks! hopefully someone from the circuitpy community could test this PR and then we will merge

askpatrickw commented 2 years ago

@stoklund is this a fix for #19 ?

stoklund commented 2 years ago

@stoklund is this a fix for #19 ?

Yes