AlexT-38 / OpenGEET_ECU_firmware

Open GEET Engine Control Unit firmware
GNU General Public License v3.0
1 stars 0 forks source link

Update Record, Screen Draw, Log to SD and Log to Serial should be separate events. #12

Closed AlexT-38 closed 1 year ago

AlexT-38 commented 1 year ago

Problem

Currently, update record, screen draw, log to SD and log to serial are scheduled as a single task. Only 40ms are available to perform all these tasks.

Record updates are relatively trivial.

Screen draw currently takes about 10ms.

Serial writes currently take about 5ms, but could be as much as 20ms or more, depending on the number of sensors, sample rates, and output format.

SD card access, depending on the card, can take more than 40ms to complete. In practice, writes have been taking 30ms. Most of this time is spent waiting for the card to complete the write, but during this time, the SPI port is not available. The standard SD card library blocks during this time. Writing (or sourcing) a non blocking SD card library is beyond the scope of this project.

Solution

The task schedule is based on 10ms slots. There are four 40ms slots available per 500ms update cycle, only one is used for the update. This was to minimise static memory usage for timestamps on the UNO. With the MEGA's increased SRAM, there is no reason not to separate them into individual tasks.

More time

If more time is needed, most of the other tasks, including the one preceding the 40ms slots, take 1ms or less, and could have their schedules moved closer together to make the time slots for screen draw, log to serial and log to SD card longer, at least up to a maximum of 49ms. The limit is the most frequently scheduled event, which is the PID calculation every 50ms. A single PID calculation takes ~80us and is probably too long to safely run in a timer ISR (see ISR notes in issue #10). Otherwise, the available time for a single task could be increased to <80ms for two of the four 40ms slots (the other two being interrupted by thermocouple readings every 250ms).

AlexT-38 commented 1 year ago

At present, the longest SDcard write time was 53840ms. Some optimisation may be needed, see issue #7