Maker Pro
Maker Pro

STM32f4 Timer to control another Timer

victorrr

Feb 11, 2015
11
Joined
Feb 11, 2015
Messages
11
Hello,
i just configured a timer of my board STM32f407VG so it can make pulses of a specific frequency indefinitely. Now I would like to control this timer with another timer so I could make for example pulses for 1 sec and then stop for 10 sec and then again pulses for 1 sec.....

How can I make this?

Thank you very much
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Set up the first timer as you did.
Set up a second timer starting e.g. with a 1s interval.
Use an auxiliary variable to note whether timer 2 is set up for 1s or 10s interval (or read this value from the timer's control register)
Enable the output of timer 1.

In the interrupt routine of timer 2:
- if it is set up for 1s, then disable the output of timer 1, set up timer 2 for 10s interval. // on entering the routine the 1s interval is over -> no more output and then wait for 10s
- if is is set up for 10s, then enable the output of timer 1, set up timer 2 for 1s interval. // on entering the routine the 10s interval is over -> activate output and then wait for 1s


Sorry, I can't give you STM code as I'm not familiar with this µC, but the above pseudo-code should suffice to write your own code.


Regards,
Harald
 

victorrr

Feb 11, 2015
11
Joined
Feb 11, 2015
Messages
11
That's a possibility. But actually my project has to be very precise and I would like to configure the "hardware" of the board, not the "software" so the board doesn't waste time reading a program.
 

victorrr

Feb 11, 2015
11
Joined
Feb 11, 2015
Messages
11
I will use this pulses to make ultrasound and calculate distances of about 5 meters. So the timing has to be very precise. I read in other posts that I could make this using slave mode but I don't know how that works.

Thank you for reply
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
At the speed of sound (340.29m/s) a resolution of 1cm in distance is equivalent to 3µs in time. This is the resolution with which you'll have to measure the time from starting the ultrasound ransducer to receiving the echo (if you use reflected sound) or receiving the sound (if you place the receiver at the other end of the distance to be measured).

This resolution (accuracy) is independent from the accuracy of the 1s or 10 s timings. So the method described in my post #2 can readily be used for these timings. You'll have to worry nly about the accuracy of the measurement of the duration from starting the ultrasound pulse to receiving it.
 
Top