Included 12bit math for STM

Boost/VVT pins dont change if 0%
Change visual led clock to 4Hz
Change analog resolution to 10bits on STM32GENERIC core
This commit is contained in:
VitorBoss 2017-09-02 13:26:41 -03:00
parent 5721c9700b
commit 8af08a7209
5 changed files with 19 additions and 8 deletions

View File

@ -64,6 +64,8 @@ void initialiseAuxPWM()
currentStatus.boostDuty = 0; currentStatus.boostDuty = 0;
boostCounter = 0; boostCounter = 0;
#if defined(CORE_STM32) //Need to be initialised last due to instant interrupt #if defined(CORE_STM32) //Need to be initialised last due to instant interrupt
Timer1.setMode(2, TIMER_OUTPUT_COMPARE);
Timer1.setMode(3, TIMER_OUTPUT_COMPARE);
if(boost_pwm_max_count > 0) { Timer1.attachInterrupt(2, boostInterrupt);} if(boost_pwm_max_count > 0) { Timer1.attachInterrupt(2, boostInterrupt);}
if(vvt_pwm_max_count > 0) { Timer1.attachInterrupt(3, vvtInterrupt);} if(vvt_pwm_max_count > 0) { Timer1.attachInterrupt(3, vvtInterrupt);}
Timer1.resume(); Timer1.resume();
@ -152,7 +154,7 @@ void vvtControl()
static inline void boostInterrupt() //Most ARM chips can simply call a function static inline void boostInterrupt() //Most ARM chips can simply call a function
#endif #endif
{ {
if (boost_pwm_state) if ((boost_pwm_state) && (boost_pwm_target_value<=2))
{ {
BOOST_PIN_LOW(); // Switch pin to low BOOST_PIN_LOW(); // Switch pin to low
BOOST_TIMER_COMPARE = BOOST_TIMER_COUNTER + (boost_pwm_max_count - boost_pwm_cur_value); BOOST_TIMER_COMPARE = BOOST_TIMER_COUNTER + (boost_pwm_max_count - boost_pwm_cur_value);
@ -174,7 +176,7 @@ void vvtControl()
static inline void vvtInterrupt() //Most ARM chips can simply call a function static inline void vvtInterrupt() //Most ARM chips can simply call a function
#endif #endif
{ {
if (vvt_pwm_state) if ((vvt_pwm_state) && (vvt_pwm_target_value<=2))
{ {
VVT_PIN_LOW(); // Switch pin to low VVT_PIN_LOW(); // Switch pin to low
VVT_TIMER_COMPARE = VVT_TIMER_COUNTER + (vvt_pwm_max_count - vvt_pwm_cur_value); VVT_TIMER_COMPARE = VVT_TIMER_COUNTER + (vvt_pwm_max_count - vvt_pwm_cur_value);

View File

@ -194,6 +194,7 @@ void initialiseIdle()
idleInitComplete = configPage4.iacAlgorithm; //Sets which idle method was initialised idleInitComplete = configPage4.iacAlgorithm; //Sets which idle method was initialised
currentStatus.idleLoad = 0; currentStatus.idleLoad = 0;
#if defined(CORE_STM32) //Need to be initialised last due to instant interrupt #if defined(CORE_STM32) //Need to be initialised last due to instant interrupt
Timer1.setMode(4, TIMER_OUTPUT_COMPARE);
if(idle_pwm_max_count > 0) { Timer1.attachInterrupt(4, idleInterrupt);} //on first flash the configPage4.iacAlgorithm is invalid if(idle_pwm_max_count > 0) { Timer1.attachInterrupt(4, idleInterrupt);} //on first flash the configPage4.iacAlgorithm is invalid
Timer1.resume(); Timer1.resume();
#endif #endif

View File

@ -10,8 +10,14 @@ unsigned long percentage(byte, unsigned long);
//This is a dedicated function that specifically handles the case of mapping 0-1023 values into a 0 to X range //This is a dedicated function that specifically handles the case of mapping 0-1023 values into a 0 to X range
//This is a common case because it means converting from a standard 10-bit analog input to a byte or 10-bit analog into 0-511 (Eg the temperature readings) //This is a common case because it means converting from a standard 10-bit analog input to a byte or 10-bit analog into 0-511 (Eg the temperature readings)
#define fastMap1023toX(x, out_max) ( ((unsigned long)x * out_max) >> 10) #if defined(_VARIANT_ARDUINO_STM32_) //libmaple
//This is a new version that allows for out_min #define fastMap1023toX(x, out_max) ( ((unsigned long)x * out_max) >> 12)
#define fastMap10Bit(x, out_min, out_max) ( ( ((unsigned long)x * (out_max-out_min)) >> 10 ) + out_min) //This is a new version that allows for out_min
#define fastMap10Bit(x, out_min, out_max) ( ( ((unsigned long)x * (out_max-out_min)) >> 12 ) + out_min)
#else
#define fastMap1023toX(x, out_max) ( ((unsigned long)x * out_max) >> 10)
//This is a new version that allows for out_min
#define fastMap10Bit(x, out_min, out_max) ( ( ((unsigned long)x * (out_max-out_min)) >> 10 ) + out_min)
#endif
#endif #endif

View File

@ -42,6 +42,8 @@ void initialiseADC()
BIT_CLEAR(ADCSRA,ADPS1); BIT_CLEAR(ADCSRA,ADPS1);
BIT_CLEAR(ADCSRA,ADPS0); BIT_CLEAR(ADCSRA,ADPS0);
#endif #endif
#elif defined(ARDUINO_ARCH_STM32) //STM32GENERIC lib
analogReadResolution(10); //use 10bits for analog
#endif #endif
MAPcurRev = 0; MAPcurRev = 0;
MAPcount = 0; MAPcount = 0;

View File

@ -104,9 +104,6 @@ void oneMSInterval() //Most ARM chips can simply call a function
{ {
loop100ms = 0; //Reset counter loop100ms = 0; //Reset counter
BIT_SET(TIMER_mask, BIT_TIMER_10HZ); 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 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 lastRPM_100ms = currentStatus.RPM; //Record the current RPM for next calc
@ -118,6 +115,9 @@ void oneMSInterval() //Most ARM chips can simply call a function
{ {
loop250ms = 0; //Reset Counter loop250ms = 0; //Reset Counter
BIT_SET(TIMER_mask, BIT_TIMER_4HZ); BIT_SET(TIMER_mask, BIT_TIMER_4HZ);
#if defined(CORE_STM32) //debug purpose, only visal for running code
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
#endif
#if defined(CORE_AVR) #if defined(CORE_AVR)
//Reset watchdog timer (Not active currently) //Reset watchdog timer (Not active currently)