Cruise Control


Closed Thread
Results 1 to 21 of 21

Thread: Cruise Control

Hybrid View

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

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

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