cancel
Showing results for 
Search instead for 
Did you mean: 

ADC multi mode operation. Please help :)

eergi
Associate II

I have a circuit, using stm32f100c6t, and there are 8 analog channels which I have to poll every 100 ms. one of the channels is rectified and filtered AC voltage, if this value is acceptable for operation, the circuit has a backup battery supply (lead acid, 12 volts) , and when the rectified value is greater than battery voltage, in every 5 minutes, I disconnect the battery from the system with a mosfet, and sink some current from the battery for 1 ms. this is for measuring the battery, if the battery is good, the current from the battery does not cause a sudden voltage drop, because the internal resistance of battery is low, some mili ohms. when the battery is bad, the voltage drop is more than 2 volts, and this means the battery is not reliable. the circuit turns on a led for signaling. I set the conversion for dma operation and 8 channels are scanned succesfully. when the 5 minute timer overflowed, I have to do a single scan for the battery connected to the an4 input via a voltage resistor. how can I interrupt the dma conversion and read a value for an4? the used channels are an1 thru an8. If the rectified ac voltage is low, that means the system is supplied by backup power source, and the health check should not run.

11 REPLIES 11
eergi
Associate II
  • I use cubemx and truestudio

Let the ADC be triggered and scan the 8 channels via DMA. This can be automated, and you can get a DMC TC interrupt indicating an EOC for all measurements. Synchronize secondary modes by selectively starting them in this interrupt.

Use "Injected" mode to read other channels as needed

Consider other F1 parts with more than 1 ADC if that's what you actually need.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
eergi
Associate II

I use HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) function after the conversion to fetch the values from dma buffer and process. the raw data is in 0-4095 range and should be scaled to actual voltage values. I trigger the dma operation with HAL_ADC_Start_IT(&hadc1); function and thera are some subroutines, which are taking more time than the conversion. I use the values after that subroutines are called. everything is ok. here. BUT, I do not know how to select adc channel4 and make the conversion manually. the hadc1 is generated by cubemx and initialized at the beginning. the continuous conversions are 8 , the ranks are defined in cubemx. I need to measure the and, which is the fourt one.

eergi
Associate II

it says

"Note: An example of firmware is provided with this application note: Indep_InjectedGroup" in the AN3116, but I can not find it, digging the internet....

S.Ma
Principal

Well on the F437 (probably the same IP in F100), you have normal and injected channels.

Use the DMA for the normal channels as a sequence which can be scanned in a single sequence manually or through a trigger event.

The injected channels are intended for "higher priority" channels. They do have their own data register for direct reading and they also provide programmable min/max range altert (interrupt)/

Injected channels scanned method is independent of normal ones. you can choose to run periodically the normal ones while the injected have different trigger method.

Try to use as much as possible the HW facilities to off-load the SW complexity.

Like this perhaps?

https://www.st.com/en/embedded-software/stsw-stm32028.html

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I opened the link and downloaded the zip file, in the main.c, there is a function "ADC_InjectedSequencerLengthConfig()" but this function is not exist in the stm32f1xx_hal_adc.c . also not exist in the example projects. there are settings in cubemx for injected conversion but no code in hal library. I use STM32CubeF1 Firmware Package V1.7.0 / 09-October-2018.

I think this one is not for hal library. or the hal library does not support injected conversion.

I found it, it is in stm32f1xx_hal_adc_ex.c file ;)