2021-06-16 02:15 PM
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?
2021-06-16 02:23 PM
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.
2021-06-16 05:26 PM
Thanks, so there is no way for the hardware to count transitions?
2021-06-16 05:39 PM
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.
2021-06-25 10:06 PM
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);
2021-06-25 10:30 PM
2021-06-25 10:32 PM
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.
2021-06-26 02:17 AM
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
2021-06-28 03:22 PM
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).
2021-06-28 03:22 PM
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?