cancel
Showing results for 
Search instead for 
Did you mean: 

What's the correct way to configure the STM32H7 to count pulses using an external trigger?

batmansfoot
Associate

I’m attempting to configure TIM3 to count up on pulses received from an external trigger on TIM3CH1 but I'm not seeing CNT change.

I’ve followed the sample instructions in the datasheet (RM3099 Rev 3) (for External clock source mode 2--all registers mentioned below are set as directed and those that aren't are in their default state):

For example, to configure the upcounter to count each 2 rising edges on ETR, use the

following procedure:

  1. Select the proper ETR source (internal or external) with the ETRSEL[3:0] bits in the TIMx_AF1 register.
  2. As no filter is needed in this example, write ETF[3:0]=0000 in the TIMx_SMCR register.
  3. Set the prescaler by writing ETPS[1:0]=01 in the TIMx_SMCR register
  4. Select rising edge detection on the ETR pin by writing ETP=0 in the TIMx_SMCR register
  5. Enable external clock mode 2 by writing ECE=1 in the TIMx_SMCR register.
  6. Enable the counter by writing CEN=1 in the TIMx_CR1 register.

My specific settings are:

  • AF1:ETRSEL = b’0000 (ETR input is connected to I/O)--I've got the output connected to TIM3_ETR and have it configured as such.

I've also tried external trigger mode 1, following these instructions from the datasheet:

For example, to configure the upcounter to count in response to a rising edge on the TI2

input, use the following procedure:

  1. Select the proper TI2x source (internal or external) with the TI2SEL[3:0] bits in the TIMx_TISEL register.
  2. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S= ‘01 in the TIMx_CCMR1 register.
  3. Configure the input filter duration by writing the IC2F[3:0] bits in the TIMx_CCMR1 register (if no filter is needed, keep IC2F=0000).
  4. Select rising edge polarity by writing CC2P=0 and CC2NP=0 and CC2NP=0 in the TIMx_CCER register.
  5. Configure the timer in external clock mode 1 by writing SMS=111 in the TIMx_SMCR register.
  6. Select TI2 as the input source by writing TS=00110 in the TIMx_SMCR register.
  7. Enable the counter by writing CEN=1 in the TIMx_CR1 register.

I adapted these to use TI1 and had the pin connected to PC6 (TIM3CH1, configured as such). AN4776 has some detail to add to the examples from the datasheet, but there wasn't anything in there that really helped.

I have a 1kHz 50% duty cycle square wave generated from TIM1 that I’m feeding into TIM3CH1 (which I’ve also had produce an output to check electrical correctness). I’d expect to see CNT increasing, but I’m not. I feel like there's something fundamental I'm missing here--I'd appreciate any help you can provide.

3 REPLIES 3

Read out and check/post content of TIM3 and relevant GPIO registers.

JW

Hi Jan--thanks for the quick reply. Easiest way seemed to be to screenshot in ozone--I'm happy to provide a different format or add information.

ETR2 TIM3:

0693W00000aH0tjQAC.png 

ETR2 GPIO:

0693W00000aH0vjQAC.png 

ETR1 TIM3:

0693W00000aH0wIQAS.pngETR1 GPIO:0693W00000aH0vAQAS.png

jlogan03
Associate

I had this problem as well (for TIM8), and made two deviations from the reference manual's instructions for External Clock Mode 1 to get it working

  • Before starting the other configuration: make sure the peripheral is enabled in the appropriate RCC register and that its peripheral clock is running
  • In the SMCR TS field, use the "Edge Detector" option
    • Seems to be only connected to the TI1 input, but I haven't tried anything to pipe it through from another pin
    • Counts on both rising and falling edges
    • Not sure about its performance characteristics yet
    • Based on the block diagram in Figure 416 (this is the TI1F_ED signal), it does not appear to go through a prescaler block, so I'm not sure whether the counts-per-trigger can be adjusted or not

No combination of configuration that I have made has been able to persuade the counter to increment with SMCR.TS set to any of the filtered input channels in External Clock Mode 1.