Cruise Control


Closed Thread
Results 1 to 21 of 21

Thread: Cruise Control

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Posts
    42

    Default Cruise Control

    Hello All,
    For those that are interested, I'm reporting my progress on a homemade Cruise for cars and motorcycles. After mounting a stepper motor and linking it mechanically to my throttle, I tapped into my vehicles VSS, (Vehicle Speed Sensor). I also tapped into the brake light switch which provides an emergency shut-off for the unit, as well as having a good ol' on/off switch mounted inside.
    The theory of operation is fairly simple, the unit counts pulses continuously from the VSS. When a momentary switch is pushed it moves on a gets a second count from the VSS and from that point on it just continues to read pulses, comparing it to the first reading, and make adjustments to the throttle. People probably wonder why I don't just but an aftermarket cruise unit but I was just interested in creating a true feedback system that I could experiment with.
    Well after playing with some of the timing elements in the program, I got the unit to work but, with a few problems. The first problem is that it is slow to respond to hills and overcompensates trying to climb them, often engaging passing gear. On flat open roads its performance is very good.
    Another problem is that it apparently cannot read the VSS pulses past about 45 mph. I've tried increasing and decreasing the timing in my COUNT statements, but to no avail. I have also tried the divide reading by 2 and /10 method, but still no luck. It may be necessary to mount a magnetic pick-up unit to the axle or CV joint. I am just an amateur programmer with no knowledge of assembly, C or other languages, but I need a system that continuously reads the pulses, without the delay of a count statement, and continuously makes adjustments. I am not selfish with my code, (I'm not going to sell these units), so if you have an old vehicle to play with you can play with my code. Be warned that safety is the number one factor and any tests should be far from city traffic. Also, I am not responsible for any mishaps, THIS IS ALL JUST TEST CODE, USE AT YOUR OWN RISK. For those that wish to weigh in on better code, your input will be greatly valued. Thanks in advance.

    ' Cruise Control Program
    ' Microcontroller used: 16F88
    ' 20 MHZ CRYSTAL fuse at hs
    ' Porta.0 - Porta.3 are stepper motor outputs
    ' Portb.0 is signal in from VSS (Vehicle Speed Sensor)
    ' Portb.1 is the signal to engage when 5v is applied. 10K tied to ground
    ' Portb.2 is tied to the brake switch. 10 k tied to ground
    ' Fine tuning may needed to the "ti" and "ts" variables for vehicle,
    ' ts may need to be a "byte" instead of "word". Depending on pulses per second


    START:
    define osc 20
    clear
    C1 VAR word
    I VAR WORD
    ti var byte
    ts var word
    B1 var word
    B2 VAR word
    TRISa = %00000000
    trisb = %00000111
    portb = 0
    porta = 0
    C1 = 5000 ' var. controls pause if b2=b1 (0 - 65000)
    ti = 200 ' stepper motor speed (20 - 200)
    ts = 5000 ' this changes how long of a count in milliseconds (100-2500)

    INIT:
    IF PORTb.1 = 1 THEN COUNTER1 'Press sw1 to engage
    pause 100
    GOTO INIT


    COUNTER1:
    IF TS < 1000 THEN TS = 1000
    count portb.0 ,ts, B1 ' read pulses from vss for ? second
    PORTB.3 = 1
    pause 100


    CRUISE:
    count portb.0 ,ts, B2 ' get a second reading and store in B2
    PORTB.4 = 1
    IF PORTb.2 = 1 THEN porta = 0:goto START ' BRAKE LIGHT SIGNAL, kill NOW
    IF B2 < B1 - 3 THEN FORW
    IF B2 > B1 + 3 THEN REVR


    Lock:
    FOR I = 1 TO c1
    IF PORTb.2 = 1 THEN porta = 0:goto START
    NEXT I
    goto cruise


    FORW:
    PORTa = %00000011
    PAUSe ti
    PORTa = %00000110
    PAUSE ti
    PORTa = %00001100
    PAUSE ti
    PORTa = %00001001
    PAUSE ti
    GOTO cruise


    REVR:
    PORTa = %00001001
    PAUSE ti
    PORTa = %00001100
    PAUSE ti
    PORTa = %00000110
    PAUSE ti
    PORTa = %00000011
    PAUSE ti
    GOTO cruise

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    You can't beat an interrupt driven speed calculation routine.
    Then that part your program won't be held up by any PBP command at all.

  3. #3
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    Yes Art you keep taunting me about interrupts and how great they are, I agree. Well I've shown you my code, why don't you help a guy out instead of sniveling, and add to it.

  4. #4
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    Quote Originally Posted by Picstar View Post
    Yes Art you keep taunting me about interrupts and how great they are, I agree. Well I've shown you my code, why don't you help a guy out instead of sniveling, and add to it.
    Uh ... surely you are joking .... right? Because I heard no sniveling.

    Lot's of people are here to help you. But very few are here to do all your work for you ...
    http://www.scalerobotics.com

  5. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    What you want is not much different from the interrupt code I posted in your other thread.
    You just need to add a line to count the interrupt events.

    Regardless, I would begin with DTs Elapsed Time code,
    and add the portb.0 interrupt from there.

    If you just get the elapsed timer working,
    so you can check within any program that the SecondsChanged
    variable is set (a second has ticked over),
    it already contains an interrupt routine for a timer.
    Then trust me, I'm in a good position to help you.

    You don't add to what you've got,
    best put it aside and use parts of it that do what you want,
    but consider beginning with the Elapsed timer demo and adding what you need to that.
    Last edited by Art; - 7th March 2012 at 01:10.

  6. #6
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    Well S.C. , I've done my own work, but there are several concepts that are a little beyond my grasp, although I'm trying. I am 67 years old and its a little bit hard to understand when someone says, " Just cut and paste this here, and write an assembler routine and add it here....". I have bought books like, "Revolutionary Assembly Language" and "Learning Assembly Language the Easy Way", all to no avail. I guess its like a cave man trying to understand a computer. At some point in our lives things just don't sink in that well. But I do appreciate Art's input but its like asking your mechanic what is wrong with your car and he replies "read the book".
    Maybe I should just quit, throw away the development board and PBP and just watch tv all the time, would that be better?

  7. #7
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    Bruce has a nice pulse measurement example using CCP1 interrupts. This might give you a head start, although it was written for a PIC18F242. It is well commented. This could replace the pulsin part of your code, so that your speed detection is much more accurate. http://www.picbasic.co.uk/forum/cont...-DT-Interrupts (the second code example uses Darrel Taylor's Interrupts.)
    http://www.scalerobotics.com

  8. #8
    Join Date
    Aug 2007
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    I am pretty much a rookie. I have to second the CCP (runs in the background) method. I was doing a speedometer project a while back and started with count, then pulsein, then looked at interrupts. Instead, I went with CCP with excellent results. Accurate and no missing pulses...and a bit easier concept (for me at the time) than trying to grasp the mystical world of interrupts. Start your timer, check to see if the CCP flag is set, and if so, look at the CCP register to get the resulting time elapsed. If the time is long and the timer overflows, you have to account for that. You may want to add an averaging or filter routine once you get an accurate speed measurement. Programming is not that hard if you do it in small bits(haha), test them and go on to the next portion of code for your project. It is time consuming and frustrating until you get it to work, it then seems simple and clear and rewarding. I am not famialir with flowcode, but PicBasic is an excellent alternative to learning assembly or C. It gives you plenty of control and access to the micro while keeping the compiled code compact.

  9. #9
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    I appreciate your insight chips123. Yes, I am still studying CCP and have found a few examples on the net. It is a puzzling project, more than I thought at first, because a "real" cruise control system does things like: slowing down before cresting a hill, so as not to overspeed, also it "smooths" out acceleration and if possible finds a spot that it locks at on straight roads. I am still trying to figure out whether I need to use just one CCP module or do I need two of them. Anyhow any chance of your showing some code of your experiments? Thanks

  10. #10
    Join Date
    Aug 2007
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    I would think you would only need one ccp. You are just trying to monitor the one thing, vehicle speed. The smoothing out part is a whole other portion of code, I presume. That is where the averaging/filtering will come in. I will look for that code tonight, as I should go to work now.

  11. #11
    Join Date
    Aug 2007
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    Below is a snippet. I did this a long time ago, so it is not that fresh in my mind.

    Remember that it does not give you the speed or the time between pulses directly. It provides the number of "counts" or "clicks" that have taken place and each count represents x microseconds which depends on clock speed, ccp setup and so on.

    The PIR1.5 may not be the correct for your specific chip.

    Hope this give you some direction.


    Code:
    'configure your PIR, PIE and CCP registers, etc as needed for your specific chip.
    
    start: 'do something here like display time or speed
    
    
    waithigh: 'wait here for rising edge and  
                  'handle timer overflow as needed
    
    
        if PIR1.5 = 0 then waithigh     'wait for rising edge
            TMR1L = 0                       'start timer over
            TMR1H = 0
            PIR1.5 = 0                      'clear ccp flag
                                   
            clicks.byte0 = CCPR1L           'value of ccp to clicks variable
            clicks.Byte1 = CCPR1H
    
           'do something here like calculate time
           'do something here like calculate speed
    
        goto start

Members who have read this thread : 0

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