2018-05-11 11:57 AM
I'm using TIM2 as a PWM. I have an (periodic) external signal that should reset the TIM2 counter to zero, so that the PWM is synchronized to the external signal. In a previous naive setup, I used the external signal to generate an interrupt (EXTI), and reset the counter in software (TIM2->CNT = 0). There is too much latency (and lack of determinism) in this approach so I would like to use the input signal to perform a hardware timer clear.
I suspect I want to use TIM2 with trigger source TI1_ED. Then bring the external signal into TIM2 CHAN1. Then I can use TIM2 CHAN2 as PWM output.
Can someone indicate if this is the right approach, or should I think about it in a different way? I can prototype it on a STM32F4 discovery board.
Thanks
#tim-counter2018-05-11 12:24 PM
Sounds good, although note that TI1F_ED detects both edges, so that's maybe not exactly what you want.
JW
2018-05-11 01:16 PM
look up external trigger synchronization in the datasheet.
2018-05-11 02:40 PM
Oh! Can I use it in a single-edge mode? If not, should I try a different approach? Do ITRn have an external interface? This is what is confusing me. Thanks!
2018-05-11 03:48 PM
I have indeed looked at much of the documentation, for example the cookbook
I also have looked at the following presentation of timers/counters for the STM32 family
http://mazsola.iit.uni-miskolc.hu/DATA/storages/files/_kbFGJG__bqURUT.pdf
As well as the datasheet, yes, the super long one
I've used these timers many times before, but never understood how to use an external (off-chip) signal to clear the counter register. The examples in the above referenced documentation use other timers, etc. or have different use cases.
So, please bear with my ignorance, and point me to the relevant part of the datasheet. Thanks in advance!
2018-05-11 05:10 PM
Oh! Can I use it in a single-edge mode?
Yes - TI1FP1 (and TI2FP2 for CH2) - both are tapped off after an edge detector, see Figure 'Capture/compare channel (example: channel 1 input stage)' in reference manual.
I've concocted a simple example -
http://www.efton.sk/STM32/ext_reset.zip
- it's for the 'L4 DISCO, but shouldn't be too hard to modify it for the 'F4 DISCO, or just read it for inspiration.JW
2018-05-11 07:30 PM
Thanks! And especially thanks for making it 'small and readable'. I will close the loop (post results) after I test this, so that other people can benefit from this.
2018-05-12 10:25 AM
'
So, please bear with my ignorance, and point me to the relevant part of the datasheet.
'
I suppose 17.3.19 is the right section for that?