ec icon indicating copy to clipboard operation
ec copied to clipboard

Calculate `DCRi` using `CTR0`

Open crawfxrd opened this issue 1 year ago • 1 comments

The PWMi Duty Cycle output = (DCRi)/(CTR+1) If the DCRi value > CTR value, PWMi signal is still low. If DCRi value = CTR value, PWMi signal is still high.

Use Cycle Time Register to determine the PWM value that should be used for DCRi.

#define PWM_DUTY(X) ((uint8_t)(((((uint16_t)(X)) * 255) + 99) / 100))

255 (0xFF) here should be CTR0.

crawfxrd avatar Jul 02 '24 19:07 crawfxrd

The problem right now is that PWM_DUTY is used in the fan tables (__code), so it must be a fixed value (which obviously means it can't read from the register).

At the very least, a comment should be added that the 0xFF is the fixed value for CTR0, and that any change to CTR in pwm_init() must be updated here.

The "fix" would be to save the percentage in fan table, and apply the duty calculation at runtime using CTR0.

crawfxrd avatar Jul 08 '24 19:07 crawfxrd