How to calculate the angular velocity through MCU

Hello

I've got a Duemilanove ATMega168 microcontroller. I would like to know how to calculate the angular velocity with it.
I have a passive induction rpm sensor. This sensor generates Alternating Current. The higher frequency, the higher rpm.
Could i use the MCU for the calculation?
I just know there is a formula, 2(pi)(f) pi=3.14 f=frequency

Hi,

if the arduino can measure the frequency depends on the range of the frequency itself and you implementation. You can use a comparator to make a square wave from the sensor signal and connect this signal to an interrupt input. Count the no.of pulses np for a certain time T. Then calculate the frequency f = np/T (T ins seconds).

Mike

Hi,

if the arduino can measure the frequency depends on the range of the frequency itself and you implementation. You can use a comparator to make a square wave from the sensor signal and connect this signal to an interrupt input. Count the no.of pulses np for a certain time T. Then calculate the frequency f = np/T (T ins seconds).

Mike

Hi Mike,
Comparator, you mean the one of op-amp ?
If i converted the AC to DC, i don't need the comparator. Is this ture ?
And the frequency f = np/T
what is the letter of n and p ?

Thanks :slight_smile:

Comparator, you mean the one of op-amp ?

You can make a comparator with an op amp if you

want. Comparator - Wikipedia

f i converted the AC to DC, i don't need the comparator. Is this ture ?

No, basically the DC you get will be independent of frequency. I think you are mixing it up with PWM.

what is the letter of n and p

from the reply:-

Count the no.of pulses np

number of pulses

Thanks everyone

Let's make it clear
Here is the process that i would like to do

rpm sensor > comparator (convert the AC sine wave curfe to the square wave which is 0 and 1 ) > interrupt input (calculate the frequency) > MCU (calculate the RPM) > Display

For the process above, AC need to be converted to DC before enter the MCU, isn't it ?

For the process above, AC need to be converted to DC before enter the MCU, isn't it ?

No, when you convert the AC sine wave into a square wave it is not called DC. It is still an alternating signal, the sign might not change but the magnitude alternates so it is not DC. A signal is DC if some aspect of it's magnitude (normally the largest part) remains constant.

To measure the frequency you can either count the number of pulses in a period of time, it doesn't have to use the interrupt but it can if you want. Or you can time the period of one cycle and work out the speed from that.

2(pi)(f) pi=3.14 f=frequency

This is just the frequency in radians per second. You want to use the relationship between how many pulses you get from your sensor per revolution and how often you get them.
So suppose you get 12 cycles per revolution and a cycle takes 20mS, then your speed is 12 * 20 = 240mS per revolution.
That is a frequency of:-
1/240 = 4.166 revolutions per second
Which is 4.166 * 60 = 250 RPM

No, when you convert the AC sine wave into a square wave it is not called DC. It is still an alternating signal, the sign might not change but the magnitude alternates so it is not DC. A signal is DC if some aspect of it's magnitude (normally the largest part) remains constant.

If the sine wave was converted to square wave, do i need to do the AC/DC conversion ? because after the wave conversion, it's still an alternating current, right? It must be turned into DC to enter the MCU, isn't it ?

So suppose you get 12 cycles per revolution and a cycle takes 20mS, then your speed is 12 * 20 = 240mS per revolution.
That is a frequency of:-
1/240 = 4.166 revolutions per second
Which is 4.166 * 60 = 250 RPM

which means, number of cycles per revolution is when the trigger wheel rotates once, it has 12 cycles.
And a cycle takes 20mS , mS stand 10^-3 sencond ?
I don't understand 1/240 = 4.166 revolutions per second
240 ms = frequency ? 1/f = rev/s ?

Hi,

i do not know what amplitude the sine wave of the sensor has, the arduino can only work with signals in the range of 0..5V. You can do one of the following:

  1. build a converter which converts a frequency to a voltage and feed the output of this inverter to an analog input of the arduino (not so easy)

  2. build a comparator (you can use an op-amp). The comparator compares the sensor signal to a fixed voltage. If for example the sine wave goes from -1V to +1V and the fixed voltage, the comparator compares it with is 0V, then the output of the comparator is +5V as long as the sine wave is above 0V and the output is 0V as long as the sine wave is below 0V. The output of the comparator can be feed directly to a digital input pin of the arduino.

Here is a short code example:

// the comparator output is feed to pin 3
#define frqPin 3
long timeStart, timeStop;

void setup()
{
  Serial.begin(9600);
  Serial.println("Start measuring");
}

void loop()
{
   // start with input low
  if (digitalRead(frqPin == 0) {
    // wait until pin goes high
    while (digitalRead(frqPin) == 0) {}
    // get the time when input goes high
    timeStart = micros();
    // wait until input goes low again
    while (digitalRead(frqPin) == 1) {}
    // wait until input goes high again
    while (digitalRead(frqPin) == 0) {}
    // take the actual time in microseconds
    timeStop = micros();
    // the timedifference is the the time between two rising
    // edges of the input pin (= 1 period)
    timeStart = timeStop-timeStart;
    // normally the result is > 0, otherwise the
    // function micros() had an overflow (every 70 min)
    // the discard this measuring (or correct the value)
    if (timeStart > 0) {
      // calculate frequency
      // 1000000 microseconds/second, f = 1/t
      double f = 1000000.0/timeStart;
      // report the measured frequency
      SerialPrintln(f);
    }
  }
}

Hope this helps

Mike

build a comparator (you can use an op-amp). The comparator compares the sensor signal to a fixed voltage. If for example the sine wave goes from -1V to +1V and the fixed voltage, the comparator compares it with is 0V, then the output of the comparator is +5V as long as the sine wave is above 0V and the output is 0V as long as the sine wave is below 0V. The output of the comparator can be feed directly to a digital input pin of the arduino

Build a comparator, if i don't use an op-amp, what is another type of comparator i could use? i don't know much about comparator.

After the comparator, do i need to convert the current? Cause, it is still alternating current, if it was converted to DC, the frequency could be calculated ?

Thanks Mike_pa :slight_smile:

Is this circuit correct ?
I got the source from here: http://www.edn.com/contents/images/329014.pdf

Thanks

Hi,

the diodes and the capacitor is not necessary. Feed the sensor signal direct to the resistor. But this circuit works only if the sensor signal is appropriate. So what type of sensor do you use (datasheet/link) or specify the output signal (amplitude, frequency min/max, output resistance). Otherwise i can not help you.

Mike

the diodes and the capacitor is not necessary. Feed the sensor signal direct to the resistor. But this circuit works only if the sensor signal is appropriate. So what type of sensor do you use (datasheet/link) or specify the output signal (amplitude, frequency min/max, output resistance). Otherwise i can not help you

Oh...
I am collecting those information about the output signal. I will post here soon.

Thanks Mike :slight_smile: