0
votes

I'm working on a firmware development on a STM32L4. I need to sample an analog signal at around 200Hz. So basically one analog to digital conversion every 5ms.

Up to now, I was starting the ADC in continuous conversion mode, triggered by a timer. However this prevents to put the STM32 in Stop mode in between conversions, which would be very efficient in terms of power consumption since 99%+ ot the time the product has nothing to do.

So my idea is to use the single conversion mode: use a low power timer to wakeup the product from Stop mode every 5ms, launch a single conversion in the LPTIM interrupt handler (waiting for ADC end of conversion in polling), and go back to Stop mode.

Do you think it makes sense or do you see problems to proceed like this ? I'm not sure about polling for a single ADC conversion inside a handler, what do you think ? I think a single conversion on one channel should be pretty fast (I run at 80MHz, the datasheet mentions a maximum sampling time of 8us)

Do I have to disable/enable ADC (the bit ADEN) between each single conversion ?

Also, I have to know how long a single conversion lasts to assess whether the solution is interesting or not. I'm confused about the sampling time (bits SMP). The reference manual states: "This sampling time must be enough for the input voltage source to charge the embedded capacitor to the input voltage level." What is the way to find the right SMP value ?

1
Wakeup with the LPTIM should be totally ok. If you have a lot of other tasks running on your µC, an operating system should help in finding slots for stop mode.A.R.C.

1 Answers

1
votes

There are no problems with the general idea, LPTIM1 can generate wakeup events through the EXTI controller even in Stop2 mode.

I'm not sure about polling for a single ADC conversion inside a handler, what do you think ?

You might want to put the MCU in Sleep mode in the timer interrupt, and have the ADC trigger an interrupt when the conversion is complete. So disable SLEEPDEEP in the timer interrupt, and enable it in the ADC interrupt.

What is the way to find the right SMP value ?

Empirical method: start with the longest sampling time, and start decreasing it. When the conversion result significantly changes, go one or two steps back.