2016-11-08 07:53 AM
2016-11-08 08:49 AM
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.2016-11-08 09:07 AM
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,2016-11-08 09:28 AM
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.2016-11-09 03:37 AM
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,