Using a microcontroller as period counter and speed detector

Thread Starter

Manjugolu

Joined Jul 31, 2014
16
Hi, I am using a microcontroller to analyse the data coming from a sensor circuit. I need to determine the speed of a moving vehicle using the complete module. The maximum speed of the target is 100km/hr which means a frequency of 4320 Hz(this is doppler shifted frequency calculated) of the signal coming from sensor circuit has to be fed to the microcontroller which will finally provide speed of vehicle.
How shall we use a microcontroller as period counter and then provide speed of object. Also what kind of microcontroller shall be used.
 

mitko89

Joined Sep 20, 2012
127
If the speed is determined by the frequency, you need a uC with a timer, which will interrupt on any rising edge of the signal. You will then measure the time period between the interrupts so you can calculate frequency. As you know that 4320 Hz corresponds to 100 km/h, you can calculate the speed by calculating the ratio.
 

sirch2

Joined Jan 21, 2013
1,037
What else does the MCU have to do; maths? drive a display? store the data? Basically any MCU can count clock ticks between high/low transitions and at 4kHz you may not even need to bother with interrupts, a modern MCU can do a lot in a millisecond.
 

mitko89

Joined Sep 20, 2012
127
What else does the MCU have to do;
Good question I though of asking, but Manjugolu didn't bother asking it so I didn't bother asking too.
you may not even need to bother with interrupts, a modern MCU can do a lot in a millisecond.
Generally it's always better to use interrupt except for when they are needed for something else, which has higer priority for the design. In the case, it all depends on the question above.
 

sirch2

Joined Jan 21, 2013
1,037
Generally it's always better to use interrupt except for when they are needed for something else, which has higer priority for the design. In the case, it all depends on the question above.
It's getting a bit off topic but I would disagree because it causes a jump in the code which adds complexity but each to his own.
 

mitko89

Joined Sep 20, 2012
127
It's getting a bit off topic but I would disagree because it causes a jump in the code which adds complexity but each to his own.
But guarantees you will not miss an event, which is the more important in most of the situations. Adding a jump, in most of the cases, means you will need one instruction cycle more for entering the ISR and one more for returning from it. Two more cycles that grant your code stability, I will always accept this trade. I don't thing few more lines of code is that much of an issue if the matter is complexity.
 
Top