cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 Signal Sensing with ADC

ast8346
Associate II
Posted on November 08, 2016 at 16:53

The original post was too long to process during our migration. Please click on the attachment to read the original post.
4 REPLIES 4
Posted on November 08, 2016 at 17:49

When posting code like this, please post enough so it compiles.

Several things I'd perhaps do differently. Consider checking the states in the IRQ Handler, and using a WFI in the loop so it isn't grinding. The way you are currently looping you could use the ADC in continuous mode.

The primary problem is that you aren't using DMA in circular mode, if you don't do that then you need to reinitialize the DMA at each iteration. As you are manually triggering, circular mode will work as your code is expecting.

Consider outputting diagnostic information to a serial port to monitor the device state and readings.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ast8346
Associate II
Posted on November 08, 2016 at 18:07

Hi,

I have reorganised the code so it fits into the main function.

The only thing that will stop it from working now is the absence of main.h that contains definitions for LEDs and etc.

I tried setting ADC to continuous mode and DMA in circular mode, but something did not work well and it wasn't updating variables in the DMA.   

I wasn't aware IRQ handler can be used to check states, how do I do that? Also, what is WFI?

Many Thanks,

Posted on November 08, 2016 at 18:28

ADC_flag should be volatile, you're changing it in the IRQ

You could add your high/low threshold code in the handler, instead of the ADC_flag. Originally you had these as separate functions, ie

Temperature_read();

Signal_sense_read();

WFI - Wait For Interrupt, often __WFI(); There is no point spinning the loop unless something has changed, the DMA IRQ would have needed to have occurred.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ast8346
Associate II
Posted on November 09, 2016 at 12:37

Hi clive1,

I have enabled continuous mode of the ADC and circular mode of the DMA and the code seems to work now. I have updated the code in the top message, please have a look.

However, it still appears to be necessary to use ADC_restart() which I find strange. Both DMA and ADC need to be restarted in this loop. Commenting any of the lines out in this function prevents the whole code from working. What do you think may be wrong or is this correct?

Many Thanks,