Cruise Control


Closed Thread
Results 1 to 21 of 21

Thread: Cruise Control

Hybrid View

  1. #1
    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

  2. #2
    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.

  3. #3
    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

  4. #4
    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.

  5. #5
    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

  6. #6
    Join Date
    Aug 2007
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    I can't figure out how to edit my post. Correction: "I hope this gives you some direction."

  7. #7
    Join Date
    Oct 2010
    Posts
    27


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    I'm not sure if your keeping up with the VSS count, but if you start missing pulses, the aliaing will kill your control. I would build a test circuit with an LCD and make sure that the VSS count works to 100mph.
    Then I think you need a PID or similar. What you appear to be doing is if the error increases over a fixed time, your output increases in a fixed manner. I would expect it to lag badly on a steep hill. I would use an equation to increase your output, based on your error like Propoutput=(sp-vss)*gain. Ideally you add a time component in this like, add error to errorvar 10 times, then add error to errorvar , multiply the errorvar by .9. then output = Propoutput +errorvar. on every loop it adds the current error and divides to give you the average of 10. This will give you a weighted increasing output as the error increases over time and decrease as the average error decreases.
    So the equation is output = Propoutput*gain + average error*gain

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