UPD: Delay in main loop #138

- improvement on HAL_Delay() in main loop, see #138
- minor adjustments for namings
This commit is contained in:
EmanuelFeru
2021-03-12 17:54:03 +01:00
parent 7f4b922808
commit e73f0535d5
4 changed files with 14 additions and 9 deletions

View File

@ -63,7 +63,8 @@
* 0 - Default board type
* 1 - Alternate board type with different pin mapping for DCLINK, Buzzer and ON/OFF, Button and Charger
*/
#define BOARD_VARIANT 0 // change if board with alternate pin mapping
#define BOARD_VARIANT 0 // change if board with alternate pin mapping
// ######################## END OF BOARD VARIANT ###############################
// ############################### BATTERY ###############################
/* Battery voltage calibration: connect power source.
@ -298,7 +299,7 @@
#define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!
#endif
// #define ADC_CONNECTION_ALTERNATE // use to swap ADC inputs
// #define ADC_ALTERNATE_CONNECT // use to swap ADC inputs
// #define SUPPORT_BUTTONS_LEFT // use left sensor board cable for button inputs. Disable DEBUG_SERIAL_USART2!
// #define SUPPORT_BUTTONS_RIGHT // use right sensor board cable for button inputs. Disable DEBUG_SERIAL_USART3!
#endif
@ -505,7 +506,7 @@
#define SPEED_COEFFICIENT 16384 // 1.0f
#define STEER_COEFFICIENT 8192 // 0.5f Only active in Sideboard input
// #define ADC_CONNECTION_ALTERNATE // use to swap ADC inputs
// #define ADC_ALTERNATE_CONNECT // use to swap ADC inputs
// #define INVERT_R_DIRECTION // Invert rotation of right motor
// #define INVERT_L_DIRECTION // Invert rotation of left motor
// #define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuk or lcd) is used!

View File

@ -60,7 +60,7 @@ extern volatile adc_buf_t adc_buffer;
uint8_t buzzerFreq = 0;
uint8_t buzzerPattern = 0;
uint8_t buzzerCount = 0;
static uint32_t buzzerTimer = 0;
volatile uint32_t buzzerTimer = 0;
static uint8_t buzzerPrev = 0;
static uint8_t buzzerIdx = 0;

View File

@ -103,6 +103,7 @@ extern volatile uint16_t pwm_captured_ch2_value;
// Global variables set here in main.c
//------------------------------------------------------------------------
uint8_t backwardDrive;
extern volatile uint32_t buzzerTimer;
volatile uint32_t main_loop_counter;
int16_t batVoltageCalib; // global variable for calibrated battery voltage
int16_t board_temp_deg_c; // global variable for calibrated temperature in degrees Celsius
@ -157,6 +158,7 @@ static int16_t speed; // local variable for speed. -1000 to 10
static int32_t speedFixdt; // local fixed-point variable for speed low-pass filter
#endif
static uint32_t buzzerTimer_prev = 0;
static uint32_t inactivity_timeout_counter;
static MultipleTap MultipleTapBrake; // define multiple tap functionality for the Brake pedal
@ -207,7 +209,7 @@ int main(void) {
while(HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) { HAL_Delay(10); }
while(1) {
HAL_Delay(DELAY_IN_MAIN_LOOP); // delay in ms
if (buzzerTimer - buzzerTimer_prev > 16*DELAY_IN_MAIN_LOOP) { // 1 ms = 16 ticks buzzerTimer
readCommand(); // Read Command: input1[inIdx].cmd, input2[inIdx].cmd
calcAvgSpeed(); // Calculate average measured speed: speedAvg, speedAvgAbs
@ -524,7 +526,9 @@ int main(void) {
// HAL_GPIO_TogglePin(LED_PORT, LED_PIN); // This is to measure the main() loop duration with an oscilloscope connected to LED_PIN
// Update states
inIdx_prev = inIdx;
buzzerTimer_prev = buzzerTimer;
main_loop_counter++;
}
}
}

View File

@ -802,12 +802,12 @@ void calcInputCmd(InputStruct *in, int16_t out_min, int16_t out_max) {
void readInputRaw(void) {
#ifdef CONTROL_ADC
if (inIdx == CONTROL_ADC) {
#ifndef ADC_CONNECTION_ALTERNATE
#ifdef ADC_ALTERNATE_CONNECT
input1[inIdx].raw = adc_buffer.l_rx2;
input2[inIdx].raw = adc_buffer.l_tx2;
#else
input1[inIdx].raw = adc_buffer.l_tx2;
input2[inIdx].raw = adc_buffer.l_rx2;
#else
input1[inIdx].raw = adc_buffer.l_rx2;
input2[inIdx].raw = adc_buffer.l_tx2;
#endif
}
#endif