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
Time signal
- 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:
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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:
I also have a sample frequency counter program using flowcode V3 if you require it.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- goldwingers
- Posts: 118
- Joined: Wed Sep 06, 2006 1:22 pm
- Location: London
- Been thanked: 1 time
- Contact:
frequency file
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
Ian
- 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:
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
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
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel