Doubling the pusle count


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 44
  1. #1
    malc-c's Avatar
    malc-c Guest

    Default Doubling the pusle count

    Guys,

    Quick question. A friend has replaced his instrument consol in his wifes car, for one that has a tacho and odometer (speedo). The tacho works fine, but the speedo uses an optical sensor (from where I don't know) that uses a slotted disk to generate the pulses, the result of which is that the speedo reads half of the true speed (ie when the speedo is showing 20mph the car is actually doing 40mph.

    He has asked me if there is a way of using some form of electronics to double the count from the optical disk sensor. I did suggest replacing the disk with twice the number of slots, but he said that is impossible to do without distroying the sensor.

    I was wondering if there was any way of using a small PIC to do the job. Not sure of how the current sensor is decoded (ie if its just the square wave pusles that is checked or if it already counts the low to high / high to low pusles. - If it counts just the positive going pulses, the could a PIC be used to count the change of state which would then result in twice the count and use this to base the frequency of the outputted square wave which could then be fed to the speedo receiver ?

    The other issue is that if the encouder is running at 12v what would be the best way to reduce this voltage to the normal 5v level, would a simple voltage divider with two resistors work ?

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    Guys,

    Quick question. A friend has replaced his instrument consol in his wifes car, for one that has a tacho and odometer (speedo). The tacho works fine, but the speedo uses an optical sensor (from where I don't know) that uses a slotted disk to generate the pulses, the result of which is that the speedo reads half of the true speed (ie when the speedo is showing 20mph the car is actually doing 40mph.

    He has asked me if there is a way of using some form of electronics to double the count from the optical disk sensor. I did suggest replacing the disk with twice the number of slots, but he said that is impossible to do without distroying the sensor.

    I was wondering if there was any way of using a small PIC to do the job. Not sure of how the current sensor is decoded (ie if its just the square wave pusles that is checked or if it already counts the low to high / high to low pusles. - If it counts just the positive going pulses, the could a PIC be used to count the change of state which would then result in twice the count and use this to base the frequency of the outputted square wave which could then be fed to the speedo receiver ?

    The other issue is that if the encouder is running at 12v what would be the best way to reduce this voltage to the normal 5v level, would a simple voltage divider with two resistors work ?
    Off the top of my head (and to keep it seriously simple) you could 'COUNT' the input pulses, double that and 'FREQOUT'. I see the obvious problem with that...but them maybe setup the PWM or TMR hardware to output the doubled-pulses.

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for that - so something like Freqout=2 X pulsein.... I'll try knocking up a square wave generator and use that as a signal input to a PIC and see what happens - many thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    ....(ie when the speedo is showing 20mph the car is actually doing 40mph...


    malc-c,

    Two other solutions:

    1. Change the numbering on the speedo display.
    or
    2. Put a little note on the display telling the driver that "Drive half speed and be safe".

    -------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    malc-c,

    Two other solutions:

    1. Change the numbering on the speedo display.
    or
    2. Put a little note on the display telling the driver that "Drive half speed and be safe".

    -------------
    Yeah.. I already told my mate that the simple answer was to tippex out the numbers and letrasett new digits on the dial

    Didn't go down well !

  6. #6
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Do you know the duty cycle of the sensor output ?

    My thought is to use the "Port B interrupt on change" feature on something like the 16F88. Looking at the datasheet it seems to indicate that an interrupt will be generated on any change so low-high and high-low would both generate an interrupt.

    Create an interrupt routine that generates a short pulse on a pin and feed the speedo with that. Provided the speedo only needs to count the pulses rather than needing an exact mark/space ratio then it should work. You would obviously need to ensure that the pulse you generated was short enough to be completed in about half the time that pulses would be arriving at maximum speed.

    The only caveat is that it depends on how it calculates the speed. If it counts the number of pulses in a second then it should be OK, but if it times the interval between pulses then there could be a problem if the output of the sensor is not 50/50 as alternate generated pulses would have different spacings.

    Dont know if any of the 8 pin PICs would be able to do it as I haven used any of those yet.
    Keith

    www.diyha.co.uk
    www.kat5.tv

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what brand, year and model of car?

    the Speed Sensor is mechanical, then you MUST measure the frequency for x speed. Once you know that, i think it can be done with a 10Fxxx pic and few line of code... if the frequency is not to high of course...

    The duty cycle have to be 50%... VSS (vehicule speed sensor) are noted in Pulse Per Mile.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Malc-c,
    Tell your friend to take the car to a speedometer shop. They will install a gear increaser to calibrate the speedometer, or they will change the drive gear or driven gear. This is probably the cheapest fastest route.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Guys thanks again for your contributions

    I'll pass on the URL to this topic and let him have a read.

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Malcolm,

    Here's one for your friend.
    It doubles input pulses from somewhere around .1 hz to 750hz. (output = .2 to 1500hz)
    Should be good enough for a speedometer.

    I did it on a 12F629 and it's internal oscillator. But, you should be able to run it on just about any 14bit core. (94 words)
    If the sensor's dutycycle isn't around 50% (40-60% max), I may need to make a couple changes.

    Here's what it looks like on the scope. Top is the input, bottom is the output.



    Code:
    '****************************************************************
    '*  Name    : FREQx2.bas                                        *
    '*  Author  : Darrel Taylor                                     *
    '*  Date    : 2/27/2007                                         *
    '*  Version : 1.0                                               *
    '*  Notes   : Doubles the frequency of input pulses             *
    '*          : Range = .1hz to 750 hz (40-60% DutyCycle)         *
    '*          : Target = PIC12F629                                *
    '****************************************************************
    @  __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    DEFINE  NO_CLRWDT 1
    
    Clear
    
    SpeedPin   VAR GPIO.2                       ; Input from speed sensor
    SpeedX2Pin VAR GPIO.4                       ; Output to Speedometer
    IdleState  CON 1                            ; State of input when sensor
                                                ;    is not on a "Slot"
    LastState  VAR BIT                          ; Last state the Input changed to
    LoopCount  VAR byte                         ; Counts the loops of each pulse
    LoopCount1 VAR byte
    LoopCount2 VAR byte
    
    X2Count    VAR byte                         ; Counts the loops of output pulse
    X2Count1   VAR byte
    X2Count2   VAR byte
    
    CMCON = 7
    SpeedX2Pin = IdleState
    OUTPUT SpeedX2Pin
    
    Main:
        LoopCount = LoopCount + 1                  ; 24-bit counter
        If LoopCount = 0 Then
            LoopCount1 = LoopCount1 + 1         
            if LoopCount1 = 0 then
                LoopCount2 = LoopCount2 + 1
            endif
        endif
        IF SpeedPin <> LastState then              ; If Input State Changed?
            
            LastState = SpeedPin
            X2Count = LoopCount
            X2Count1 = LoopCount1
            X2Count2 = LoopCount2
            ASM
                bcf   STATUS,C                     ; X2Count = LoopCount / 2
                rrf   _X2Count2, F                 ; Output Pulse is half of Input
                rrf   _X2Count1, F
                rrf   _X2Count, F
            ENDASM
            LoopCount = 0                          ; reset LoopCount
            LoopCount1 = 0
            LoopCount2 = 0
            SpeedX2Pin = !IdleState                ; start Output Pulse
        else
            if SpeedX2Pin != IdleState then
                if X2Count = 0 then                ; countdown output time (24bit)
                    if X2Count1 = 0 then
                        if X2Count2 = 0 then
                            SpeedX2Pin = IdleState ; end of pulse, 
                        else                       ; wait for next transition
                            X2Count2 = X2Count2 - 1
                            X2Count1 = 255
                            X2Count  = 255
                        endif
                    else
                        X2Count1 = X2Count1 - 1
                        X2Count    = 255
                    endif
                else
                    X2Count = X2Count - 1
                endif
            else
              @ NOP                                ; Keep the loop symmetrical
              @ NOP
              @ NOP
              @ NOP
            endif
        endif
    goto Main
    end
    HTH,
    DT

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink and without PIC ???

    I remember we did that with a 4069 hex inverter ... some centuries ago.

    The trick is to trigger a simple monostable through a basic diode AND Gate on the rising edge ... and also the falling edge.

    How ???

    an inverted falling edge is a leading edge ... no more.

    That's not a "true" freq. doubler ... but it doubles the Pulse count !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  12. #12
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Sure,

    But can a monostable multivibrator measure the previous pulse width and modify it's time period accordingly?

    Added: In a single 8-pin package?
    <br>
    Last edited by Darrel Taylor; - 1st March 2007 at 09:51. Reason: 8-pin
    DT

  13. #13
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink Take it easy ...

    Hi, Darrel

    Your job is nice ...and I do appreciate !!!

    Just understand it is over the requirements ...

    But excellent example for further general development !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  14. #14
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Is it me? Or is everyone going nut's around me.

    I got a teddy bear to throw here....
    <br>
    DT

  15. #15
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    don't worry... i feel of some jealousy 'round
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  16. #16
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Is it me? Or is everyone going nut's around me.

    I got a teddy bear to throw here....
    <br>
    LOL - (seems my comment stuck )

    Well I apreciate your help Darrel.

    I have a 12F675 to hand, and I'll compile and burn the HEX to it and post it to my mate so he can try it. What would be the best way to interface the PIC to the signal, assuming it output is at 12v battery levels.

  17. #17
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    I've just received a reply from my mate


    The pulses appear to be 0-12-0 "square" wave, but not 50/50 duty cycle. the 12 volt pulse is much less than the 0 volt. I've found that a similar unit off a Ford uses a hall effect transistor and a multipole magnet, very similar to a heli throttle govenor.

    Frequency...difficult right now to get you an accurate figure for the maximum..minimum is easy, it's 0....LOL. I can't imagine it would be more than 1 khz maximum on the unit I have.
    Does this help to determin the adjustments for the code

  18. #18
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    o.k. ONCE again

    which car model, brand, year?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  19. #19
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    o.k. ONCE again

    which car model, brand, year?
    Probably not going to mean much to you.

    Make and Model: Vauxhall Corsa
    Year: ? no idea - will ask him.

    All I had to go on was:
    My wife Jenny has a Vauxhall Corsa that had just a cable driven speedo. I've gotten hold of an insrtumanet cluster that has tacho and speedo, but the speedo isn't cable, it's electrical. The tach works fine, but the rotary encoder I've picked up (which is supposed to be the right one) is giving only half the number of pulses required by the speedo, i.e. the speedo is reading half the actual speed.
    The question I have is....."Is there a simple way to double the number of pulses to the speedo...like a frequency doubling circuit" ??

    I believe the unit I have works optically...disc with 10 light dark changes per rev. The easy answer would be to put a disc in the unit with twice the number of segments, but it's not able to be disassembled easily.

  20. #20
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Maybe you didn't know it alrady but, i've been a car accessoiries installer (alarm, car starter, radio, gps, etc etc ) for over 12 years and i still do some custom car modification here and there.

    Why i asked, is because most cruise control brand have their own application list and hints. Even on some VSS generated cable, some cars may have another source for an optional Cruise control or else. And you was right... i never see any opel/vauxhall here... only few picture here and there over the web.

    Anyways, without knowing the exact frequency range, Darrel's example have to work within it's range... no doubt on it!

    To interface.. a simple NPN or PNP or simple OP-AMP would do the job pretty well. I don't think 12V amplitude is really needed... maybe 5Volts could work... with a simple resistor in serie.

    Hey.. you didn't SIMed it this time ?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  21. #21
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Steve, no I didn't know you had the automotive electrical experience.

    I'm off to download some spice application and SIM this... or should I just contact a local PCB house and get them to send me a prototype... afterall if its wrong I'll bin that one and order another

    Any chance of a quick schematic on the input.. I was planning on using a small 100mA 5v reg for the PICs supply, and assume that the transistor would be between +5 and gnd (C and E) with the base connected to the sensor ?

  22. #22
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    What i suspect to work... is something as simple as...
    <img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1433&stc=1&d=117279195 7">

    for the input, a simple resistor in serie will work without problem (1-10k), OR a simple voltage divider.
    Attached Images Attached Images  
    Last edited by mister_e; - 1st March 2007 at 23:48.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  23. #23
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The pulses appear to be 0-12-0 "square" wave, but not 50/50 duty cycle.
    I was hoping it would be the easy way (50%).
    Oh well, back to the drawing board. I'm re-writing it now.

    Should have something later today (that's probably tomorrow for your time period).
    <br>
    DT

  24. #24
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Darrel... i don't think it will be revealant to be 50% or not... it's all about pulse/miles after all.

    In the good ol' time we installed 2 magnetic sensor on the drive shaft as a VSS generator. using that... no way you could have a 50% duty cycle as the magnets where about 1 inch wide.

    I should take a car ride here and record the VSS signal to see how clean it is... in case some want to know.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  25. #25
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    AAAAAAAAAAAHAHAHAHAHAHHA i knew that one of my OLD cruise control installation manual would be handy one day or another... here's a quote of the revealant part...
    <table><tr><td></td><td>
    Quote Originally Posted by Good ol' dusty manual
    Using a multimeter to measure the frequency
    of the VSS pulse. Usually, the PPM
    (pulses per mile) of the VSS signal is
    known. At 40 km/hr (25 mph) the following
    frequencies should be:
    2000 PPM : 14 hz
    4000 PPM : 28 hz
    5000 PPM : 35 hz
    8000 PPM : 56 hz
    </td><td></td></tr></table>
    Last edited by mister_e; - 2nd March 2007 at 01:04.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  26. #26
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    It was easier than I thought, just more of the same stuff.

    <table><tr><td>
    IdleState CON 0
    </td><td>
    IdleState CON 1
    </td></tr></table>
    Code:
    '****************************************************************
    '*  Name    : FREQx2.bas                                        *
    '*  Author  : Darrel Taylor                                     *
    '*  Date    : 3/1/2007                                          *
    '*  Version : 2.0                                               *
    '*  Notes   : Doubles the frequency of input pulses,            *
    '*          : and maintains the same DutyCycle as the Input.    *
    '*          : Range = .1hz to 500 hz  (0-40% DutyCyle)          *
    '*          : Target = PIC12F629/675                            *
    '****************************************************************
    @  __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    DEFINE  NO_CLRWDT 1
    
    Clear
    
    SpeedPin   VAR GPIO.2                       ; Input from speed sensor
    SpeedX2Pin VAR GPIO.4                       ; Output to Speedometer
    IdleState  CON 0                            ; State of input when sensor
                                                ;    is not on a "Slot"
    NotIdle    CON IdleState ^ 1
    LastState  VAR BIT                          ; Last state the Input changed to
    LoopCount  VAR byte                         ; Counts the loops of each pulse
    LoopCount1 VAR byte
    LoopCount2 VAR byte
    
    PulseWidth  VAR byte  BANK0                 ; Counts the loops of output pulse
    PulseWidth1 VAR byte  BANK0
    PulseWidth2 VAR byte  BANK0
    
    LastPulseWidth  VAR byte                    ; saved width of last pulse
    LastPulseWidth1 VAR byte                    ;    so it can duplicate it
    LastPulseWidth2 VAR byte
    
    CycleWidth  VAR byte  BANK0                 ; Counts the loops of output cycle
    CycleWidth1 VAR byte  BANK0
    CycleWidth2 VAR byte  BANK0
    
    OutPulseCount VAR BIT
    
    
    CMCON = 7
    'ANSEL = 0    ; for 12F675
    
    SpeedX2Pin = IdleState
    OUTPUT SpeedX2Pin
    
    Main:
        LoopCount = LoopCount + 1               ; 24-bit counter
        If LoopCount = 0 Then
            LoopCount1 = LoopCount1 + 1         
            if LoopCount1 = 0 then
                LoopCount2 = LoopCount2 + 1
            endif
        endif
        IF SpeedPin <> LastState then           ; If Input State Changed?
            LastState = SpeedPin
            
            if LastState = NotIdle then         ; Start of Input Pulse
                CycleWidth  = LoopCount
                CycleWidth1 = LoopCount1
                CycleWidth2 = LoopCount2
                ASM
                    bcf   STATUS,C              ; CycleWidth = LoopCount / 2
                    rrf   _CycleWidth2, F       ; Output Cycle is half of Input
                    rrf   _CycleWidth1, F
                    rrf   _CycleWidth, F
                ENDASM
                LoopCount  = 0                  ; reset LoopCount
                LoopCount1 = 0
                LoopCount2 = 0
            else                                ; End of Input Pulse
                PulseWidth  = LoopCount
                PulseWidth1 = LoopCount1
                PulseWidth2 = LoopCount2
                ASM
                    bcf   STATUS,C              ; PulseWidth = PulseWidth / 2
                    rrf   _PulseWidth2, F       ; Output Pulse is half of Input
                    rrf   _PulseWidth1, F
                    rrf   _PulseWidth, F
                ENDASM
                LastPulseWidth = PulseWidth
                LastPulseWidth1 = PulseWidth1
                LastPulseWidth2 = PulseWidth2
                SpeedX2Pin = NotIdle            ; start First Output Pulse
                OutPulseCount = 0
            endif
        else
            if SpeedX2Pin = NotIdle then
                if PulseWidth = 0 then          ; countdown output time (24bit)
                    if PulseWidth1 = 0 then
                        if PulseWidth2 = 0 then
                            SpeedX2Pin = IdleState ; end of pulse, 
                        else                       ; wait for next transition
                            PulseWidth2 = PulseWidth2 - 1
                            PulseWidth1 = 255
                            PulseWidth  = 255
                        endif
                    else
                        PulseWidth1 = PulseWidth1 - 1
                        PulseWidth  = 255
                    endif
                else
                    PulseWidth = PulseWidth - 1
                endif
            else
              @ NOP                             ; Keep the loop symmetrical
              @ NOP
              @ NOP
              @ NOP
              @ NOP
            endif
            
            if OutPulseCount = 0 then
                if CycleWidth = 0 then          ; countdown to Midpoint of cycle
                    if CycleWidth1 = 0 then
                        if CycleWidth2 = 0 then
                            SpeedX2Pin = NotIdle ; Start second pulse
                            OutPulseCount = 1
                            PulseWidth  = LastPulseWidth
                            PulseWidth1 = LastPulseWidth1
                            PulseWidth2 = LastPulseWidth2
                        else
                            CycleWidth2 = CycleWidth2 - 1
                            CycleWidth1 = 255
                            CycleWidth  = 255
                        endif
                    else
                        CycleWidth1 = CycleWidth1 - 1
                        CycleWidth  = 255
                    endif
                else
                    CycleWidth = CycleWidth - 1
                endif
            else
              @ NOP                             ; Keep the loop symmetrical
              @ NOP
              @ NOP
              @ NOP
            endif
        endif
    goto Main
    end
    HTH,
    DT

  27. #27
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    The knowledge and experience you guys have amaizes me !

    Woke up this morning and checked this thread and found a suggested schematic from Steve and revised code from Darrel ! - Thanks guys.

    I'll compile and burn the code to a 12F675 and send it to my mate for testing.. I'll report back on his findings in a couple of days

  28. #28
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    The knowledge and experience you guys have amaizes me !

    Woke up this morning and checked this thread and found a suggested schematic from Steve and revised code from Darrel ! - Thanks guys.

    I'll compile and burn the code to a 12F675 and send it to my mate for testing.. I'll report back on his findings in a couple of days
    I would just like to point out that in the event of your mate getting caught for speeding, Steve and Darrels contribution towards the speeding fine will be limited to the amount paid for the code and schematic
    Keith

    www.diyha.co.uk
    www.kat5.tv

  29. #29
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I don't know if I could afford that Keith

    I think Steve's circuit will invert the output, so I'll need to reverse the pulse in the program to be able to use that.

    And you need an input circuit. I was thinking something like the circuit below might be nice. And, I'll need to make it use the GP0 input to determine what the Idle polarity is.

    I smell a Version 3.

    I tried something else, then realized it wouldn't work.
    What do you think about this one.

    Click Image to Enlarge

    Click Image to Enlarge
    DT

  30. #30
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Keith, I like where you're coming from

    Darrel, that looks good. I've already pointed my mate to this forum so he can keep up to speed to see what a stirling effort you guys are doing !

    Thanks guys !

  31. #31
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Well, for whomever will be using it in the end ...

    Here's version 3. Hopefully the last one.
    I think I covered all the bases.

    Added another input. (see schematic above) GPIO.1 that determines if the output is inverted or not. It has a weak Pull-up, so you can just leave it disconnected for use with the NPN transistor.

    Code:
    '****************************************************************
    '*  Name    : FREQx2.bas                                        *
    '*  Author  : Darrel Taylor                                     *
    '*  Date    : 3/2/2007                                          *
    '*  Version : 3.0                                               *
    '*  Notes   : Doubles the frequency of input pulses,            *
    '*          : and maintains the same DutyCycle as the Input.    *
    '*          : Range = .1hz to 500 hz  (0-40% max DutyCyle)      *
    '*          : Target = PIC12F629/675                            *
    '****************************************************************
    @  __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    DEFINE  NO_CLRWDT 1
    
    Clear
    
    SpeedPin   VAR GPIO.2                       ; Input from speed sensor
    SpeedX2Pin VAR GPIO.4                       ; Output to Speedometer
    IdleState  VAR GPIO.0                       ; State of input when sensor
                                                ;    is not on a "Slot"
    Invert     VAR GPIO.1                       ; Inverts output if = 1
    
    OPTION_REG.7 = 0                            ; enable weak Pull-ups
    WPU = 3                                     ; weak Pull-up on GP0 and GP1      
    ;_____________________________________________________________________________
    
    LastState  VAR BIT                          ; Last state the Input changed to
    LoopCount  VAR byte                         ; Counts the loops of each pulse
    LoopCount1 VAR byte
    LoopCount2 VAR byte
    
    PulseWidth  VAR byte  BANK0                 ; Counts the loops of output pulse
    PulseWidth1 VAR byte  BANK0
    PulseWidth2 VAR byte  BANK0
    
    LastPulseWidth  VAR byte                    ; saved width of last pulse
    LastPulseWidth1 VAR byte                    ;    so it can duplicate it
    LastPulseWidth2 VAR byte
    
    CycleWidth  VAR byte  BANK0                 ; Counts the loops of output cycle
    CycleWidth1 VAR byte  BANK0
    CycleWidth2 VAR byte  BANK0
    
    OutPulseCount VAR BIT
    
    
    CMCON = 7
    'ANSEL = 0    ; for 12F675
    
    SpeedX2Pin = IdleState
    OUTPUT SpeedX2Pin
    
    Main:
        LoopCount = LoopCount + 1               ; 24-bit counter
        If LoopCount = 0 Then
            LoopCount1 = LoopCount1 + 1         
            if LoopCount1 = 0 then
                LoopCount2 = LoopCount2 + 1
            endif
        endif
        IF SpeedPin <> LastState then           ; If Input State Changed?
            LastState = SpeedPin
            
            if LastState = (IdleState ^ 1) then         ; Start of Input Pulse
                CycleWidth  = LoopCount
                CycleWidth1 = LoopCount1
                CycleWidth2 = LoopCount2
                ASM
                    bcf   STATUS,C              ; CycleWidth = LoopCount / 2
                    rrf   _CycleWidth2, F       ; Output Cycle is half of Input
                    rrf   _CycleWidth1, F
                    rrf   _CycleWidth, F
                ENDASM
                LoopCount  = 0                  ; reset LoopCount
                LoopCount1 = 0
                LoopCount2 = 0
            else                                ; End of Input Pulse
                PulseWidth  = LoopCount
                PulseWidth1 = LoopCount1
                PulseWidth2 = LoopCount2
                ASM
                    bcf   STATUS,C              ; PulseWidth = PulseWidth / 2
                    rrf   _PulseWidth2, F       ; Output Pulse is half of Input
                    rrf   _PulseWidth1, F
                    rrf   _PulseWidth, F
                ENDASM
                LastPulseWidth = PulseWidth
                LastPulseWidth1 = PulseWidth1
                LastPulseWidth2 = PulseWidth2
                SpeedX2Pin = ((IdleState ^ 1) ^ Invert) ; start First Output Pulse
                OutPulseCount = 0
            endif
        else
            if SpeedX2Pin = ((IdleState ^ 1) ^ Invert) then
                if PulseWidth = 0 then          ; countdown output time (24bit)
                    if PulseWidth1 = 0 then
                        if PulseWidth2 = 0 then
                            SpeedX2Pin = (IdleState ^ Invert) ; end of pulse, 
                        else                       ; wait for next transition
                            PulseWidth2 = PulseWidth2 - 1
                            PulseWidth1 = 255
                            PulseWidth  = 255
                        endif
                    else
                        PulseWidth1 = PulseWidth1 - 1
                        PulseWidth  = 255
                    endif
                else
                    PulseWidth = PulseWidth - 1
                endif
            else
              @ NOP                             ; Keep the loop symmetrical
              @ NOP
              @ NOP
              @ NOP
              @ NOP
              @ NOP
            endif
            
            if OutPulseCount = 0 then
                if CycleWidth = 0 then          ; countdown to Midpoint of cycle
                    if CycleWidth1 = 0 then
                        if CycleWidth2 = 0 then
                            SpeedX2Pin = ((IdleState ^ 1) ^ Invert) ; Start second pulse
                            OutPulseCount = 1
                            PulseWidth  = LastPulseWidth
                            PulseWidth1 = LastPulseWidth1
                            PulseWidth2 = LastPulseWidth2
                        else
                            CycleWidth2 = CycleWidth2 - 1
                            CycleWidth1 = 255
                            CycleWidth  = 255
                        endif
                    else
                        CycleWidth1 = CycleWidth1 - 1
                        CycleWidth  = 255
                    endif
                else
                    CycleWidth = CycleWidth - 1
                endif
            else
              @ NOP                             ; Keep the loop symmetrical
              @ NOP
              @ NOP
              @ NOP
              @ NOP
            endif
        endif
    goto Main
    end
    You come up with some fun projects Malcolm. Trains, Automobiles, All we need are planes, and we're set.
    <br>
    DT

  32. #32
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink Joking ???

    Hi, Darrel

    You really want something about planes ....???

    I must have a project somewhere for you ... one minute please !

    Alain
    Last edited by Ioannis; - 20th January 2011 at 11:05. Reason: slash in [i]
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  33. #33
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    I've just received an e-mail from my mate, thought you guys might like to know that he passes on his thanks

    Malc...really looks like I've given you guys something to think about with this one. Thank them for their efforts will you and just for the record the car is a 1995 Vauxhall Corsa 1.2 injection...LS
    I've programmed the PIC with Darrels code and will build the circuit over the weekend as he doesn't have them to hand

    Thanks guys for your help, hopefully it will be positive news when he receives it and fits it to his wifes car

  34. #34
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    I've made a small PCB based on your schematic above, and sent it to my mate with the car to try. The PIC was programmed with your version 3 code.

    I've received a mail from him asking the following
    Do you think I should leave the two "control" wires open for starters and only mess with them if it doesn't work right stright off???
    The two control wires he mentions are two wires for the idle and invert options. I suggested he leaves these un-connected first off and see if there is a change in the speedo reading, but wondered if you could clarify (in laymans terms for both me and Brian) how these options affect the processing of the signal from the sensor (or how it should affact the output)

  35. #35
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    As long as the internal pull-up are good enough to reject the possible incoming noise, it won't cause any problem... but i'm not a internal-pull-up oriented guy for a final product... but once again it's me.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  36. #36
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    I thought about adding a couple of external pull up resistors, but didn't know ( I know, should of asked ) if taking them high would of caused problems.. Its not a problem as they can be added at the switch

  37. #37
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I think if there are antenna's (a.k.a. long wires) hooked up to the option pins, the internal pull-ups may not be good enough. Small jumpers or dip switches should be ok though. No problem adding external pull-ups if desired. Or you can tie them directly to VDD or VSS.

    With the IdleState pin left open, the program will assume the input idles HIGH, with negative going pulses, which is the opposite of the 0-12-0 polaraity described before. So I'd start with that pin grounded.

    The Invert input should be left open, without any wires, since that circuit uses the NPN transistor that inverts the output. It was just an option available for anyone else that might pick up the code from the forum. The output follows the same polarity as the input Idlestate, so there shouldn't be a need to change it with that circuit.

    When you programmed the chip, did you uncomment the ANSEL line?
    I was using a 12F629, but I think you're using a 675.
    <br>
    DT

  38. #38
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for the feedback.

    I did see you note on the use of the chip, and missed it completely when I programed the ver3 of the code ! Bu99er !!!

    With the ansel line remmed out and using a 12F675 - how would that effect the way the unit performed... (Brian - if you are reading this I'll send a new PIC to you if I screwed up !!)

  39. #39
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    With the ansel line remmed out and using a 12F675 - how would that effect the way the unit performed
    Without it, there won't be a performance.
    The digital Input latches are disabled while in analog mode. So it can't see the pulses, or the options.

    Sorry, I should have left it un-commented.
    DT

  40. #40
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    [sware] beep beep beeeeeP [/sware]

    I thought as much... I'll re-code and send him a replacement PIC

    Next time I'll wear my glasses !!

Similar Threads

  1. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  2. Can't get COUNT to count
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd March 2009, 23:14
  3. Count pulses between VARIABLE TIME
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2007, 12:44
  4. Multiplex Display with count comand
    By mdaweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th October 2005, 04:09
  5. Count command
    By hawk72501 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th September 2005, 19:04

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts