Cleaner transitions when using VVT for on/off control

This commit is contained in:
Josh Stewart 2017-07-24 16:04:29 +10:00
parent 1da217eb40
commit bfc5c7c841
2 changed files with 30 additions and 4 deletions

View File

@ -6,6 +6,18 @@ void boostControl();
void vvtControl();
void initialiseFan();
#if defined(CORE_AVR)
#define ENABLE_BOOST_TIMER() TIMSK1 |= (1 << OCIE1A)
#define DISABLE_BOOST_TIMER() TIMSK1 &= ~(1 << OCIE1A)
#define ENABLE_VVT_TIMER() TIMSK1 |= (1 << OCIE1B)
#define DISABLE_VVT_TIMER() TIMSK1 &= ~(1 << OCIE1B)
#define BOOST_PIN_LOW() *boost_pin_port &= ~(boost_pin_mask)
#define BOOST_PIN_HIGH() *boost_pin_port |= (boost_pin_mask)
#define VVT_PIN_LOW() *vvt_pin_port &= ~(vvt_pin_mask)
#define VVT_PIN_HIGH() *vvt_pin_port |= (vvt_pin_mask)
#endif
volatile byte *boost_pin_port;
volatile byte boost_pin_mask;
volatile byte *vvt_pin_port;

View File

@ -106,11 +106,25 @@ void vvtControl()
if( configPage3.vvtEnabled == 1 )
{
byte vvtDuty = get3DTableValue(&vvtTable, currentStatus.TPS, currentStatus.RPM);
vvt_pwm_target_value = percentage(vvtDuty, vvt_pwm_max_count);
if(vvtDuty == 0)
{
//Make sure solenoid is off (0% duty)
VVT_PIN_LOW();
DISABLE_VVT_TIMER();
}
else if (vvtDuty >= 100)
{
//Make sure solenoid is on (100% duty)
VVT_PIN_HIGH();
DISABLE_VVT_TIMER();
}
else
{
vvt_pwm_target_value = percentage(vvtDuty, vvt_pwm_max_count);
ENABLE_VVT_TIMER();
}
}
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
else { TIMSK1 &= ~(1 << OCIE1B); } // Disable timer channel
#endif
else { DISABLE_VVT_TIMER(); } // Disable timer channel
}
//The interrupt to control the Boost PWM