SX chip first timer, tachometer application
nige66
Posts: 12
Just been reading through the forums, and lookinging at examples of code, I found the basic example of rc time to serial LCD does what I basically want, however I want to measure a tachometer pulse of up to 0-4000 RPM at 6 pulses per rpm. Pulsein(?) command measure how many pulses within a given time frame, I have a serial LCD so that should be fairly straight forward, maybe some pullup required. So my question is can any one help with an example of code of sampling a input, getting a number doing some math then sending to serial LCD, I'm looking at running at 4 mhz.
thanks
nige
thanks
nige
Comments
dan
As Dan said, that should do what you want.
You don't say what resolution you want, but if you COUNT for 1000 mSec that will give you RPM / 10.
If you COUNT for 100mSec that will give you RPM / 100 (which is usually enough).
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"I'm a man, but I can change, if I have to, I guess" The Red Green Show
·
COUNT· 6000 = RPM / 10
thanks
nige
Attached is my·code...
Counting pulses is pretty good if you have quite a few pulses, but when the pulses are less than 100 or so per sample, you will have alot of drifting. But with my project I'll always have ~65 pulses / second so It's not too bad. Another idea is to write a custom function that counts rising & falling edges of the signal, that will give you twice as many to count.
Jim
He said in his original post that he got 6 pulses per revolution.
You should enable the Schmitt triggers for the pin that the pulses are coming in on.
That is probably why the lower RPMs cause drifting.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"I'm a man, but I can change, if I have to, I guess" The Red Green Show
·
All this stuff is good to get the brains cells moving.
thanks
nige
Whats your thoughts?
count freqin, duration, hertz
tx_byte lcdline1
tx_str hertz
thanks
nige
· You can do something like I did for the HC4LED displays.
· Look at this demo program http://forums.parallax.com/attachment.php?attachmentid=42396
· It looks clunky, but it's really code effecient.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"I'm a man, but I can change, if I have to, I guess" The Red Green Show
·
hope this helps
dan
regards
nige
I looked at the cheap LED displays they( HC4LED displays) they would not be suitable as I would want to display messages text as well as numbers.
I found the rc time pot example got me a little further proving that the count pulses could be displayed real time o.k , that worked by replacing the RC command with a count command and willl measure 1 pulse p min to 100 per minute o.k ( and display on serial LCD o.k ), however when I try 1khz and add an extra line to divide by 1000 I get an error where the ( Line 352, Warning 37, Pass 2: Literal truncated to 8 bits ) so is this number stretching the math of the SX, I have included the program minus the /1000 step, any ideas to get around this?
\
nige
The "analog" variable is a single byte, so it can only hold values from 0 to 255.· Also, the #1000 constant is truncated to a single-byte value, which is why the basic compiler is issuing the warning.
You would need a 2-byte value to be able to count to 6000.· I'm not familiar with the count routine, so I don't know if·it can handle 2-byte values.· You could look at the assembly code generated by the count routine and adapt it to your specific needs.· Instead of using a binary counter you could implement a 4-digit BCD counter.· This would eliminate the need for dividing by 1000, 100 and 10.
Dave Hein
count freqin,duration,analog ' read pot (10 us units)
anathou = analog / 1000 ' freq in / 1000 if > 1000 then 1000's will be in anathou LSB
anahun =__wremainder ' anahundred word contains remainder gor confused on __Wremainder ( help wasn't so helpful) __remainder only for byte ?
thou=anathou_lsb ' convert to single byte for use in TXBYTE
anahun= anahun/100 ' anahund / 100 if > 100 then will be in anahun LSB
anaten=__wremainder
'
thou = thou + "0" ' convert 1000s to ASCII
PUT line1(6), thou ' move to LCD buffer, in position 6
ect ect
thanks
nige