cancel
Showing results for 
Search instead for 
Did you mean: 

Forcing Capture-Compare-Register to clear [STM32H7]

bnguy.1
Associate III

I'm trying to count the number transition during the time another process is taking place. Don't need frequency, just the counts.

So I've enabled TIM8CH3 for capture-compare, and have verified that CCR3 does change when there are transitions on the input... however, it always accumulates, and I can'tclear by writing 0 to CCR3... nor by re-initializing the timer itself.

htim8->Instance.CC3 = 0;
MX_TIM8_Init();
HAL_TIM_Base_Stop(&htim8);
HAL_TIM_Base_Start(&htim8);
HAL_TIM_IC_Start(&htim8, TIM_CHANNEL_3);

How can the capture-compare register contents be cleared?

10 REPLIES 10
TDK
Guru

In IC mode, the register is read only and cannot be changed. You can disable the timer to clear it, but there shouldn't be a need to do so. See the reference manual:

If channel CC1 is configured as input: CR1 is the counter value transferred by the last

input capture 1 event (IC1). The TIMx_CCR1 register is read-only and cannot be

programmed.

The value doesn't accumulate, it takes the value of the CNT register at the last event that triggered it.

If you feel a post has answered your question, please click "Accept as Solution".
bnguy.1
Associate III

Thanks, so there is no way for the hardware to count transitions?

TDK
Guru

One way to count transitions would be to use the signal as the external timer clock. The timer counter would count the number of pulses on the line.

If you feel a post has answered your question, please click "Accept as Solution".
bnguy.1
Associate III

Strange, no matter how I configure the TIM8 / CH3 , I don't see the Timer CNT change, despite having plenty of falling edge of TIM8CH3,

Looking at TIM8 on the datasheet, I'm not exactly sure about the Trigger Selection field so I just cleared it. should the Trigger Source point to CH3 Input? Perhaps a clock/prescaler issue?

	htim8.Instance->TISEL  =  0;
 
	// CC3S = 01
	htim8.Instance->CCMR2 &=  ~(3 << 0);
	htim8.Instance->CCMR2 |=   (1 << 0);
 
	// No Filter - IC3F
	htim8.Instance->CCMR2 &=  ~(0x4 << 12);
 
	// Falling Edge Detect - CC3P
	htim8.Instance->CCER |= ( 1 << 9 );
 
	// Slave Mode Sel : External Clock Mode 1
	htim8.Instance->SMCR &= ~( 1 << 16 );
	htim8.Instance->SMCR |=  ( 7 << 0 );
 
	// Trigger Selection -- ???
	htim8.Instance->SMCR &=  ~(7 << 4);
	htim8.Instance->SMCR &=  ~(3 << 20);
 
	// Enable
	htim8.Instance->CR1 |=  (1 << 0);
 
 

0693W00000Bc3sGQAR.png

You’re using input capture. I’m suggesting using external clock mode.
The reference manual has details about the timer. The datasheet only contains limited device specific stuff.
If you feel a post has answered your question, please click "Accept as Solution".

Actually Maybe you’re not using input capture mode. But reference manual should give you details. Pretty sure the input pin isn't the CH3 pin.

Edit: TIM8_ETR is on PA0.

If you feel a post has answered your question, please click "Accept as Solution".

You cannot use CH3 as input to the slave-mode controller, so cannot use it as external clock input.

There's a workaround using an undocumented property of STM32, namely that inputs to modules which don't have assigned a pin in GPIP are fixed at 0. This, you can use the CH1-CH2-CH3 XOR to effectively redirect CH3 into CH1 and then use CH1 as ingot to the slave-mode controller.

As I've said this is undocumented, so treat it as such.

JW

Thanks, yes the TIM8's ETR trigger input is PA0 , PI3 or PG8.. unfortunately, the clock source I want to monitor is connected to PI7 (Pin B3).

Thanks I'd like to give this a try.. so would I select ETR1/CH1 as the Trigger source, TIM8_CH3 as Input Capture Direct Mode ? How would CH1/CH2/CH3 be set for XOR.. and wouldn't CH1/CH2 pins have to be floating?