2013-08-27 02:24 AM
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-trigger2016-02-12 08:55 AM
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 timelineThe 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.2016-02-29 07:31 AM
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''2016-03-07 07:48 AM
2016-03-07 07:55 AM
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.2016-03-07 08:02 AM
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?2016-03-07 08:30 AM
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 samplesThe Prescaler and Period values are N-1You 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 MHz84000000 / 8000 = 10500ie simple factoring 1 * 10500Prescaler = 1 - 1;Period = 10500 - 1;2016-03-07 08:39 AM
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¤tviews=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=1992016-03-08 04:24 AM
2016-03-08 05:00 AM
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.2019-01-08 10:40 AM
@Community member 200KHz x2 HT/TC at 1KHz. I don't understand how to calculate 1KHz and 500ms at HT?