1
\$\begingroup\$

I have a project that outputs a series of values to DACs with a precise timing interval. The problem is that sometimes there is a delay longer than expected between the system timer interrupt in which the DAC values are updated. This leads to jitter in the output. I need help figuring out what is causing this delay. The only other user code running than the timer is handling of incoming USB packets containing the data to be output.

Things I have tried:

  • Decreasing the priority of every single interrupt other than the timer
  • Disabling any kind of sleep mode that might require time to wake up from
  • Decreasing the USB packet size to make them faster to process (though because of their interrupts having lower priority it shouldn't interfere with the timer anyway)

But nothing has worked so far.

The full code is here: https://github.com/Grix/helios_dac/blob/master/firmware/AtmelStudio_helios/lasdac_mainfirmware/src/main.c

The MCU is an Atmel ATSAM4S2B (32-bit arm cortex-m4)

Any ideas?

EDIT: I found the problem, it was the interrupt priorities. I set the priorities at bootup, however the CMSIS library SysTick_Config() function actually resets the priority for the systick every time it is called, so I had to manually correct the priority every time I called this.

\$\endgroup\$
  • 2
    \$\begingroup\$ Do you mean there is extra delay between consecutive system timer interrupts? Or that there is extra delay between the interrupt and something else occurring? How are you measuring the delay to be aware of the jitter? Consider toggling one or more GPIO pins throughout the code and use a logic analyzer to observe the toggles in real-time. Then adjust the toggle points to narrow in on the problem area until the source becomes clear. \$\endgroup\$ – kkrambo Jan 13 '17 at 12:30
  • 2
    \$\begingroup\$ If there is extra delay between consecutive system timer interrupts then is it possible that the previous interrupt handler does not finish before the next interrupt occurrence is asserted? The interrupt handler must not run longer than the period between interrupts. \$\endgroup\$ – kkrambo Jan 13 '17 at 12:32
  • 2
    \$\begingroup\$ @GrixM - Since you've found the problem (well done :-) ) please write an answer with those details (and accept it), instead of editing the answer into the question. Accepting an answer will mark the question as "answered" and you'll gain points for the answer too. \$\endgroup\$ – SamGibson Jan 24 '17 at 16:23
3
\$\begingroup\$

I found the problem, it was the interrupt priorities after all. I set the priorities at bootup, however the CMSIS library SysTick_Config() function actually resets the priority for the systick every time it is called, so I had to manually correct the priority every time after I called this.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.