/**************************************************************************** Module ESC_Control pseudo code /*----------------------------- Module Defines ----------------------------*/ #define NORMAL_OPERATION //#define TESTING_SUPPLY #define ENTRY_STATE SUPPLY_WAITING #define TWO_SEC 2000 #define TEN_MS 10 #define THIRTY_MS 30 #define THREE_SEC 3000 #define HALF_SEC 500 #define MAX_BALL_RECEIVED 4 #define COMPETITION_FULL_DUTY 75 #define CORRECTION_FULL_DUTY 55 /*---------------------------- Module Variables ---------------------------*/ init flags for different timers init pulse counter init flag to indicate whether supply LED is on init timer lengths for various milisecond values init a counter variable and valid count flag init flags for whether PWM lines for R/L are high init offsets and bounds for the PWM signal based on tested max/min duties init variables to keep track of the current timeouts for R/L uint32_t GetOneShotTimeOut(int input_us){ return (CLOCK_RATE*input_us)/1000000; } void InitOneShotInt_ESC_Left(void){ start by enabling the clock to the timer (Wide Timer 4) kill a few cycles to let the clock get going make sure that timer (Timer B) is disabled before configuring set it up in 32bit wide (individual, not concatenated) mode set up timer B in 1-shot mode so that it disables timer on timeouts first mask off the TAMR field (bits 0:1) then set the value for 1-shot mode = 0x01 set timeout enable a local timeout interrupt. TBTOIM = bit 8 enable the Timer B in Wide Timer 0 interrupt in the NVIC it is interrupt number 103 so appears in EN3 at bit 1 make sure interrupts are enabled globally now kick the timer off by enabling it and enabling the timer to stall while stopped by the debugger. TAEN = Bit0, TASTALL = bit1 print debugging message "Finished init one shot for Left Fan ESC" SetCurrentTimeout_Left(0.8); StartOneShot_ESC_10ms_Left(); } void StartOneShot_ESC_Left(uint32_t input){ start by grabbing the start time now kick the timer off by enabling it and enabling the timer to stall while stopped by the debugger } void StartOneShot_ESC_10ms_Left( void ){ start by grabbing the start time now kick the timer off by enabling it and enabling the timer to --> stall while stopped by the debugger } void StartOneShot_ESC_30ms_Left( void ){ start by grabbing the start time now kick the timer off by enabling it and enabling the timer to --> stall while stopped by the debugger } void OneShotIntResponse_ESC_Left( void ){ start by clearing the source of the interrupt if left PWM is in the high state set pin High call StartOneShot_ESC_Left using 20ms timeout - CurrentTimeout_left set high_state_left flag to false else set pin Low call StartOneShot_ESC_Left using CurrentTimeout_left set high_state_left flag to true } void SetCurrentTimeout_Left(float input_ms){ set CurrentTimeout_left to the correct # clock cycles based on milisecond input } /*****************************************************************************************/ void InitOneShotInt_ESC_Right( void ){ start by enabling the clock to the timer (Wide Timer 5) kill a few cycles to let the clock get going make sure that timer (Timer B) is disabled before configuring set it up in 32bit wide (individual, not concatenated) mode set up timer B in 1-shot mode so that it disables timer on timeouts first mask off the TAMR field (bits 0:1) then set the value for 1-shot mode = 0x01 set timeout enable a local timeout interrupt. TBTOIM = bit 8 enable the Timer B in Wide Timer 5 interrupt in the NVIC it is interrupt number 105 so appears in EN3 at bit 9 make sure interrupts are enabled globally now kick the timer off by enabling it and enabling the timer to stall while stopped by the debugger. TAEN = Bit0, TASTALL = bit1 print debugging message "Finished init one shot for Right Fan ESC" SetCurrentTimeout_Right(0.8); StartOneShot_ESC_10ms_Right(); } void StartOneShot_ESC_Right(uint32_t input){ start by grabbing the start time now kick the timer off by enabling it and enabling the timer to stall while stopped by the debugger } void StartOneShot_ESC_10ms_Right( void ){ start by grabbing the start time now kick the timer off by enabling it and enabling the timer to stall while stopped by the debugger void StartOneShot_ESC_30ms_Right( void ){ start by grabbing the start time now kick the timer off by enabling it and enabling the timer to stall while stopped by the debugger } void OneShotIntResponse_ESC_Right( void ){ start by clearing the source of the interrupt if right PWM is in the high state set pin High call StartOneShot_ESC_Left using 20ms timeout - CurrentTimeout_right set high_state_right flag to false else set pin Low call StartOneShot_ESC_Right using CurrentTimeout_right set high_state_right flag to true } void SetCurrentTimeout_Right(float input_ms){ set CurrentTimeout_right to the correct # clock cycles based on milisecond input }