From 8af08a720930896e6ac99dd44a5f86a347fbb4ae Mon Sep 17 00:00:00 2001 From: VitorBoss Date: Sat, 2 Sep 2017 13:26:41 -0300 Subject: [PATCH] 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 --- speeduino/auxiliaries.ino | 6 ++++-- speeduino/idle.ino | 1 + speeduino/maths.h | 12 +++++++++--- speeduino/sensors.ino | 2 ++ speeduino/timers.ino | 6 +++--- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/speeduino/auxiliaries.ino b/speeduino/auxiliaries.ino index 0eff9134..162798d3 100644 --- a/speeduino/auxiliaries.ino +++ b/speeduino/auxiliaries.ino @@ -64,6 +64,8 @@ void initialiseAuxPWM() currentStatus.boostDuty = 0; boostCounter = 0; #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(vvt_pwm_max_count > 0) { Timer1.attachInterrupt(3, vvtInterrupt);} Timer1.resume(); @@ -152,7 +154,7 @@ void vvtControl() static inline void boostInterrupt() //Most ARM chips can simply call a function #endif { - if (boost_pwm_state) + if ((boost_pwm_state) && (boost_pwm_target_value<=2)) { BOOST_PIN_LOW(); // Switch pin to low 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 #endif { - if (vvt_pwm_state) + if ((vvt_pwm_state) && (vvt_pwm_target_value<=2)) { VVT_PIN_LOW(); // Switch pin to low VVT_TIMER_COMPARE = VVT_TIMER_COUNTER + (vvt_pwm_max_count - vvt_pwm_cur_value); diff --git a/speeduino/idle.ino b/speeduino/idle.ino index 3670de16..0b8c3ec0 100644 --- a/speeduino/idle.ino +++ b/speeduino/idle.ino @@ -194,6 +194,7 @@ void initialiseIdle() idleInitComplete = configPage4.iacAlgorithm; //Sets which idle method was initialised currentStatus.idleLoad = 0; #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 Timer1.resume(); #endif diff --git a/speeduino/maths.h b/speeduino/maths.h index a1796e86..6c2760dc 100644 --- a/speeduino/maths.h +++ b/speeduino/maths.h @@ -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 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) -//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) +#if defined(_VARIANT_ARDUINO_STM32_) //libmaple + #define fastMap1023toX(x, out_max) ( ((unsigned long)x * out_max) >> 12) + //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 diff --git a/speeduino/sensors.ino b/speeduino/sensors.ino index 7057819c..bf847710 100644 --- a/speeduino/sensors.ino +++ b/speeduino/sensors.ino @@ -42,6 +42,8 @@ void initialiseADC() BIT_CLEAR(ADCSRA,ADPS1); BIT_CLEAR(ADCSRA,ADPS0); #endif +#elif defined(ARDUINO_ARCH_STM32) //STM32GENERIC lib + analogReadResolution(10); //use 10bits for analog #endif MAPcurRev = 0; MAPcount = 0; diff --git a/speeduino/timers.ino b/speeduino/timers.ino index b4ff21b3..70a7f9e8 100644 --- a/speeduino/timers.ino +++ b/speeduino/timers.ino @@ -104,9 +104,6 @@ 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 @@ -118,6 +115,9 @@ void oneMSInterval() //Most ARM chips can simply call a function { loop250ms = 0; //Reset Counter 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) //Reset watchdog timer (Not active currently)