cancel
Showing results for 
Search instead for 
Did you mean: 

How can I set the timer to trigger ADC on counter overflow?

NTosi
Associate III

Hi,

I have set the timer4 in center alligned mode 3 and I want to trigger ADC on counter overflow. If I understand correctly the ADC trigger input TIM4_TRGO can be set in timer configuration as update event output but that means also in underflow will send the timer a trigger for conversion.

Do you know any solution?

10 REPLIES 10
GwenoleB
ST Employee

Dear @NTosi​,

Indeed, ADC cannot differentiate a counter overflow or underflow as the trigger is common.

The UEV Update Event is set when an overflow or underflow occurs, then the trigger will be set also to the ADC.

To understand better your application, is there any reason you use the center aligned mode on TIM4?

Best Regards,

Gwénolé

Hi,

thank you for your reply. I try to implement a FOC algorithm and I have seen also some application notes from ST, in which they mentioned this process for better adc measuring.

GwenoleB
ST Employee

Hello,

Alright! Will be possible to provide the MCU reference you are using?

It could be useful to verify embedded features inside the TIM4.

Best Regards,

Gwénolé

Hi,

I use F446RE and my configurations is like TIM1 -> is a master with CH1 and CH1N also CH2 CH2N are used for the phase U and V. The TIM4 is the slave and is synchronized with TIM1 and is connected with phase W.

The TIM1 has the TRGO as a Counter Enabled output so I cannot use it for the PWM.

Right now I use the CH1N to trigger the ADC conversion but I have seen in STM application note that if I change to counter overflow I can have a better result.

best regards,

Nikos

GwenoleB
ST Employee

Hi,

Indeed two solutions exist:

  1. Trigger the ADC on OCxREF signal meaning that ADC trigger is 90° out of phase with Overflow flag
  2. Cascade a third timer to generate a trigger on ADC. This timer is a slave of the TIM1 also.

Below a scheme of how timers and ADC are interconnected


_legacyfs_online_stmicro_images_0693W00000bl91ZQAQ.png 

TIM1 & TIM4 are setup as center aligned 3 (Up and Down CNT).

TIM3 is setup as Up CNT where ARR = 2*(ARR_TIM1)-1. Be sure that ARR of TIM1 doesn't exceed 65536/2, else we recommend the usage of TIM2/5 (32-bit resolution).

Please note that:

  • TIM2/3/8 can be used to trigger ADC for regular conversion
  • TIM2/5 for injected conversion. For TIM5, it must be triggered by TIM4 CNT_EN in aid of TIM1


_legacyfs_online_stmicro_images_0693W00000bl92SQAQ.pngBlue --> PWM signal

Red --> End of ADC conversion (IO toggling)

As a result, ADC will be synchronized with Overflow of TIM1 & TIM4

Let me know if it's unclear or you need more clarification.

Best Regards,

Gwénolé

Thank you, top support!

I will test it the next days and I will be back to write the results.

best regards,

Nikos

Hi,

I need some more help please.

Which should be the Input trigger Signal from tim3 to ADC and which should be the output connected to TRGO for the timer 3?

I suppose to use Injected channels because the results is always available and I dont need the DMA to store the regular channel result in the memory.

I tried yesterday also a variant with Timer3 Ch2 as Compare output without the GPIO Connected and the ADC1 injected channels connected to trigger signal tim3_ch2 but ADC1 was not triggered.

King Regards,

Nikos

GwenoleB
ST Employee

Hello @NTosi​,

Will you able to share your ADC configuration? Based on this I will guide you on TIM configuration.

Nevertheless, using injected conversion requires the use of TIM2 or TIM5 in aid of TIM3 as depicted in my previous scheme.

In the Reference Manual, you will find the list of signals able to trigger the ADC in injected mode:


_legacyfs_online_stmicro_images_0693W00000dJq60QAC.pngAt least, you need to select a TIMx_TRGO event and not a TIMx_CHy event.

Anyway, feel free to share with your ADC configuration and I will help you with TIMER configuration.

Best Regards,

Gwénolé

Hi,

I made the changes and is working BUT not properly. The timer 1 has ARR = 500 and the timer 2 as you said ARR = 999 but the ADC will be triggered when the PWM output is HIGH. (I use tim2 because tim3 is occupied).

But this is not what I want, because in FOC algorithm the ADC Conversion should be start when the Low Side of the Bridge is high.

The first build is how I understand this and the second of the oscilloscope, the blue is the ADC interrupt and the other are the two synchronized timers.
_legacyfs_online_stmicro_images_0693W00000dJuUzQAK.png
_legacyfs_online_stmicro_images_0693W00000dJuDAQA0.png