AnsweredAssumed Answered

Spurious SAR trigger by Disabled timer

Question asked by iumez on Mar 11, 2015
Latest reply on Mar 12, 2015 by iumez
I'm setting up a process where a regular group of SAR conversions will be triggered by a timer. The SAR is configured to use DMA to transfer that data into a buffer. The buffer memory is actually organized into two buffers with the DMA half transfer and transfer complete interrupts used to signal main code which is currently the "read" buffer.

I've set up the SAR and verified that the conversions and DMA work correctly when software triggered. However, when I started testing automatic triggering from a timer, I ran into some strange behavior.

1. The first time, I accidentally specified the wrong trigger source (timer 19 TRGO instead of timer 3). My initialization code enables the timer 3 peripheral clock. I then set up the SAR and DMA, then configure timer 3 to trigger the SAR. In my SAR configuration, I noticed that as soon as I executed the line of code to write the trigger source, my buffer filled up with samples, with values that I'd expect, indicating that the regular group SAR conversions were occuring and as configured, DMA was transferring them to the buffer.

As a first step, I added code in the DMA ISR for that channel to toggle a pin to try and get an idea of what was going on. An LED validates it's running. I need to scope it and see if I can correlate the triggering to my timer config.

2. I correct the mistake (change configuring the SAR trigger to timer 3), and get to the timer 3 configuration. At the start of timer 3 configuration, I set the UDIS bit to guard against spurious triggers of the SAR while I make changes. However, when I use the CMSIS function to write the prescaler immediately (which generates an update event), I notice the same thing behavior - SAR conversions and DMA start running. However, according to the scope, the DMA ISR isn't running.

If I let the code finish the timer 3 configuration and enable timer 3, I'm then able to hit the DMA ISR.

3. As a temporary work around, I decided to try configuring the SAR trigger *after* timer 3 is up and running. Using the timer 3 ISR. Since the ISR doesn't trigger until the timer is actually enabled, I can use it to enable external triggering on the SAR and configure the trigger source. This time, the SAR conversions are never triggered(almost), even though the ADC registers all have the correct values. Why almost? Well, if I set a break point, and start poking around the registers in the debugger, at after some random interval, I'll notice the ADC status register value change. And if I go and take a look at the buffer, I'll see that conversions and DMA transfers are happening as expected. If I  then run, I'll hit the DMA ISR.

As a first pass, has anyone encountered something like this and has ideas on what's going wrong. I've confirmed this behavior on multiple prototype boards so I'm relatively sure it's not just an isolated defect with my microcontroller.

Outcomes