Page 1 of 1
comparing the phase of two signals
Posted: Mon Nov 28, 2011 7:32 pm
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.
Re: comparing the phase of two signals
Posted: Mon Nov 28, 2011 7:39 pm
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
Re: comparing the phase of two signals
Posted: Mon Nov 28, 2011 7:51 pm
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.
Re: comparing the phase of two signals
Posted: Mon Nov 28, 2011 7:55 pm
by Giovanni
You will need two timers, each ICU uses a whole timer (two comparators of the same timer).
Giovanni
Re: comparing the phase of two signals
Posted: Mon Nov 28, 2011 8:32 pm
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

I'll post my findings later..
Re: comparing the phase of two signals
Posted: Mon Nov 28, 2011 8:56 pm
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.
Re: comparing the phase of two signals
Posted: Mon Nov 28, 2011 9:34 pm
by Giovanni
Fixed, thanks for finding.
Giovanni