60 likes | 165 Views
Project 4 – Multi-Rate. So, what’s new?!?! Similar set of tasks Will need to add Timer 1 configuration for 1 ms period to system_init () decode_buttons () will need to calculate a step_delay to achieve proper speed main() will check two SW counters for when to read buttons or take a step
E N D
Project 4 – Multi-Rate • So, what’s new?!?! Similar set of tasks • Will need to add Timer 1 configuration for 1 ms period to system_init() • decode_buttons() will need to calculate a step_delay to achieve proper speed • main() will check two SW counters for when to read buttons or take a step • Delay routine will poll T1IF until 1 ms expires, then decrement SW counters and toggle LED
Task Manager – While(1) • Checks button_delay counter. If zero, it calls read_buttons and decode_buttons, toggles LEDB, and resets the counter. • Checks step_delay counter. If zero, it calls the FSM and motor output functions, toggles LEDC, and resets the counter. Reset value will depend upon current step_delay value. • Calls Timer1_Delay
LED Behavior • LEDA toggles once per ms (2 ms period!) • LEDB toggles when buttons are read (100 ms) • LEDC toggles every step (speed/mode dependent based on buttons) “Some” flexibility on where certain LED toggle in the software.
Gotcha! • Two errors can lead to a task not executing • Avoid decrementing the counter past zero before the task manager detects it • Avoid resetting the counter before the task is performed