PDA

View Full Version : need help for measuring two freq at same time



vu2iia
- 27th December 2008, 05:11
Hi,

I am hobbyst, I want to measure two frequencies between 10hz to 500hz at same time on two different pins, ie measure two frequencies within same time base of 1000 mili sec . I tried "Count" but I cold not measure two inputs within same 1000ms. Is there a better way to do it?, any example code would help me lot.

I am using 16f73 @4mhz. Actually I am trying to measures pulses coming from my motor bikes spark plug, I have condtioned and converted pules picked up from spark plug and converted to TTL level. Other frequency input is coming from speed sensor.

These Pulses from spark plug are erratic, Does anybody have any circuit for getting reliable reading using PIC?.

Thanks in advance

regards
mahesh
VU2IIA

Kamikaze47
- 2nd January 2009, 15:32
you could try using the "change on portb" interrupt. put both of the inputs on port b and then any change will trigger the interrupt. You could set up the interrupt handler to figure out which one has changed and using a timer and a bit of maths, work out both frequencies.

Melanie
- 2nd January 2009, 19:26
This is like super-crude... but it'll kinda work as a starting point...


InputA var PortB.0
InputB var PortB.1
LED var PortB.4

Temp var Byte
ToggleA var Temp.0
ToggleB var Temp.1

CounterA var WORD
InputACount var WORD
InputBCount var WORD

TRISB=%00001111

Start:
'
' Get Ready
' ---------
ToggleA=0
ToggleB=0
InputACount=0
InputBCount=0
High LED ' We're Ready...
'
' Start Count
' -----------
For CounterA=0 to 3999
If (InputA=0 and ToggleA=0) then ToggleA=1
If (InputA=1 and ToggleA=1) then
InputACount=InputACount+1
ToggleA=0
endif
If (InputB=0 and ToggleB=0) then ToggleB=1
If (InputB=1 and ToggleB=1) then
InputBCount=InputBCount+1
ToggleB=0
endif
PauseUS 250
Next CounterA
'
' Stop Count
' ----------
Low LED
LCDOut $FE,1,"A=",#InputACount,"Hz"
LCDOut $FE,$C0,"B=",#InputBCount,"Hz"
Goto Start ' Loop forever

Yes, of course there are limitations... you'll have to trim PauseUS so that the For/Next Loop is exactly 1 second long... so put a scope on the LED pin... another limitation is that your Pulse must be wider than about 270uS so you may need some external circuitry... another is that probably 3.5kHz is a practical maximum count... but go play...

vu2iia
- 3rd January 2009, 04:48
Hi Melanie & kamikaze47,

First of all New year Greetings to you. Thanks for replying and giving me helping hand.

Actually 2 Months back I purchased Cheap 100cc new motorcycle, which doesnt have RPM meter, so I wanted to make RPM meter and Speedometer for my bike. I am getting RPM signals from Spark plug and and Speedometer signal from hall sensor, which is just few hundred hz per seconds, but problem was how to measure both signals at same time.

Melanie, I will try your code, I will try not to bother you and use my small brain to its max.

Thank you once again,

regards
Mahesh-VU2IIA
my hobby page, if you have time to see.
http://www.vu2iia.bravehost.com/