Fix for reverse PWM IAC valve setting not working
This commit is contained in:
parent
fcde4cb28e
commit
0b82b120c5
28
idle.ino
28
idle.ino
|
@ -243,20 +243,38 @@ ISR(TIMER4_COMPC_vect)
|
||||||
{
|
{
|
||||||
if (idle_pwm_state)
|
if (idle_pwm_state)
|
||||||
{
|
{
|
||||||
|
if (configPage4.iacPWMdir == 0)
|
||||||
|
{
|
||||||
|
//Normal direction
|
||||||
*idle_pin_port &= ~(idle_pin_mask); // Switch pin to low (1 pin mode)
|
*idle_pin_port &= ~(idle_pin_mask); // Switch pin to low (1 pin mode)
|
||||||
if(configPage4.iacChannels) { *idle2_pin_port |= (idle2_pin_mask); } //If 2 idle channels are in use, flip idle2 to be the opposite of idle1
|
if(configPage4.iacChannels) { *idle2_pin_port |= (idle2_pin_mask); } //If 2 idle channels are in use, flip idle2 to be the opposite of idle1
|
||||||
OCR4C = TCNT4 + (idle_pwm_max_count - idle_pwm_cur_value);
|
|
||||||
if (configPage4.iacPWMdir == 0) { idle_pwm_state = false; }
|
|
||||||
else { idle_pwm_state = true; }
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//Reversed direction
|
||||||
*idle_pin_port |= (idle_pin_mask); // Switch pin high
|
*idle_pin_port |= (idle_pin_mask); // Switch pin high
|
||||||
if(configPage4.iacChannels) { *idle2_pin_port &= ~(idle2_pin_mask); } //If 2 idle channels are in use, flip idle2 to be the opposite of idle1
|
if(configPage4.iacChannels) { *idle2_pin_port &= ~(idle2_pin_mask); } //If 2 idle channels are in use, flip idle2 to be the opposite of idle1
|
||||||
|
}
|
||||||
|
OCR4C = TCNT4 + (idle_pwm_max_count - idle_pwm_cur_value);
|
||||||
|
idle_pwm_state = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (configPage4.iacPWMdir == 0)
|
||||||
|
{
|
||||||
|
//Normal direction
|
||||||
|
*idle_pin_port |= (idle_pin_mask); // Switch pin high
|
||||||
|
if(configPage4.iacChannels) { *idle2_pin_port &= ~(idle2_pin_mask); } //If 2 idle channels are in use, flip idle2 to be the opposite of idle1
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Reversed direction
|
||||||
|
*idle_pin_port &= ~(idle_pin_mask); // Switch pin to low (1 pin mode)
|
||||||
|
if(configPage4.iacChannels) { *idle2_pin_port |= (idle2_pin_mask); } //If 2 idle channels are in use, flip idle2 to be the opposite of idle1
|
||||||
|
}
|
||||||
OCR4C = TCNT4 + idle_pwm_target_value;
|
OCR4C = TCNT4 + idle_pwm_target_value;
|
||||||
idle_pwm_cur_value = idle_pwm_target_value;
|
idle_pwm_cur_value = idle_pwm_target_value;
|
||||||
if (configPage4.iacPWMdir == 0) { idle_pwm_state = true; }
|
idle_pwm_state = true;
|
||||||
else { idle_pwm_state = false; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
2
math.h
2
math.h
|
@ -76,7 +76,7 @@ unsigned long divu100(unsigned long n) {
|
||||||
//This is a relatively fast approximation of a percentage value.
|
//This is a relatively fast approximation of a percentage value.
|
||||||
unsigned long percentage(byte x, unsigned long y)
|
unsigned long percentage(byte x, unsigned long y)
|
||||||
{
|
{
|
||||||
return divu100(y) * x;
|
return divu100(y * x);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MATH_H
|
#endif // MATH_H
|
||||||
|
|
Loading…
Reference in New Issue