Shop OBEX P1 Docs P2 Docs Learn Events
PULSIN running at 5mhz VS 50mhz — Parallax Forums

PULSIN running at 5mhz VS 50mhz

eagletalontimeagletalontim Posts: 1,399
edited 2009-03-10 02:47 in General Discussion
I am currently using PULSIN to read RPM's but I have changed the code that can be found on other threads for reading RPM's to output a byte variable instead of a word.· I have noticed the other RPM code is run at 50MHZ.· Would this affect my output since I only run the chip at 5MHZ?· Since I have 2 commands to read the high and low pulse times, I figure that the delay before the 2nd PULSIN is run may mess up some things.· The accuracy of my code is +/- 100 rpm according to the tach, but sometimes it will go haywire and the RPM output would be 10,000 or 0 even though I am at 2500 RPM.

Comments

  • BeanBean Posts: 8,129
    edited 2009-03-05 14:55
    You don't have any interrupts do you ? They will mess up the reading if an interrupt occurs while it is measuring.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • ZootZoot Posts: 2,227
    edited 2009-03-06 00:43
    eagletalontim -- if you were using PULSIN at 50mhz with any interrupts, you might have "gotten away with it" given the relatively low frequency of your RPMs. At 5mhz you may not. I've read a good number of your posts on this project, and seen some of Jon's code -- if you want to accurately measure ticks from a tach sensor, and if you want nice clean serial, it really would be best to use serial RX/TX (with a nice-sized buffer) in an ISR and fold your ticks measurements in there. Then your mainline will be pretty clean -- wait for serial request from host, then send current count (or a parsed version thereof, say accumulated counts, or counts divided into a standard timebase, e.g. RPM), and rock solid. Probably take a lot less code space too.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-03-06 01:39
    No, there are no interrupts since I want to stay away from them because the timing issues and me not having a clue how to work with them tongue.gif I tried to use interrupts but since I only need to read the sensors when needed, I don't think an interrupt is necessary. Same goes with the serial connection. Data is only sent when needed. It could be 1 hour before data is sent to the next chip or it could be 1 second. If there was someone I could trust with my code, I would send it to them to possibly help me better understand how to clean up my code and make it more efficient.
  • ZootZoot Posts: 2,227
    edited 2009-03-06 02:07
    Right. And what if a tick from the tach sensor comes in *while* you are SERINing or SEROUTing? You'll miss it and get inaccurate counts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-03-06 03:01
    the RPM function is called while in the running mode. If serial data needs to be sent, it will only send it after the RPM has been read.

    Here is an example :
    '  These are all functions....
    sensor1 = getsensor1
    sensor2 = getsensor2
    rpm = getrpm
    ....
    'Do stuff with the data....
    ....
    IF data_to_send = 1 THEN
       SEND_BYTE ShowData, label, data, multiplier  ' This is also a function
    ENDIF
    



    'Receiving chip
    Main:
      FOR idx = 0 TO 3
        cmd = RX_BYTE
        IF cmd = SYNC THEN Main        ' fix busted packet
        in(idx) = cmd
      NEXT
    .....
    
    
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-03-07 03:22
    ok, I have been working my hardest to get this working and accurate but I am having no luck [noparse]:([/noparse] I have the code posted below which works, but is not 100% accurate all the time. What is happening is while I am still in first gear, the RPM is pretty accurate up to about 5000 RPM....anything above that is 500 RPM off. The faster I get up into the high RPM range, the more accurate it seems to be. When in second gear and at 6500 on the stock tach, the RPM on the LCD reads 5500. And the strange thing is that at 2000 RPM in neutral reads 2000 RPM's on the LCD. What could be causing the inaccurate results at a high RPM? I do not have access to a scope so tracking this down is almost impossible for me [noparse]:([/noparse]

    FUNC getrpm
      PULSIN RPM_signal, 0, tmpW1
      PULSIN RPM_signal, 1, tmpW2
      tmpW1 = tmpW1 + tmpW2
      tmpW1 = tmpW1 * 2               'Double the signal since there are 2 pulses per revolution.
      tmpW1 = 60000 / tmpW1        'Divide by 60,000 to output Byte in _LSB and save space.
      RETURN tmpW1_LSB
      ENDFUNC
    
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-03-07 03:46
    At least simplify your calculation which also reduces
    chance on overflow.

    Try

    FUNC getrpm
      PULSIN RPM_signal, 0, tmpW1
      PULSIN RPM_signal, 1, tmpW2
      tmpW1 = tmpW1 + tmpW2
      tmpW1 = 30000 / tmpW1        'Divide by 30,000 to output Byte in _LSB and save space.
      RETURN tmpW1_LSB
      ENDFUNC
    
    



    See if your results are better now.

    regards peter
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-03-07 13:01
    ok, did not think about that tongue.gif what would be the best way to detect an overflow if it did happen?
  • VelocitVelocit Posts: 119
    edited 2009-03-07 22:55
    Check the carry bit (bit 0) in the STATUS register.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Paul
  • Desy2820Desy2820 Posts: 138
    edited 2009-03-08 03:07
    I don't have an SX.· Just thought I'd throw this out there:· Check some of the basics, such as: How clean is your power input?· I ask because I think you're testing this in a car, which is a harsh electrical environment for anything.· Are you using the car's electrical system to power the SX?··If so, make sure that your have plenty of filtering on the input power.· If you're using seperate supplies, is the sensor powered from the SX supply or the car?· You may need to connect your power supply grounds together, so they have a common reference point.· You do have to be careful, as you can also pick-up·noise through this connection.

    How far apart·are the SX and sensor?· Could you be picking up high-frequency noise on the input line from the sensor?· Try changing the routing of the wire, too close to the alternator/generator, spark plug wires, motors·or the distributor can induce lots of other frequencies, which may swamp the one you're trying to measure.

    I hope this helped, or at least gives you food for thought.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-03-08 14:25
    The board is powered by the stock wiring harness and all the sensors are connected to the same harness allowing for short connections to be made. I am going to attempt to get an o-scope so I can see the signal and if it is clean or not. The power is connected to a 10uf cap which goes through a 7805 regulator. Each chip has a .001uf cap across the Vdd and Vss terminals.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-03-10 02:18
    so far, I have not been able to find an O-Scope [noparse]:([/noparse] If there was trash being sent through the sensor line, what would be the best way to clean it up to a good input?

    [noparse][[/noparse]QUOTE]Check the carry bit (bit 0) in the STATUS register.

    How would I check the bit?

    IF tmpW1.0 = 1 THEN
    '... do something?
    ENDIF
  • ZootZoot Posts: 2,227
    edited 2009-03-10 02:47
    IF C = 0 THEN

    or

    IF C = 1 THEN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.