comparing the phase of two signals

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

comparing the phase of two signals

Post by Badger »

I'm trying to understand the ICU driver for STM32F1, to see if I can use the timer hardware for a project. I am trying to compare two pulses of the same frequency; I want to work out the relative phase difference of the two signals, comparing on the rising edge. Can I achieve this with the ICU driver? The frequency (typically 60hz) and required acuracy (1ms) is low, so I can get away with probing the pins or using interrupts.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: comparing the phase of two signals

Post by Giovanni »

Hi,

It should be feasible using the ICU driver as-is, it can measure both the period and the duty cycle. The upper limit is only the capability to serve the callbacks fast enough but at 60hz there are no problems at all.

Giovanni
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: comparing the phase of two signals

Post by Badger »

Thanks for the quick reply Giovanni. Something I'm not sure of is how to get the period / width of individual channels on a timer; functions e.g icuGetWidthI() only take a driver as a parameter. Should I have each signal going to a separate timer? Something I might not have made clear is that each pulse is a fixed width.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: comparing the phase of two signals

Post by Giovanni »

You will need two timers, each ICU uses a whole timer (two comparators of the same timer).

Giovanni
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: comparing the phase of two signals

Post by Badger »

It looks like I should be able to play with the CCRx registers to reconfigure the timer such that a rising edge on TIM1_CH1 defines the start of the pulse, and a rising edge on TIM1_CH2 defines the end of the pulse. So in effect the width of the pulse will be the phase difference :D

I'll post my findings later..
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: comparing the phase of two signals

Post by Badger »

Looks like there is a typo in STM32/icu_lld.h:

Code: Select all

  /* CCMR1_CC1S = 01 = CH1 Input on TI1.
     CCMR1_CC2S = 10 = CH2 Input on TI2.*/
  icup->tim->CCMR1 = TIM_CCMR1_CC1S_0 |
                     TIM_CCMR1_CC2S_1;


But from the datasheet for CC2S:

Code: Select all

10: CC2 channel is configured as input, IC2 is mapped on TI1

So I think the second line of the comment should be TI1 not TI2.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: comparing the phase of two signals

Post by Giovanni »

Fixed, thanks for finding.

Giovanni
Post Reply