cancel
Showing results for 
Search instead for 
Did you mean: 

Pulse Lenght

andiob
Associate II
Posted on January 29, 2014 at 14:12

I finally managed to setup TIM3 to measure pulse lenght of 4 pwm signal. The only thing left to do is manage the disconnection of one of the wire feeding the signal.For now when the wire is disconnected the last valid measure is kept i want the value to go 0.

I thought to increment a control value every time there is a transition from high to low and to decrease the same value at a fixed rate using a loop considering the pulse 0 when the counter itself reaches 0. Is there a more efficent way?
3 REPLIES 3
chen
Associate II
Posted on January 29, 2014 at 15:26

Hi

''I finally managed to setup TIM3 to measure pulse lenght of 4 pwm signal.''

''For now when the wire is disconnected the last valid measure is kept''

''Is there a more efficent way?''

Depends on how the timer is set up.

If the value is being read from one of the CCR registers, you could add a 'time out' and on the time out - reset the CCR register. The timeout is usually the 'Update event', the length (time out) is set in the ARR register.

andiob
Associate II
Posted on January 30, 2014 at 15:38

I capture the value on both edges and subtract the value of the timer at the rising esge from the value at the falling edge ( correcting when the timer overflows )

if(pulse_in[index].capture_r < pulse_in[index].capture_f)

{

    pulse_in[index].value = pulse_in[index].capture_f - pulse_in[index].capture_r;

}else if(pulse_in[index].capture_r < pulse_in[index].capture_f)

{

    pulse_in[index].value = (0xFFFF - pulse_in[index].capture_r) + pulse_in[index].capture_f + 1;

}

chen
Associate II
Posted on January 30, 2014 at 16:04

Hi

Showing random bits of code is of little use.

I re-state : it depends on how the timer is set up.

How are you using the timer?