diff --git a/src/main.c b/src/main.c index a880416..f2dd498 100644 --- a/src/main.c +++ b/src/main.c @@ -14,12 +14,13 @@ #define FAN02 PD5 // Fan Peltier Cold Side Speed #define HOT01 PD7 // Heating Temperature -#define FAN01_MIN_DUTY (320 * 0.2f) // 20% -#define FAN02_MIN_DUTY (320 * 0.2f) // 20% +#define PWM_CYCLE_TOP (F_CPU / 25000) // 25 KHz +#define FAN01_MIN_DUTY (PWM_CYCLE_TOP * 0.2f) +#define FAN02_MIN_DUTY (PWM_CYCLE_TOP * 0.2f) #define HOT01_MIN_DUTY 0 static void SetPinDefaults(void); -static void SetTWIChannel(int channel); +static void SetTwiChannel(int channel); static void SetMosState(int port, bool state); static void SetPwmValue(int port, int value); @@ -50,7 +51,7 @@ int main(void) SetPwmValue(FAN02, 50); SetPwmValue(HOT01, 0); - SetTWIChannel(0); // I2C Mux + SetTwiChannel(0); // I2C Mux Info("Running idle loop..."); @@ -92,14 +93,14 @@ static void SetPinDefaults(void) TCCR1A = BIT(WGM11) | BIT(COM1A1) | BIT(COM1B1); TCCR1B = BIT(WGM12) | BIT(WGM13) | BIT(CS10); TCCR2 = BIT(WGM20) | BIT(WGM21) | BIT(COM21) | BIT(CS20); - ICR1 = 320; // 8000 MHz / 25000 KHz + ICR1 = PWM_CYCLE_TOP; // 8000 MHz / 25000 KHz OCR1A = FAN01_MIN_DUTY; OCR1B = FAN02_MIN_DUTY; OCR2 = HOT01_MIN_DUTY; } -static void SetTWIChannel(int channel) +static void SetTwiChannel(int channel) { unsigned char crb; @@ -175,7 +176,7 @@ static void SetPwmValue(int port, int value) if (port != PD4 && port != PD5 && port != PD7) return; // Invalid port - n = CLAMP(value, 100, 0) * 3.6f; + n = CLAMP(value, 100, 0) * (PWM_CYCLE_TOP / 100.0f); Info("Setting PWM value to %d...", n); switch (port) {