2019-08-07 11:18 PM
Hi, I am currently facing the problem, that we made a new product and slightly changed the design and routing from the old version and now the input for counting pulses in on PB1. I would like to count pulses on tim3 channel 4 and I am really not sure if this is possible.
I read in the internet, that only channel 1 and 2 can be used as external triggers. Is this true? Is there a workaround to use tim3 channel4 anyway?
Thanks, Mario
2019-08-08 12:01 AM
> I read in the internet, that only channel 1 and 2 can be used as external triggers. Is this true?
This is concerning. Why do you resort to internet, instead of the Reference Manual?
Normally, for pulse counting, you would use the counter driven by the slave-mode controller in Extenal Clock Mode 1 by setting TIMx_SMCR.SMS=0b111 (or, driven from the ETR input in External Clock Mode 2 but that's another story), and, indeed, from the capture-compare channels, only channel 1 and 2 can be used as input to the slave-mode controller, by setting TIMx_SMCR.TS to 0b101 or 0b110 (or 0b100 if you want to count every edge both rising and falling, but only on channel 1).
But here's a trick, if the input frequency is not too high: you can set any of the 4 channels as Input Capture (as in your name) in respective TIMx_CCMRx and enable in TIMx_CCER (and ignore the captured value), set it to trigger DMA by setting the respective TIMx_DIER.CCxDE bit, set up the respective DMA stream to do unnecessary transfers (e.g. from any memory position into an unused TIMx_CCRx), and then the DMA's NDTR register functions essentially as a downcounter for the capture events.
JW