STIMER Capture Operation Gotcha

I found some Artemis Apollo3 STIMER behavior that caught me by surprise, so I figured I would document it here so that Google can find it.

The issue is this: I had naively assumed that the STIMER capture was somewhat asynchronous to the STIMER counting. After all, the capture is spec’d to occur on a rising or falling edge of capture GPIO. Not so simple, as it turns out…

As background, I imagined that if the STIMER was set up to count at 1KHz, I could issue capture requests at a much higher rate, like say 16 KHz. Because I would be capturing 16 times faster than the STIMER would be counting, I was expecting my capture ISR to capture the same STIMER value N over and over again until the next STIMER tick whereupon I would capture the new STIMER value N+1 again over and over again, until the next increment.

Hoo boy, was I wrong. Instead of getting 16384 capture interrupts per second from my 16 KHz capture requests, I was getting like 5 of them.

After two days of head-scratching (OK, and maybe a few bad words), I figured out the capture GPIO is not really edge-triggered in the sense I was thinking, but more like a level-sensitive signal that gets periodically sampled at the STIMER clock rate. A capture signal can be driven high at any point in time, but the STIMER will not not recognize it or generate a capture interrupt until its next tick. That could be a long time off if the counter is configured to run slowly. It also means that your circuitry that generates a capture ‘edge’ needs to make sure that the ‘edge’ persists at its active level until the next STIMER clock.

I was seeing very few interrupts because my capture signal was gone by the next time that my 1KHz STIMER did its next tick. Increasing the speed of the STIMER caused the interrupts to occur in a more timely fashion. Sadly, it did not help me in my attempt to oversample the STIMER count using capture interrupts. That turns out to not be possible.

I hope this helps someone. I suppose I shouldn’t have assumed how the capture mechanism operated. But in all fairness, the details of how a capture event is recognized were not documented either. Onwards…