2014-01-29 05:12 AM
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?2014-01-29 06:26 AM
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.2014-01-30 06:38 AM
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; }2014-01-30 07:04 AM
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?