Shop OBEX P1 Docs P2 Docs Learn Events
SX chip first timer, tachometer application — Parallax Forums

SX chip first timer, tachometer application

nige66nige66 Posts: 12
edited 2006-07-21 00:49 in General Discussion
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

Comments

  • SawmillerSawmiller Posts: 276
    edited 2006-07-13 12:36
    i would think what you would want might be the count command, not the pulsein.. look at sx/b help
    dan
  • BeanBean Posts: 8,129
    edited 2006-07-13 13:48
    The COUNT command has just been added to SX/B (as of version 1.50).
    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
    ·
  • SawmillerSawmiller Posts: 276
    edited 2006-07-13 15:30
    would be a good app for bean's hc4led's [noparse]:)[/noparse]
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-07-13 18:24
    COUNT 60000 = RPM····· (if 60000 = 60,000 msec)

    COUNT· 6000 = RPM / 10
  • nige66nige66 Posts: 12
    edited 2006-07-13 21:12
    Hey thanks for the replys, I'll check out the help page with the COUNT command, and let you know if I need any other tips

    thanks

    nige
  • Jim FouchJim Fouch Posts: 395
    edited 2006-07-13 23:02
    his is scary...I was up till 2am last night working on this very same type of project. I'm trying to add a Tach to my 2000 GMC Safari Van. I found a Crank Case Position signal that has a width ~15ms @ Idle (~600RPM) I'm using Bean's display and SX/B w/ the new Count method.

    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
  • BeanBean Posts: 8,129
    edited 2006-07-13 23:25
    PJ,
    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
    ·
  • nige66nige66 Posts: 12
    edited 2006-07-14 03:35
    I saw jim's info on his motor tach application, my application is more of an industrial one rather than automotive however the similarities are there with the code required, the electric motor has a 2 pole magnet which activates a hall effect as it passes, the 6 pulses per rev come from it driving a gear of different ratio , so i'm taking my input off the motor rather than the final drive output, the sx will basically replace a moving coil meter and circuit measuring off the same point.

    All this stuff is good to get the brains cells moving.

    thanks

    nige
  • nige66nige66 Posts: 12
    edited 2006-07-14 10:57
    O.K got started using the Count command and had some success using the Watch in debug I'm using the Pro development kit with the on board pulse generator and am picking up with the count command the variations in freq either 100 hz or 1000hz , I am getting other characters to the LCD o.k but I'm not sure how I should be treating the freq value to get it to display on LCD as dec rather than weird characters "pedd* " ect. Had a look through the help but nothing jumps out as far as converting dec to ascii,

    Whats your thoughts?

    count freqin, duration, hertz

    tx_byte lcdline1
    tx_str hertz

    thanks

    nige
  • BeanBean Posts: 8,129
    edited 2006-07-14 12:22
    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
    ·
  • SawmillerSawmiller Posts: 276
    edited 2006-07-14 14:21
    dont know if this helps, but i've had problems before with lcd's displaying wierd chars till i added the ascii number for "a" to the char i was outputing..basicly moved it up to the char set, instead of unprintable chars..

    hope this helps

    dan
  • nige66nige66 Posts: 12
    edited 2006-07-14 21:21
    Thanks I'll look at those items , and see how it goes.

    regards

    nige
  • nige66nige66 Posts: 12
    edited 2006-07-16 22:20
    Hey Bean,

    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
  • nige66nige66 Posts: 12
    edited 2006-07-16 22:28
    opps forgot to post the file ,
  • Dave HeinDave Hein Posts: 6,347
    edited 2006-07-17 14:22
    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
  • nige66nige66 Posts: 12
    edited 2006-07-21 00:49
    Found a way around the one Byte limitation, did math in word , then used the LSB to get answer for output to serial LCD

    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
Sign In or Register to comment.