fossasia / pslab-firmware

Firmware for PSLab Open Hardware Platform https://pslab.io
Apache License 2.0
1.56k stars 76 forks source link

Fix slow oscilloscope #139

Closed bessman closed 2 years ago

bessman commented 2 years ago

This fixes a bug with the oscilloscope I've been trying to fix for months. It turned out to be caused by two separate things, making it hard to nail down.

  1. When building with -O0, the ADC1_Interrupt* functions were not being inlined, which caused significant call overhead. I've added a warning in the ISR documentation explaining this. An alternative solution would be to #define the functions instead of making them static inlines.
  2. The legacy firmware uses a nested if clause to collect samples from different channels, which is super ugly so I replaced it with a for loop. Turns out the for loop is also much slower, so I had to change it back to the nested if. Bleh.

Also, while triaging this I noticed that the LED toggling actually slows down the oscilloscope by a measurable amount. It's very very little, but not nothing. Maybe don't toggle it during sample collection? Note to self: Discuss during next meeting,