cancel
Showing results for 
Search instead for 
Did you mean: 

ADC trigger on timer update

alexpabouct9
Associate II
Posted on August 27, 2013 at 11:24

Hello,

I'm currently working on a brushless motor control application and i'm in the process of implementing the current measuring of the three phases. In order to do so, I need to synchronise the ADC sampling with the PWM outputs in order to sample at the center of the PWM outputs (center aligned 2 mode).

Unfortunately cannot find a simple solution. From the datasheet i see that the ADC can be trigger by either the CC1-4 timer interrupts or the TRGO interrupt. However, from what i've read, the interrupt that that the ADC needs to trigger off of is the timer update interrupt (which is not in the list of available ADC triggers external triggers).

Am i understanding this correctly? I was expecting a straightforward solution as this is a common problem in any motor control application, which is one of the mains features of the advanced timers.

Thanks,

Alex

#stm3-adc-trigger
23 REPLIES 23
Posted on February 12, 2016 at 17:55

I'm not using HAL, you're on your own there.

The ADC triggers are tied to specific resources, if you use things for other applications this doesn't change the available connectivity, but might limit usability. Depending on how you are using the timer, you could still place capture/compare points on that timeline

The ADC allows different capture/compare points of the same timer so you can control the phase, not just the periodicity. Most likely you'd use two different ADC, and trigger them from different phase/angles of the same timer.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
r2s
Associate II
Posted on February 29, 2016 at 16:31

Hi Clive again

I have some doubts about the circular mode and the Dma burst this example ....

In this particular case, the Dma triggers an interrupt when the ''Fifo buffer'' is half full.

So as far as i undestand, in the background process, the fifo is refilled automatically every time the ADC has completed the conversion. The ''Dma Fifo buffer'' is filled with the ADC conversions and when it achieves its half capacity, the Dma triggers an interrupt. Is this correct?

When enabling the Circular Mode, can the  Burst mode be used ? I' ve checked some examples and i think it s not quite clear and i get confused.

Cube Example:

 hdma_adc.Init.Mode                = DMA_CIRCULAR;               

 hdma_adc.Init.Priority            = DMA_PRIORITY_HIGH;          

 hdma_adc.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;       

 hdma_adc.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_HALFFULL;

 hdma_adc.Init.MemBurst            = DMA_MBURST_SINGLE;       

This Example:

DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;      DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;

Thanks in advance

Sug!!!

PS: I know i'm alone with the Hal Cube but the reasonning here is the same... ''relation of the circular mode with the fifo mode''

shoaib
Associate II
Posted on March 07, 2016 at 16:48

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6Y7&d=%2Fa%2F0X0000000bqT%2FksTm2QYZxfrDyi9uljhy8OESyiiDof2vlEOHsacbdsY&asPdf=false
Posted on March 07, 2016 at 16:55

You aren't going to get 8 channels from 1 pin.

You don't configure the ADC in continuous mode if you are triggering it.

If you are triggering it from the timer, you don't start it in the timer, the connectivity/start is implied.

You need to use DMA for multiple channels.

You don't use the ADC IRQ as an EOC interrupt, you should use the DMA HT/TC interrupts to do that.

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

Thanks a lot for helping. one last thing is that how can i get 8KHz for all channels of adc?

TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

                TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

                TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

                TIM_TimeBaseStructure.TIM_Period = 2;

                TIM_TimeBaseStructure.TIM_Prescaler = 5000;                       // 168 MHz/4 = APB1 , APB1/5000 = 8.4 KHz for Timer 2 and ADC

                TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

                TIM_SelectOutputTrigger(TIM2,TIM_TRGOSource_Update);

                TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);

                TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update); // Timer2 will trigger ADC2: ADC_ExternalTrigConv_T2_TRGO

is it right to make 8 KHz for all channels?

Posted on March 07, 2016 at 17:30

Clearly the math doesn't work..

In your case all 8 channels will be sampled, one after another, at each trigger. ie 1x trigger, 8x samples

The Prescaler and Period values are N-1

You want to factor the division between the Prescaler and Period where the Precaler is the smaller value.

TIM2 would most likely be clocking at 84 MHz

84000000 / 8000 = 10500

ie simple factoring 1 * 10500

Prescaler = 1 - 1;

Period = 10500 - 1;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 07, 2016 at 17:39

You don't need the timer interrupt, the trigger is independent and doesn't need you to manually start the ADC

4 and 13 up examples

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/stm32f4%20adc%20dma%2014%20analog%20inputs&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=199]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2Fstm32f4%20adc%20dma%2014%20analog%20inputs&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=199

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

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6dZ&d=%2Fa%2F0X0000000bsF%2Fcvhd01NfXbt3owEXGpIMogOU_i5MxY7lvVmKMb1I7X4&asPdf=false
Posted on March 08, 2016 at 14:00

How can i see all 8 channels value that dma is receiving?

It would be in the memory array you specified to the DMA controller. The data is copied there in the background from the ADC. For HT/TC the buffer would need to be twice the size of the sample set, so you could manage the data in the inactive half without the content changing underneath you.

DMA = Direct Memory Access

Review the examples more carefully, understand them first, I'm not looking to fix everyone else's broken code.

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

@Community member​  200KHz x2 HT/TC at 1KHz. I don't understand how to calculate 1KHz and 500ms at HT?