Complete but untested boost and vvt
This commit is contained in:
parent
d5855eb7cd
commit
4d4cd29a19
|
@ -7,8 +7,11 @@ volatile byte vvt_pin_mask;
|
||||||
|
|
||||||
volatile bool boost_pwm_state;
|
volatile bool boost_pwm_state;
|
||||||
unsigned int boost_pwm_max_count; //Used for variable PWM frequency
|
unsigned int boost_pwm_max_count; //Used for variable PWM frequency
|
||||||
unsigned int boost_pwm_cur_value;
|
volatile unsigned int boost_pwm_cur_value;
|
||||||
|
unsigned int boost_pwm_target_value;
|
||||||
|
|
||||||
volatile bool vvt_pwm_state;
|
volatile bool vvt_pwm_state;
|
||||||
unsigned int vvt_pwm_max_count; //Used for variable PWM frequency
|
unsigned int vvt_pwm_max_count; //Used for variable PWM frequency
|
||||||
unsigned int vvt_pwm_cur_value;
|
volatile unsigned int vvt_pwm_cur_value;
|
||||||
|
unsigned int vvt_pwm_target_value;
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ void initialiseAuxPWM()
|
||||||
|
|
||||||
boost_pin_port = portOutputRegister(digitalPinToPort(pinBoost));
|
boost_pin_port = portOutputRegister(digitalPinToPort(pinBoost));
|
||||||
boost_pin_mask = digitalPinToBitMask(pinBoost);
|
boost_pin_mask = digitalPinToBitMask(pinBoost);
|
||||||
boost_pin_port = portOutputRegister(digitalPinToPort(pinBoost));
|
vvt_pin_port = portOutputRegister(digitalPinToPort(pinVVT_1));
|
||||||
boost_pin_mask = digitalPinToBitMask(pinBoost);
|
vvt_pin_mask = digitalPinToBitMask(pinVVT_1);
|
||||||
|
|
||||||
boost_pwm_max_count = 1000000L / (16 * configPage3.boostFreq * 2); //Converts the frequency in Hz to the number of ticks (at 16uS) it takes to complete 1 cycle. The x2 is there because the frequency is stored at half value (in a byte)
|
boost_pwm_max_count = 1000000L / (16 * configPage3.boostFreq * 2); //Converts the frequency in Hz to the number of ticks (at 16uS) it takes to complete 1 cycle. The x2 is there because the frequency is stored at half value (in a byte)
|
||||||
vvt_pwm_max_count = 1000000L / (16 * configPage3.vvtFreq * 2);; //Converts the frequency in Hz to the number of ticks (at 16uS) it takes to complete 1 cycle
|
vvt_pwm_max_count = 1000000L / (16 * configPage3.vvtFreq * 2);; //Converts the frequency in Hz to the number of ticks (at 16uS) it takes to complete 1 cycle
|
||||||
|
@ -41,7 +41,54 @@ void initialiseAuxPWM()
|
||||||
|
|
||||||
void boostControl()
|
void boostControl()
|
||||||
{
|
{
|
||||||
|
if(configPage3.boostEnabled)
|
||||||
|
{
|
||||||
|
byte boostDuty = get3DTableValue(&boostTable, currentStatus.TPS, currentStatus.RPM);
|
||||||
|
boost_pwm_target_value = percentage(boostDuty, boost_pwm_max_count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vvtControl()
|
||||||
|
{
|
||||||
|
if(configPage3.vvtEnabled)
|
||||||
|
{
|
||||||
|
byte vvtDuty = get3DTableValue(&vvtTable, currentStatus.TPS, currentStatus.RPM);
|
||||||
|
vvt_pwm_target_value = percentage(vvtDuty, vvt_pwm_max_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//The interrupt to control the Boost PWM
|
||||||
|
ISR(TIMER1_COMPA_vect)
|
||||||
|
{
|
||||||
|
if (boost_pwm_state)
|
||||||
|
{
|
||||||
|
*boost_pin_port &= ~(boost_pin_mask); // Switch pin to low
|
||||||
|
OCR1A = TCNT1 + (boost_pwm_max_count - boost_pwm_cur_value);
|
||||||
|
boost_pwm_state = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*boost_pin_port |= (boost_pin_mask); // Switch pin high
|
||||||
|
OCR1A = TCNT1 + boost_pwm_target_value;
|
||||||
|
boost_pwm_cur_value = boost_pwm_target_value;
|
||||||
|
boost_pwm_state = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//The interrupt to control the VVT PWM
|
||||||
|
ISR(TIMER1_COMPB_vect)
|
||||||
|
{
|
||||||
|
if (vvt_pwm_state)
|
||||||
|
{
|
||||||
|
*vvt_pin_port &= ~(vvt_pin_mask); // Switch pin to low
|
||||||
|
OCR1B = TCNT1 + (vvt_pwm_max_count - vvt_pwm_cur_value);
|
||||||
|
vvt_pwm_state = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*vvt_pin_port |= (vvt_pin_mask); // Switch pin high
|
||||||
|
OCR1B = TCNT1 + vvt_pwm_target_value;
|
||||||
|
vvt_pwm_cur_value = vvt_pwm_target_value;
|
||||||
|
vvt_pwm_state = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -360,7 +360,7 @@ byte pinSpareLOut3;
|
||||||
byte pinSpareLOut4;
|
byte pinSpareLOut4;
|
||||||
byte pinSpareLOut5;
|
byte pinSpareLOut5;
|
||||||
byte pinBoost;
|
byte pinBoost;
|
||||||
byte pinVVt_1; // vvt output 1
|
byte pinVVT_1; // vvt output 1
|
||||||
byte pinVVt_2; // vvt output 2
|
byte pinVVt_2; // vvt output 2
|
||||||
byte pinFan; // Cooling fan output
|
byte pinFan; // Cooling fan output
|
||||||
byte pinStepperDir; //Direction pin for the stepper motor driver
|
byte pinStepperDir; //Direction pin for the stepper motor driver
|
||||||
|
|
|
@ -506,6 +506,8 @@ void loop()
|
||||||
currentStatus.tpsADC = fastMap1023toX(analogRead(pinTPS), 0, 1023, 0, 255); //Get the current raw TPS ADC value and map it into a byte
|
currentStatus.tpsADC = fastMap1023toX(analogRead(pinTPS), 0, 1023, 0, 255); //Get the current raw TPS ADC value and map it into a byte
|
||||||
currentStatus.TPS = map(currentStatus.tpsADC, configPage1.tpsMin, configPage1.tpsMax, 0, 100); //Take the raw TPS ADC value and convert it into a TPS% based on the calibrated values
|
currentStatus.TPS = map(currentStatus.tpsADC, configPage1.tpsMin, configPage1.tpsMax, 0, 100); //Take the raw TPS ADC value and convert it into a TPS% based on the calibrated values
|
||||||
currentStatus.TPS_time = currentLoopTime;
|
currentStatus.TPS_time = currentLoopTime;
|
||||||
|
|
||||||
|
boostControl(); //Most boost tends to run at about 30Hz, so placing it here ensures a new target time is fetched at least that frequently
|
||||||
}
|
}
|
||||||
|
|
||||||
//The IAT and CLT readings can be done less frequently. This still runs about 4 times per second
|
//The IAT and CLT readings can be done less frequently. This still runs about 4 times per second
|
||||||
|
@ -546,6 +548,7 @@ void loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
idleControl(); //Perform any idle realted actions
|
idleControl(); //Perform any idle realted actions
|
||||||
|
vvtControl();
|
||||||
//END SETTING STATUSES
|
//END SETTING STATUSES
|
||||||
//-----------------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue