USB serial transmits blocking ADC interrupts? (75000Hz -> ~74700Hz)

Status
Not open for further replies.

GDouglas

Active member
[Solved] USB serial affecting ADC interrupts?

Hello!

Teensy 3.2 running at 96Mhz, ADC in free running mode. Oversample count 1, conversion speed VERY_LOW_SPEED, sampling speed VERY_LOW_SPEED, resulting in a 75KHz math calculation.

Using a ring buffer in my ADC ISR.
Trying with both ADC library, and bypassing ADC library.

Frequency 75000 without USB streaming
When no USB data is occuring, it runs at almost exactly 75KHz (75000 samples a second, +/- 0.5)

Frequency 74950-74990 with USB serial streaming at 1.5 Mbits/second
Frequency 74600-74750 with USB serial streaming at 3 Mbits/second
However, when I stream USB data, the ADC frequency falls gradually, the more data I try to stream out of the USB port (using the Serial library)

Upon further diagnosis using micros(), I notice sometimes the time interval between two values exceeds 2/75000ths of a second -- which means missed ADC samples! So it appears that USB transmissions somehow block the ADC ISR for more than 2/75000th of a second. These interrupt-blockings seems to happen roughly once every 64 bytes written to the USB port, corresponding to the USB packet transmission.

This problem does not happen at 18.75Khz (oversample count 4) but I do see lots of jitter in time between interrupts coinciding at the same intervals, but not severe enough to reach 2/18750ths of a second.
 
Last edited:
Never mind, I found the problem.

A very carefully located pair of cli() / sei() needed to be added to one volatile variable shared in ISR/outside.

Needed even just to safely read a single line of code -- an integer readout counter. Funny how adding cli() / sei() around one line of code made a huge difference.

Now it's stable at the frequency I'm expecting.
 
You can (probably) solve this by changing the relative interrupt priorities. Give the ADC a higher priority (lower number = higher priority) interrupt setting.
 
Status
Not open for further replies.
Back
Top