cancel
Showing results for
Did you mean:

# PWM Input Capture vs. EXTI+TIMx->CNT differing values

Posted on August 18, 2017 at 02:58

I'm having a really fun time learning this stuff!

I have my WWVB decoder working with EXTI and TIM2 free running . As a learning exercise, I was trying to use the PWM Input Capture method.

TIM2 prescaler is (timer clock/1000) -1 in both situations, and ARR 0xFFFFFFFF

With the PWM Input Capture method, I'm using this formula to determine pulse width:

abs(*(uint32_t*)&TIM2->CCR1 - *(uint32_t*)&TIM2->CCR2);

With the EXTI+TIMx method, here's how I'm measuring it:

`````` if (GPIO_Pin == WWVB_IN_Pin)
{
if (pinState == GPIO_PIN_SET)
{
pulseStart = htim2.Instance->CNT;
}
if (pinState == GPIO_PIN_RESET) {
pulseEnd = htim2.Instance->CNT;
}
}�?�?�?�?�?�?�?�?�?�?�?�?``````

I get vastly differing values [using two boards sharing same input signal] between the two methods. The PWM Input Capture method has very much shorter measured pulse time. Am I getting it wrong, or is that normal? Shouldn't the values measured be closer?

1 ACCEPTED SOLUTION

Accepted Solutions
Guru
Posted on August 18, 2017 at 03:49

abs(*(uint32_t*)&TIM2->CCR1 - *(uint32_t*)&TIM2->CCR2); // Bit of a dogs breakfast

For INPUT CAPTURE

uint32_t delta =

TIM2->CCR2- TIM2->CCR1; // for all cases, assuming CCR1 leads CCR2, ie first edge, second edge, program for opposite edges

For PWM INPUT, one is the Period, and one is the time from rising edge to falling edge (duty), also assumes programmed to reset on each cycle

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
2 REPLIES 2
Guru
Posted on August 18, 2017 at 03:49

abs(*(uint32_t*)&TIM2->CCR1 - *(uint32_t*)&TIM2->CCR2); // Bit of a dogs breakfast

For INPUT CAPTURE

uint32_t delta =

TIM2->CCR2- TIM2->CCR1; // for all cases, assuming CCR1 leads CCR2, ie first edge, second edge, program for opposite edges

For PWM INPUT, one is the Period, and one is the time from rising edge to falling edge (duty), also assumes programmed to reset on each cycle

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 18, 2017 at 04:22

Thank you for your help. Sometimes I dont know why I write the code I do [ok, yes I do, beer sometimes fuels my programming hobby] and you're very generous with your knowledge. Thanks again, Clive One. I had that wrong, and I had the polarity wrong regarding the channels. Now my LED blinks concurrently on both boards, and I'm getting sane values. You rock.

on edit:

woo hoo! it works!

``````WWVB Sync pulse received