Time signal

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
KeithSloan
Posts: 114
Joined: Fri Jul 27, 2007 10:50 am
Been thanked: 1 time

Time signal

Post by KeithSloan »

What is the best way of going about trying to decode a time signal. i.e. Ones and Zero's on a signal line?

Can anybody point me at some examples?

Thanks Keith

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hello

The easiest way is to wait until the signal changes.

Eg

While (porta.0 == 0); //Wait for RA0 to go high
While (porta.0 == 1); //Wait for RA0 to go low

once you know that pin RA0 has just changed from high to low you can begin counting. The easiest way to do this is to use a hardware timer. Either Timer0 for a small period or Timer1 for a larger period.

tmr0 = 0;
tmr1 = 0;

Then all you have to do is wait until the state changes again and retreive the timer value.

While (porta.0 == 0); //Wait for RA0 to go high
count = tmr1;

For further help on using the timers and configuring their counting rate see the specific PICmicro datasheet for your target processor.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

I also have a sample frequency counter program using flowcode V3 if you require it.

User avatar
goldwingers
Posts: 118
Joined: Wed Sep 06, 2006 1:22 pm
Location: London
Been thanked: 1 time
Contact:

frequency file

Post by goldwingers »

Benj. I could do with a copy of your frequency meter file. I have been trying to build a complex program to measure engine speed and other stuff. would be most grateful
Ian

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

The code for the frequecy meter is available from here.

http://www.matrixmultimedia.com/softwar ... ounter.fcf

The code is designed to print out the freqency of pulses incoming to the pin specified in the Read_Input macro.

Max Input freq approx 32000Hz

Higher frequencies ( < 64000Hz ) can be measured by modifying the LCD Print Number Function

Let me know if you have any problems

Post Reply