Shop OBEX P1 Docs P2 Docs Learn Events
Need a Tach converter... — Parallax Forums

Need a Tach converter...

Jeff RedingtonJeff Redington Posts: 10
edited 2007-07-01 08:12 in BASIC Stamp
In advance I want to say thank you, if you can help me with this...

I want to create a program, which I don't know how to do...

I have a pulse that varies from 0 to 7000 RPM coming from a· tachometer...
The pulses at 800 RPM are on for 5ms and then off for 20ms.

I want to read this with the Stamp and send out another pulse that is scaled...· the convertion needs to be·thus:

For every 3 pulses I need 2·· · "3 to 2"

- I had thought maybe counting the high and low pulse, so every three pulses, I would get 6 counts... then send that to a second counter... and every three counts it would send out a· pulse.· But this does not really measure the frequency and will be differently spaced at the RPM's of the motor goes up and down.

So I am hoping for, Frequency in, measured, scaled, then correct pulses out.

Thanks again,

Jeff R.

Comments

  • Larry~Larry~ Posts: 242
    edited 2007-05-14 18:16
    check out this site they have a divide by 1.5 circuit



    http://www.discovercircuits.com/DJ-Circuits/divider1.htm
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-05-15 08:44
    Capt. Quirk -

    If your basic equation is correct, then the actual formula is quite simple:

    result = variable * 2 / 3

    which merely adjusts the formula to work with whole numbers, since the Stamp will only work with whole integers and not with fractionals.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Jeff RedingtonJeff Redington Posts: 10
    edited 2007-05-17 17:07
    Ok, below is what I have for now... this measures the frequency over 50ms which it the lowest I can go. At 400 RPM this would be 1 pulse every 50ms multiplied X 20 gives me 20 pps. Thus my freq. The adjusted frequency is what I want to put out at a constant rate. Right now it is not putting this out for 50ms when it is doing the measurements. It is working otherwise putting out 13 pps as desired, but only for 950ms out of 1000.

    How can I get this to put out all the time, and still do the measurements in the background, without interupting the pulse flow. Is it possible to do this with some more direct control, (if this then that) and get the math to work it out. Without using these little programs, which have to be waited upon??? See program below:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    readfreq VAR Word
    freq VAR Word
    adjfreq VAR Word


    Setup:
    HIGH 0 ' make P0 high

    Main:

    COUNT 7, 50,readfreq 'read freq over 50 ms
    freq = readfreq * 20 'reading * 20 would be pps
    adjfreq = freq * 2 / 3 'adjusted freq for pulses out
    DEBUG HOME, DEC3 freq,CR
    DEBUG DEC3 adjfreq
    FREQOUT 0, 950, adjfreq
    GOTO Main
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-05-18 03:10
    Jeff Redington said...
    How can I get this to put out all the time, and still do the measurements in the background, without interupting the pulse flow.
    I guess you're trying to make a glitch-free frequency converter...· shakehead.gif·.· One of the Parallax products may accomodate (Propeller?), but not a Stamp.· It's not a multi-tasking processor, it can't output as you require·and process feedback simultaneously.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-18 16:32
    One way to acheive this with a state machine would be as follows. This works similar to the circuit Larry referenced, in that the the output is triggered alternately by a rising edge and then by a falling edge of the input in a cycle of 3 edges.

    new VAR bit
    old VAR bit
    change VAR bit
    N VAR nib
    
    LOW 1 ' make p1 output
    DO
      new = in0   ' input pulse
      change = new ^ old
      old = new
      N = change + N // 3  ' cycle of 3
      out1 = 1 - (N max 1)  & change   ' pulse out when N=0 and change=1
    LOOP
    



    I think that would work at low RPMs, but it will have trouble at high RPMs. If the output is 20ms off and 5 ms on at 800 RPM, that corresponds to a frequency of 40 Hertz, or 2400 pulses per minute, which means there are 3 pulses per revolution (=2400/800). All the above code is going to take around 5 milliseconds to execute on a standard BS2, so it is going to stop working somewhere around and above 800 RPM. You could use a faster Stamp, but that would not get it up to 7000 RPM. There would be no problem though if you implement it in SX/B on an SX chip, or in assembly on an SX or PIC.

    I recently had a similar problem, to make a piece of equipment think its input was coming from one brand of anemometer when it was really coming from a different one, a spoof, involving a real time scaled frequency translation. The ratio was not simple like 2:3, but 134/213. That kind of translation takes an numerical accumulator, using logic which can handle any ratio:
    N = N + 41229 ' word variable, output pulse whenever there is a carry out. 41229 = 134*65536/213.
    The propeller counter module is very suited to that kind of thing. For a ratio of 2:3 using that kind of logic, you would do,
    N = N + 43691 ' pulse out on carry from word accumulator, ratio 2:3.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jeff RedingtonJeff Redington Posts: 10
    edited 2007-05-18 18:01
    Tracy A,

    Thanks,

    ·Yes, I need to work at higher speeds,·if I get the propeller kit, what would that program above look like for it???· Would it be similar, enough that I can understand it?

    See attached chart...· I should be clear here... it must be a 3:2 conversion...

    I just ordered the Propeller... kit...

    Can you tell me where to get the SPIN programming software, seems to be hidden somewhere, will it come with the kit I just bought, it seems from what I read it will be similar to Pbasic... and will be programmable that way.·· With the eight processors, seems that I can measure the freq. and do the conversion, one processor handling the input freq., another handling the output freq. and the rest all going for it on the conversion and handling the math...·and so forth...

    I had the development kit already for the Basic, so I just got the BS2, seems I should have listened to my "gut" and ordered this Propeller to start with.

    Am I stupid or what?· But this Propeller seems to be something else, like out of this world tech., to have 8 processors in it.· Seems I could use it to control a whole machine, do stepper control, and write letters with an ink pin, and still have processors left over to pour the coffee.

    Should have the kit by Monday, and hope again for a· little help.· Got to get this going,· have already got the "low down" on the input and out 3.3 to 5volt conversion issues, should be able to handle that end, the programming I am not to scared of, with a little help from my friends... thanks.



    Post Edited (Jeff Redington) : 5/18/2007 7:38:49 PM GMT
    656 x 132 - 20K
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-18 23:52
    It sounds like a good choice for what you want to do. The Spin code for the Propeller will look very much like the PBASIC code above.

    CON
        _clkmode = xtal1 + pll16x   ' this makes the code execute as fast as possible
        _xinfreq = 5_000_000    ' tells it what crystal frequency is driving the Prop
    
    VAR 
       byte new, old, change, N  ' same variables as PBASIC version, but using bytes instead of bits and nibs
    
    PUB twothirds      ' no frills main program routine
      dira[noparse][[/noparse] 1] := 1     ' make a1 an output
      repeat              ' does this loop indented below, forever
         new := ina[noparse][[/noparse] 0]     ' read the input pin
         change := new ^ old   ' detect change of state
         old := new          ' update state machine
         N := (change + N) // 3    ' cycle of 3 edges
         outa[noparse][[/noparse] 1] := (1 - (N <# 1)) & change   ' ouput pulse when every third edge
    



    See the one to one correspondence with the Basic? The Spin operator <# is like the Pbasic operator max, and in this case it causes the expression in (N <# 1) to equal 1 when N is either 1 or 2, and 0 only when N is zero.

    The code assumes too that the input signal is absolutely clean and does not need debouncing. Also, makes short pulses on the output pin, a1, but I see you want specific widths in mind to track RPMs. That would require some extra doing.

    Propeller Spin is, like Pbasic, a tokenized code and takes quite a speed hit compared to machine code. But on the Propeller, it is easy to throw one cog at generating the tachometer frequency conversion, and if it turns out not to be fast enough to keep up with your RPMs in Spin, there is the option to do it in assembly at blinding speeds, not much more complicated. You can find plenty of help in the Propeller forum.

    edited parentheses for order of precedence.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 5/19/2007 4:52:27 PM GMT
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-19 17:24
    I edited the Prop code in my previous post, because I had left out essential parentheses. Spin has a more well defined order of precedence of operators--I have to watch out for bugs due to my habit of writing expressions in the flat left to right manner of Pbasic.

    Here though is another approach using PBASIC on the Stamp, that outputs 2 pulses for every three at the input. It might even be fast enough to do up to near 7000 RPM. This program has an advantage that the output pulse duration is 1.5 times the input pulse duration as in your chart. The pulses are staggered, so it repeats (rest, tick, tick) at the output, like this:

    ...00001000010000100001000010000100001000010000100001... input
    ...000000000010000100000000000000100001000000000100001.... output

    DO
      PULSIN 7, 1, PW   ' wait for high PW pulse at input
      N = N + 1 // 3     ' cycle of 3
      IF N THEN PULSOUT 0, PW */ 384   ' skip N=0, output 1.5 PW on pin p0 when N=1 or 2.
    LOOP
    



    I don't know which timing parameters are important for you application. On the Prop, you have a lot of flexibility, taking advantage of the built in system counter and one or more of the 16 peripheral counter modules.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 5/21/2007 12:22:25 AM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-05-20 16:09
    Still been thinking about this.
    Was wondering whether a micro-controller was necessary?
    Attached is a schematic for a two IC solution --·yields two out
    for every three in.·
    The Frequnecy has to be at CMOS levels and·input conditioning etc.
    not included.

    Update --
    Drat, I messed up.· So, don't use this circuit, because it lets "2" through when Freq is Low.· Woe is me for I am undone.· Most humbling.
    A corrected circuit is provided a few posts down.


    Post Edited (PJ Allen) : 5/26/2007 1:42:51 PM GMT
    584 x 598 - 62K
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-21 17:01
    Neat circuit PJ! Discrete logic is still good for so many things and does it at such low power consumptiion. In these days of microprocessors, I wonder how many neat chips like the 4017 are still being designed into systems? It is so easy to throw an 8 pin micro at something like this, or a subroutine in a more powerful micro like the Stamp or Prop. That becomes necessary when the requirements of the system are more complex. We don't know which timing parameters in the topic of this thread are important.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jeff RedingtonJeff Redington Posts: 10
    edited 2007-05-21 18:54
    Timing, which are important?

    The system sending this tach information is a 6 cylinder engine distributer.· Thus the Distributer is the sender, which sends·its·pulses based on the RPM of the engine, the PW will change as the Engine runs higher RPM's, what does not change, is the percentage of the Pulse on and Pulse off,· that is what I am trying to explain in my chart.· 100% would equal the leading edge of the pulse, then the next leading edge of a pulse, the higher the RPM the less this becomes.·

    What does not change is the division of the 100%, the PW will be 20% of that total time, and the remainder will be the delay, till the next pulse.· So when looking at the chart, if the PW is 5ms on the signal, the delay till the next pulse is 20ms, this is at 800 RPM.

    I believe some of what is described above will not work, because the 20% pulse and the 80% Delay is not considered.· This will always be changing, and possibly could need to be a part of the equation?

    Does this make since or have I lost you?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-21 21:04
    Jeff, it makes sense, that the output ratio needs to be uniform from pulse to pulse as it tracks the input. One way to accomplish that in code would be to delay every other output pulse by a time interval proportional to the DW width. Something like this:

    DO
      PULSIN 7, 1, PW   ' wait for high PW pulse at input
      N = N + 1 // 2     ' cycle of 2 (but it will end up being a cycle of 3 anyway)
      SELECT N 
        CASE 0 
          PULSOUT 0, PW */ 384   ' output 1.5 PW on pin p0
        CASE 1
          PULSOUT 1, PW */ 640   ' delay time (PW*2.5) on dummy output pin
          PULSOUT 0, PW */ 384   ' output (1.5 * PW) on pin p0 when N=1 or 2.
       ENDSELECT   ' note nothing generated for N=2
    LOOP
    



    I didn't analyse it super carefully, but my hunch is that the delay in CASE 1 would make it naturally miss the third input pulse. For example, after a 5 millisecond DW pulse, in CASE 1, it would delay 12.5 milliseconds before starting the output pulse, plus the 7.5 millisecond pulse, puts it too late to detect the input pulse that occurs at the 20 millisecond point. I don't know how high the Stamp could go in frequency with this, but it would be dicey due the the interpreter overhead.

    Similar logic would have no problem on the Propeller, where it could be synced to the system clock and more than one thing can happen at once.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jeff RedingtonJeff Redington Posts: 10
    edited 2007-05-21 23:33
    I have a friend who has a collector car, which he has put in a six cylinder, where a 4 used to be, there is no tach in that model made for a 6 cylinder engine... so I have the job of creating this conversion, and I did already try the circuit mentioned at the top of this post, which I had no luck with, it did not work for me.

    I have bought the Propeller, it should be here tomorrow.·

    I am putting a new post over on the Propeller Forum Section, so will see what they come up with there.· After all this, I think I can explain what I want better.

    I really want to measure the Freq. In, Convert, and Freq. Out.· This will need to be able to read down to .5ms (500us) when operating at 7000 RPM.

    See my new post over on the Prepeller Forum.....

    I do believe that the code above stated for the Propeller, by Tracy Allen, may work.· And I may use this.

    However, the Propeller if it works as advertised, should be able to do multiple task all at once, and that with different cogs, thus not influencing the outcome of the other cogs as far as timing.

    Thanks you,

    - Jeff Redington
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-05-21 23:48
    Reviewed my "mud-chart" for my previous schematic.· Wrong-O.· In my zeal to suppress Freq I overlooked that I was·letting the "2" get through when it's HI and Freq is LO.

    For shame!

    Well, I've attached a Revised schematic, still uses only two ICs (the 3 NANDs are part of a "Quad" pkg.)

    Karnaugh map:

    ···· f··/f

    ·2·· 0·· 0

    /2·· 1·· 0


    Post Edited (PJ Allen) : 5/21/2007 11:55:11 PM GMT
    580 x 439 - 38K
  • Jeff RedingtonJeff Redington Posts: 10
    edited 2007-05-22 00:15
    I am moving this over to the Propeller Section:

    http://forums.parallax.com/showthread.php?p=651534

    As this is the Basic Stamp Section.


    I am not really interested in non-processor control, as I have learned several years ago that if you need more than 1 timer and 2 relays, you are better off with a processor,·then all you do is the programming.· The interface is much better, and the design time is less.

    Thanks,

    Jeff Redington
  • Larry~Larry~ Posts: 242
    edited 2007-05-22 16:21
    I copied below what you said was needed. Im also not sure it matters, you are getting pulses from a distributer which is about 20%on 80% off this sounds just like the timing of the Lobes of the distributer what you need to look at is what is the tach really needs or can tolerate. I would pulse a 50% duity to the tach and see if it works.

    The system sending this tach information is a 6 cylinder engine distributer. Thus the Distributer is the sender, which sends its pulses based on the RPM of the engine, the PW will change as the Engine runs higher RPM's, what does not change, is the percentage of the Pulse on and Pulse off, that is what I am trying to explain in my chart. 100% would equal the leading edge of the pulse, then the next leading edge of a pulse, the higher the RPM the less this becomes.

    What does not change is the division of the 100%, the PW will be 20% of that total time, and the remainder will be the delay, till the next pulse. So when looking at the chart, if the PW is 5ms on the signal, the delay till the next pulse is 20ms, this is at 800 RPM.

    I believe some of what is described above will not work, because the 20% pulse and the 80% Delay is not considered. This will always be changing, and possibly could need to be a part of the equation?
  • metron9metron9 Posts: 1,100
    edited 2007-05-22 18:19
    I know with a guy that fixes tachs for a living at [noparse]:http:[/noparse]//www.gaugeguys.com/

    Typically a 50% duty cycle is all a tach needs. The frequency is what sets the output.

    Since the frequency can be calculated using an interrupt (on a tiny13 for example) from rising edge to rising edge it is a simple matter to measure the length of time of a single pulse, divide by 1/2 and add that time to the original.

    I would setup an interrupt to detect rising edges.
    Start a timer on the first rising edge
    stop the timer on the second rising edge.
    calculate the time
    stuff a second timer with the time. The second timer outputs the frequency set in its compare registers.

    The main program would simply loop and the hardware timers and interrupt code would take care of everything.

    If you like, I could whip one up and send you one, the chip is only $1.25

    You would need 5V dc though so an additional regulator should be used as well as a small capacitor for the chip and capacitors for the regulator.

    I have a frequency doubler design for some older model tach outputs to use the newer tach guages. It simply doubles the frequency. I also have a voltage doubler for 6V cars that want to use the newer 12V tach guages.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • ProTechProTech Posts: 1
    edited 2007-07-01 08:12
    Could you use a 4017 (count to N and recycle) then interface with BS2?
Sign In or Register to comment.