Severson-Group / AMDC-Firmware

Embedded system code (C and Verilog) which runs the AMDC Hardware
http://docs.amdc.dev/firmware
BSD 3-Clause "New" or "Revised" License
31 stars 5 forks source link

Add high priority task register function #273

Closed npetersen2 closed 2 years ago

npetersen2 commented 2 years ago

Resolves #272

After merging this PR, user control tasks should use: scheduler_tcb_register_high_priority(tcb) to help with jitter issues in the scheduler.

Bharat-Ramadas commented 2 years ago

I tested the set highest priority function on the AMDC. The below plots show a comparison of the loop and task timings before and after using the functions.

Previously, the priority assigned to different tasks in the AMDC was more or less random. As a result, cmd tasks, blink tasks etc. could potentially run at a higher priority than your timing critical control algorithm. This adds unnecessary jitter to the primary control task. The plot below shows how this manifests on the AMDC. ctrl_dt is the time taken by the AMDC to actually execute the code and loop_dt is the time between each task cycle. Ideally, ctrl_dt should be well below loop_dt (which is met in this test), and loop_dt should be constant throughout the test at 40 us (25 kHz). At around time = 0.2s, a command was send to the controller, causing a large spike in the loop time (expected value = 40 us). This, as well as the significant jitter under normal conditions as well is undesirable. timing_wo_pri

With the new set highest priority function, this issue is resolved. This can be clearly seen from the plot below. The test was conducted under the exact same conditions as the test above. Not only has the jitter under normal conditions been significantly reduced, we can also see that sending a command to the AMDC has virtually no effect on the control algorithm loop time. timing_with_pri

npetersen2 commented 2 years ago

@Bharat-Ramadas awesome, thanks for testing!