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

Change scheduler functionality to align with timing manager #392

Closed annikaolson closed 4 months ago

annikaolson commented 4 months ago

This PR addresses issues #391, #314, and #377. Previously, the scheduler ISR was triggered by the SysTick private timer in timer.c. This was initialized to a predetermined control rate, with the default at 10kHz - in other words, the scheduler would fire every 100 μs. The goal here was to instead synchronize the scheduler with the PWM carrier.

Two Scheduler Modes

There are now two modes for the scheduler source/functionality. This is user-configurable in usr/user_config.h by USER_CONFIG_ISR_SOURCE.

Mode 0

The scheduler runs the tasks (i.e. ISR is called to move out of the idle state) on every "trigger" assertion.

The user can change the PWM event qualifier (carrier high, low, or both) and the user ratio to change the control frequency of the tasks.

Mode 1

When none of the sensors are enabled, this mode operates the same as mode 0. When any sensors are enabled, the scheduler is synchronized with the sensors. The ISR is called when all of the sensors have completed their acquisition cycles (positive edge of all_done).

FPGA Changes

Sensors

https://github.com/Severson-Group/AMDC-Firmware/blob/47d34ecf31241087504ffe84d59e5e3b1ca63290/ip_repo/amdc_timing_manager_1.0/src/timing_manager.v#L207-L223

C-Code Changes

cmd_hw.c

To report the time, the code before was directly calling timing_manager_get_time_per_sensor(), but it is now using the statistics struct for each sensor. It's pulling the value (which is the most recent value), but the stats also hold the max, min, and mean value for each sensor time.

timing manager changes

scheduler changes

Block Design Changes

npetersen2 commented 4 months ago

Next step is @codecubepi manually resolving the merge conflicts in the .bd file, then we merge this and test the v1.3-staging branch in the lab.

codecubepi commented 4 months ago

I am going to close this PR, since its changes have been implemented in #397 (specifically commit bd8ae30).