Read a pwm signal

Hi everybody my question is verry easy. Could an arduino read a pwm signal and give it frequence? and how?
thanks!!!

Depending on the frequency range and the nature of the PWM signals it might be as easy as "pulseIn()" which measures a single pulse in microseconds.

hi, thanks for your replie. here a quote from a compass datasheet i would like to use:" The pulse width varies from 1mS (0° ) to 36.99mS (359.9° )"
it gives the angle using pwm… do you thing it’s possible to read that kind of signal with arduino?

The accuracy of the pulseIn function is limited to approximately +/- 4 mS. So, no, I don't think that compass would be a good choice.

ok thanks a lot and if i use a compass with i2c is it easy to use? i mean is i2c easy to use?

i mean is i2c easy to use?

No. It is designed to be very difficult to use. Only people with 200 years experience and a PhD in computer science can get it to work.

The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and the analogReference() function. Additionally, some pins have specialized functionality:

TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the Wire library.

Fortunately, all the hard work has been done.

victorjung:
hi, thanks for your replie. here a quote from a compass datasheet i would like to use:" The pulse width varies from 1mS (0° ) to 36.99mS (359.9° )"
it gives the angle using pwm... do you thing it's possible to read that kind of signal with arduino?

PaulS:
The accuracy of the pulseIn function is limited to approximately +/- 4 mS. So, no, I don't think that compass would be a good choice.

Since pulseIn() measures in microseconds I find it hard to believe that it would be off by milliseconds (thousands of microseconds).

It can't measure pulses shorter than 10 microseconds or longer than about three minutes but the range 1000 to 36990 microseconds should be no problem. To get degrees:

unsigned long pulseWidth = pulseIn(pin, HIGH);
if (pulseWidth != 0)
    float degrees = (pulseWidth / 1000.0) - 1.0;
else
    Serial.println("No pulse found.");

Note that since you didn't specify the polarity of the pulse I'm guessing it's HIGH.

It [pulseIn] can't measure pulses shorter than 10 microseconds or longer than about three minutes

There is a patch for this, see bugreport - Google Code Archive - Long-term storage for Google Code Project Hosting. -

Change the macros from wiring.h

#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )

to

#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
#define microsecondsToClockCycles(a) ( ((a) * clockCyclesPerMicrosecond() )

and the range (at least upper side of it) of pulsein will improve a lot.