EdgePi-Cloud / edgepi-python-sdk

Python SDK to control EdgePi, an industrial PC/PLC/IoT device powered by Raspberry Pi CM4
MIT License
6 stars 3 forks source link

Improve performance of ADC reads #424

Closed EarthenSky closed 2 months ago

EarthenSky commented 2 months ago

Building on #423

Performance is improved by 19 times, from 105ms per 8 ADC reads, to 5.5ms per 8 ADC reads.

It's possible to improve the performance more than 160 hz for all 8 ADC, however 1/3 of all time is being spend sleeping, while another 1/3 is spent transferring data over SPI. It's unlikely to get faster than 200 hz. The speed improvements are due to bit optimizations, minimizing data sent over the channel, python optimizations, and batching of requests (minimize system calls opening & closing devices), all of which were found via profiling. For more info, see this (private) page in the wiki.

Main Changes

TODOs

EarthenSky commented 2 months ago

Trace of 1 ADC read (before): Screenshot 2024-08-15 164831

Trace of 8 ADC reads (optimized): Screenshot 2024-08-15 163008

github-actions[bot] commented 2 months ago

Code Coverage

Package Line Rate Branch Rate Health
adc 92% 87%
calibration 100% 100%
dac 100% 97%
digital_input 100% 91%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 69% 23%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3176 / 3457) 80% (680 / 845)