Fix for reverse PWM IAC valve setting not working

This commit is contained in:
Josh Stewart 2016-05-27 22:44:40 +10:00
parent fcde4cb28e
commit 0b82b120c5
2 changed files with 27 additions and 9 deletions

View File

@ -243,20 +243,38 @@ ISR(TIMER4_COMPC_vect)
{
if (idle_pwm_state)
{
*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.iacPWMdir == 0)
{
//Normal 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
}
else
{
//Reversed 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
}
OCR4C = TCNT4 + (idle_pwm_max_count - idle_pwm_cur_value);
if (configPage4.iacPWMdir == 0) { idle_pwm_state = false; }
else { idle_pwm_state = true; }
idle_pwm_state = false;
}
else
{
*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.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;
idle_pwm_cur_value = idle_pwm_target_value;
if (configPage4.iacPWMdir == 0) { idle_pwm_state = true; }
else { idle_pwm_state = false; }
idle_pwm_state = true;
}
}

2
math.h
View File

@ -76,7 +76,7 @@ unsigned long divu100(unsigned long n) {
//This is a relatively fast approximation of a percentage value.
unsigned long percentage(byte x, unsigned long y)
{
return divu100(y) * x;
return divu100(y * x);
}
#endif // MATH_H