cancel
Showing results for 
Search instead for 
Did you mean: 

I have a timer set up to measure the input PWM period on channel 1 and pulse width on channel 2 as outlined in the reference manual and it works fine. However, when I stop the input signal, the capture registers are never reset to indicate 0 frequency.

bmose.2
Associate

Timer configurations are as follows:

  // Control registers(input PWM on channel 1 and 2[pin 12 & 13])

  TIM4->CCMR1 |= TIM_CCMR1_CC1S_0 ; // Active input for tim_ccr1

  TIM4->CCMR1 |= TIM_CCMR1_CC2S_1; // Active input for tim_ccr2

  TIM4->CCER  |= TIM_CCER_CC2P;    // Active polarity for tl1fp2 (measure duty)

  TIM4->SMCR  |= 0x50;             // Select valid input trigger TL1

  TIM4->SMCR  |= TIM_SMCR_SMS_2;   // configure controller in reset mode

  TIM4->CCER  |= (TIM_CCER_CC1E | TIM_CCER_CC2E); // Enable captures

When the input signal is present, the measurements reports the correct period and pulse-width at the pins. When I shut the PWM signal at the pins, the last captured values are retained in CCR1 and CCR2. When the channels are configured as input, as in this case, CCR1 and CCR2 are read only and I cannot clear them manually. The reset mode here seems to only reset the timer counter, not the capture registers.

Am I missing something in the cofigurations?, my intention is to be able to measure PWM frequency and pulse-width, and as well to know if the PWM signal has been turned off (my assumption being the capture registers be cleared )

If there is no PWM signal, there is no rising edge to reset the counter, even so the capture registers seem to never reset , just updated with new values during capture events(rising and falling edges).

Is there a way to reset these registers to that when there is no input PWM signal at the pins I will know since they will read 0.

1 ACCEPTED SOLUTION

Accepted Solutions

Capture just captures the moment of input edges. No edges on input, no change in capture registers.

Set one of the unused channels as Compare and set the maximum expected pulse length into CCRx of that channel; enable interrupt on that channel.

If that time is reached, clear whatever you need to be cleared.

JW

View solution in original post

2 REPLIES 2

Capture just captures the moment of input edges. No edges on input, no change in capture registers.

Set one of the unused channels as Compare and set the maximum expected pulse length into CCRx of that channel; enable interrupt on that channel.

If that time is reached, clear whatever you need to be cleared.

JW

Thank you very much.