cancel
Showing results for 
Search instead for 
Did you mean: 

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

john doe
Lead
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)
 {
 GPIO_PinState pinState = HAL_GPIO_ReadPin(WWVB_IN_GPIO_Port, WWVB_IN_Pin);
 if (pinState == GPIO_PIN_SET)
 {
 pulseStart = htim2.Instance->CNT;
 }
 if (pinState == GPIO_PIN_RESET) {
 pulseEnd = htim2.Instance->CNT;
 pulseReceived = 1;
 }
 }�?�?�?�?�?�?�?�?�?�?�?�?

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
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..

View solution in original post

2 REPLIES 2
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
WWVB 0 pulse received: 0xA508443014610000
WWVB 1 pulse received: 0xA508443014612000
WWVB 1 pulse received: 0xA508443014613000
WWVB 1 pulse received: 0xA508443014613800
WWVB 0 pulse received: 0xA508443014613800
WWVB 0 pulse received: 0xA508443014613800
WWVB 0 pulse received: 0xA508443014613800
WWVB 1 pulse received: 0xA508443014613880
WWVB 1 pulse received: 0xA5084430146138C0
WWVB Sync pulse received
WWVB Frame received: 0xA5084430146138C0
WWVB 11:55 UTC Day 230 of 2017
WWVB DUT1 +0.3 DST: Yes Leap year: No Leap second: No
WWVB Local time: 06:56 AM Friday August 18, 2017
RTC Updated - 06:56:00 8-18-2017
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Now I've managed to [poorly] get it working with SysTick, EXT+TIM2, and TIM2 PWM Input Capture. Learning is fun.