Work on boost/vvt and timers for STM32
This commit is contained in:
parent
94e0c6c19c
commit
1defafb387
|
@ -81,6 +81,9 @@ volatile bool vvt_pwm_state;
|
|||
unsigned int vvt_pwm_max_count; //Used for variable PWM frequency
|
||||
volatile unsigned int vvt_pwm_cur_value;
|
||||
long vvt_pwm_target_value;
|
||||
|
||||
#if defined (CORE_TEENSY) || defined(CORE_STM32)
|
||||
static inline void boostInterrupt();
|
||||
static inline void vvtInterrupt();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,9 +40,9 @@ void initialiseAuxPWM()
|
|||
#elif defined(CORE_TEENSY)
|
||||
//REALLY NEED TO DO THIS!
|
||||
#elif defined(CORE_STM32)
|
||||
Timer1.attachInterrupt(2, boostControl);
|
||||
Timer1.attachInterrupt(3, vvtControl);
|
||||
Timer1.resume();
|
||||
Timer1.attachInterrupt(2, boostInterrupt);
|
||||
Timer1.attachInterrupt(3, vvtInterrupt);
|
||||
Timer1.resume();
|
||||
#endif
|
||||
|
||||
boost_pin_port = portOutputRegister(digitalPinToPort(pinBoost));
|
||||
|
|
|
@ -86,6 +86,8 @@ static inline void enableIdle();
|
|||
static inline byte isStepperHomed();
|
||||
static inline byte checkForStepping();
|
||||
static inline void doStep();
|
||||
static inline void idleInterrupt();
|
||||
#if defined (CORE_TEENSY) || defined(CORE_STM32)
|
||||
static inline void idleInterrupt();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -79,8 +79,8 @@ void initialiseIdle()
|
|||
}
|
||||
|
||||
#elif defined(CORE_STM32)
|
||||
Timer1.attachInterrupt(4, idleInterrupt);
|
||||
Timer1.resume();
|
||||
Timer1.attachInterrupt(4, idleInterrupt);
|
||||
Timer1.resume();
|
||||
#endif
|
||||
|
||||
//Initialising comprises of setting the 2D tables with the relevant values from the config pages
|
||||
|
|
|
@ -161,11 +161,11 @@ void initialiseSchedulers()
|
|||
NVIC_ENABLE_IRQ(IRQ_FTM1);
|
||||
|
||||
#elif defined(CORE_STM32)
|
||||
Timer1.setPeriod(2); //2us resolution
|
||||
Timer2.setPeriod(2); //2us resolution
|
||||
Timer3.setPeriod(2); //2us resolution
|
||||
#if defined(ARDUINO_ARCH_STM32) // STM32GENERIC core
|
||||
//see https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444
|
||||
Timer1.setPrescaleFactor((HAL_RCC_GetHCLKFreq() * 2U)-1); //2us resolution
|
||||
Timer2.setPrescaleFactor((HAL_RCC_GetHCLKFreq() * 2U)-1); //2us resolution
|
||||
Timer3.setPrescaleFactor((HAL_RCC_GetHCLKFreq() * 2U)-1); //2us resolution
|
||||
Timer2.setMode(1, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(2, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(3, TIMER_OUTPUT_COMPARE);
|
||||
|
@ -179,6 +179,11 @@ void initialiseSchedulers()
|
|||
|
||||
#else //libmaple core aka STM32DUINO
|
||||
//see https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/754bc2969921f1ef262bd69e7faca80b19db7524/STM32F1/system/libmaple/include/libmaple/timer.h#L444
|
||||
//(CYCLES_PER_MICROSECOND == 72, APB2 at 72MHz, APB1 at 36MHz).
|
||||
//Timer2 to 4 is on APB1, Timer1 on APB2. http://www.st.com/resource/en/datasheet/stm32f103cb.pdf sheet 12
|
||||
Timer1.setPrescaleFactor((72 * 2U)-1); //2us resolution
|
||||
Timer2.setPrescaleFactor((36 * 2U)-1); //2us resolution
|
||||
Timer3.setPrescaleFactor((36 * 2U)-1); //2us resolution
|
||||
Timer2.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(TIMER_CH2, TIMER_OUTPUT_COMPARE);
|
||||
Timer2.setMode(TIMER_CH3, TIMER_OUTPUT_COMPARE);
|
||||
|
|
|
@ -157,15 +157,15 @@ void setup()
|
|||
doUpdates(); //Check if any data items need updating (Occurs ith firmware updates)
|
||||
|
||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3
|
||||
if (configPage10.enable_canbus == 1) { Serial3.begin(115200); }
|
||||
if (configPage10.enable_canbus == 1) { CANSerial.begin(115200); }
|
||||
#elif defined(CORE_STM32)
|
||||
if (configPage10.enable_canbus == 1) { Serial2.begin(115200); }
|
||||
if (configPage10.enable_canbus == 1) { CANSerial.begin(115200); }
|
||||
else if (configPage10.enable_canbus == 2)
|
||||
{
|
||||
//enable local can interface
|
||||
}
|
||||
#elif defined(CORE_TEENSY)
|
||||
if (configPage10.enable_canbus == 1) { Serial2.begin(115200); }
|
||||
if (configPage10.enable_canbus == 1) { CANSerial.begin(115200); }
|
||||
else if (configPage10.enable_canbus == 2)
|
||||
{
|
||||
//Teensy onboard CAN not used currently
|
||||
|
@ -1122,7 +1122,6 @@ void loop()
|
|||
if (currentStatus.hasSync && (currentStatus.RPM > 0))
|
||||
{
|
||||
if(currentStatus.startRevolutions >= configPage2.StgCycles) { ignitionOn = true; fuelOn = true;} //Enable the fuel and ignition, assuming staging revolutions are complete
|
||||
else { ignitionOn = false; fuelOn = false;}
|
||||
//If it is, check is we're running or cranking
|
||||
if(currentStatus.RPM > ((unsigned int)configPage2.crankRPM * 100)) //Crank RPM stored in byte as RPM / 100
|
||||
{
|
||||
|
|
|
@ -503,7 +503,7 @@ float get3DTableValueF(struct table3D *fromTable, int Y, int X)
|
|||
}
|
||||
return tableResult;
|
||||
}
|
||||
*/
|
||||
|
||||
//This function pulls a value from a 3D table given a target for X and Y coordinates.
|
||||
//It performs a 2D linear interpolation as descibred in: http://www.megamanual.com/v22manual/ve_tuner.pdf
|
||||
int get3DTableValueS(struct table3D *fromTable, int Y, int X)
|
||||
|
@ -605,4 +605,4 @@ int get3DTableValueS(struct table3D *fromTable, int Y, int X)
|
|||
}
|
||||
return tableResult;
|
||||
}
|
||||
|
||||
*/
|
||||
|
|
|
@ -47,6 +47,9 @@ void initialiseTimers()
|
|||
Timer4.resume(); //Start Timer
|
||||
#endif
|
||||
|
||||
#if defined(CORE_STM32)
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
#endif
|
||||
dwellLimit_uS = (1000 * configPage2.dwellLimit);
|
||||
lastRPM_100ms = 0;
|
||||
}
|
||||
|
@ -100,6 +103,9 @@ void oneMSInterval() //Most ARM chips can simply call a function
|
|||
{
|
||||
loop100ms = 0; //Reset counter
|
||||
BIT_SET(TIMER_mask, BIT_TIMER_10HZ);
|
||||
#if defined(CORE_STM32) //debug purpose, only visal for running code
|
||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
||||
#endif
|
||||
|
||||
currentStatus.rpmDOT = (currentStatus.RPM - lastRPM_100ms) * 10; //This is the RPM per second that the engine has accelerated/decelleratedin the last loop
|
||||
lastRPM_100ms = currentStatus.RPM; //Record the current RPM for next calc
|
||||
|
|
|
@ -196,11 +196,11 @@ void setPinMapping(byte boardID)
|
|||
pinCoil3 = 30;
|
||||
pinO2 = A22;
|
||||
#elif defined(STM32F4)
|
||||
pinInjector1 = PE11; //Output pin injector 1 is on
|
||||
pinInjector2 = PE12; //Output pin injector 2 is on
|
||||
pinInjector3 = PE13; //Output pin injector 3 is on
|
||||
pinInjector4 = PE14; //Output pin injector 4 is on
|
||||
pinInjector5 = PE15; //Output pin injector 4 is on
|
||||
pinInjector1 = PE7; //Output pin injector 1 is on
|
||||
pinInjector2 = PE8; //Output pin injector 2 is on
|
||||
pinInjector3 = PE9; //Output pin injector 3 is on
|
||||
pinInjector4 = PE10; //Output pin injector 4 is on
|
||||
pinInjector5 = PE11; //Output pin injector 5 is on
|
||||
pinCoil1 = PB10; //Pin for coil 1
|
||||
pinCoil2 = PB11; //Pin for coil 2
|
||||
pinCoil3 = PB12; //Pin for coil 3
|
||||
|
@ -224,6 +224,8 @@ void setPinMapping(byte boardID)
|
|||
pinFlex = PC4; // Flex sensor (Must be external interrupt enabled)
|
||||
pinTrigger = PC5; //The CAS pin
|
||||
pinTrigger2 = PC6; //The Cam Sensor pin
|
||||
pinBoost = PE0; //Boost control
|
||||
pinVVT_1 = PE1; //Default VVT output
|
||||
#elif defined(CORE_STM32)
|
||||
//http://docs.leaflabs.com/static.leaflabs.com/pub/leaflabs/maple-docs/0.0.12/hardware/maple-mini.html#master-pin-map
|
||||
//pins 23, 24 and 33 couldn't be used
|
||||
|
@ -254,6 +256,8 @@ void setPinMapping(byte boardID)
|
|||
pinTrigger = 25; //The CAS pin
|
||||
pinTrigger2 = 22; //The Cam Sensor pin
|
||||
pinBaro = pinMAP;
|
||||
pinBoost = 1; //Boost control
|
||||
pinVVT_1 = 0; //Default VVT output
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in New Issue