Support FAN03 PWM with reduced frequency on m32a until m1284p port is finished
This commit is contained in:
@@ -93,15 +93,10 @@ int PWM_Init(void)
|
|||||||
OCR1B = FAN01_MIN_DUTY; // PD4
|
OCR1B = FAN01_MIN_DUTY; // PD4
|
||||||
OCR1A = FAN02_MIN_DUTY; // PD5
|
OCR1A = FAN02_MIN_DUTY; // PD5
|
||||||
|
|
||||||
// TIMER2: Fast mode, non-inverting, top=0xFF, prescale /8
|
// TIMER2: Fast mode, non-inverting, top=0xFF, prescale /1
|
||||||
// TOP set to 8000000 (f_cpu) / 8 (prescale) / 25000 (f_pwm) - 1
|
|
||||||
|
|
||||||
TCCR2 = BIT(WGM20) | BIT(WGM21) | BIT(COM21) | BIT(CS21);
|
TCCR2 = BIT(WGM20) | BIT(WGM21) | BIT(COM21) | BIT(CS20);
|
||||||
OCR2 = 255; // XXX: OCR2A=TOP OCR2B=duty
|
OCR2 = FAN03_MIN_DUTY;
|
||||||
|
|
||||||
// TCCR2 = 0; // Normal operation
|
|
||||||
// OCR2 = FAN03_MIN_DUTY; // PD7
|
|
||||||
// PORTD &= ~BIT(PD7); // Low
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -109,18 +104,20 @@ int PWM_Init(void)
|
|||||||
// Value in range 0-100 is expected
|
// Value in range 0-100 is expected
|
||||||
void PWM_SetValue(int port, int value)
|
void PWM_SetValue(int port, int value)
|
||||||
{
|
{
|
||||||
int n;
|
int n, m;
|
||||||
|
|
||||||
if (port != FAN01 && port != FAN02 && port != FAN03)
|
if (port != FAN01 && port != FAN02 && port != FAN03)
|
||||||
return; // Invalid port
|
return; // Invalid port
|
||||||
|
|
||||||
n = CLAMP(value, 100, 0) * (PWM_CYCLE_TOP / 100.0f);
|
// Workaround: Missing third 16-bit timer output
|
||||||
|
m = (port != FAN03) ? PWM_CYCLE_TOP : 0xFF;
|
||||||
|
n = CLAMP(value, 100, 0) * m / 100.0f;
|
||||||
|
|
||||||
Info("Setting duty cycle for %s to %d/%d...",
|
Info("Setting duty cycle for %s to %d/%d...",
|
||||||
(port == FAN01) ? "FAN01" :
|
(port == FAN01) ? "FAN01" :
|
||||||
(port == FAN02) ? "FAN02" :
|
(port == FAN02) ? "FAN02" :
|
||||||
(port == FAN03) ? "FAN03" :
|
(port == FAN03) ? "FAN03" :
|
||||||
"UNKNOWN", n, PWM_CYCLE_TOP);
|
"UNKNOWN", n, m);
|
||||||
|
|
||||||
switch (port) {
|
switch (port) {
|
||||||
case PD4: OCR1B = n; break;
|
case PD4: OCR1B = n; break;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#define PWM_CYCLE_TOP (F_CPU / 25000 - 1) // 8 MHz / 25 KHz
|
#define PWM_CYCLE_TOP (F_CPU / 25000 - 1) // 8 MHz / 25 KHz
|
||||||
#define FAN01_MIN_DUTY (PWM_CYCLE_TOP * 0.2f)
|
#define FAN01_MIN_DUTY (PWM_CYCLE_TOP * 0.2f)
|
||||||
#define FAN02_MIN_DUTY (PWM_CYCLE_TOP * 0.2f)
|
#define FAN02_MIN_DUTY (PWM_CYCLE_TOP * 0.2f)
|
||||||
#define FAN03_MIN_DUTY (PWM_CYCLE_TOP * 0.2f)
|
#define FAN03_MIN_DUTY (0xFF * 0.2f)
|
||||||
|
|
||||||
int PWM_Init(void);
|
int PWM_Init(void);
|
||||||
void PWM_SetValue(int port, int value);
|
void PWM_SetValue(int port, int value);
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ static int Init(void)
|
|||||||
|
|
||||||
PWM_SetValue(FAN01, 50); // Fan Peltier Hot side
|
PWM_SetValue(FAN01, 50); // Fan Peltier Hot side
|
||||||
PWM_SetValue(FAN02, 50); // Fan Peltier Cold Side
|
PWM_SetValue(FAN02, 50); // Fan Peltier Cold Side
|
||||||
// PWM_SetValue(FAN03, 20); // Fan Heating
|
PWM_SetValue(FAN03, 50); // Fan Heating
|
||||||
|
|
||||||
// The I2C_SetChannel command changes the channel
|
// The I2C_SetChannel command changes the channel
|
||||||
// setting of the PCA9546 I2C multiplexer. Any
|
// setting of the PCA9546 I2C multiplexer. Any
|
||||||
|
|||||||
Reference in New Issue
Block a user