That's not PWM, its pulse-width coding. You'll probably want an ISR to decode that, checking the delays
between edges (ie reading micros() and comparing to the previous time and seeing if its > or < than 60us).
You need to watch out for other ISRs skewing your measured times though.
volatile unsigned long prev_ts = 0 ;
void my_isr ()
{
sense = digitalRead (pin) ;
ts = micros () ;
if (ts - prev_ts > 60)
{
if (sense)
{ // just seen long LOW
}
else
{ // just seen long HIGH
}
else
{
if (sense)
{ // just seen short LOW
}
else
{ // just seen short HIGH
}
}
prev_ts = ts ;
}
void setup ()
{
attachInterrupt (digitalPinToInterrupt (pin), my_isr, CHANGE) ;
...
}
The Arduinos runs on a resonator, not a crystal.
These drift with temperature by some amount.
If you need better timing, you need to calibrate to
a crystal clock reference. I've used a DS3231 board
and a 1 second interrupt to calibrate the processor speed.
It is good to better than 1x10-5 within any 1 second span
and long term better than 1x10-7.
Dwight
For decoding see DHT22 library, it is the same principle = detecting the length of 1s and 0s.
Warning digitalRead () function is very slow compared to the time to measure.
Best to do is using Rob Tillaert's library available on the playground, or even better to use direct reading of the registers of the micro controller but in this case you must use the Atmel I/O name , see datasheet.
FYI
DigitalRead () ~ 60/80 clock cycles, depending if I/O is PWM capable or not.
Method Rob T ~ 30 clock cycles, not possible to make faster because Wiring/Arduino store variables in Flash with PROGMEN.