Skip to content

Timer with sub-microsecond accuracy #2146

Answered by earlephilhower
tomcombriat asked this question in Q&A
Discussion options

You must be logged in to vote

SYSTICK is already hooked for the cycle counter (there's only a 24-bit count OTW, the systick lets us keep an epoch and know the true cycles).

32K IRQs/second seems like a bad idea just in general. AIUI IRQ handling here is not very lightweight so you've got a lot of overhead on each one of those calls just to send 1 sample.

We use the DMA engine with timed transfers to send PWM audio output already, why not use that instead of rolling your own? Send in ping and pong buffers and the HW does all the work, only giving an IRQ when one buffer is free for the next one (which is also taken care of by the PWMAudio class).

And, obviously, having SYSCLK be an exact multiple of your desired output …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tomcombriat
Comment options

@earlephilhower
Comment options

Answer selected by tomcombriat
@tomcombriat
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants