Cruise Control


Closed Thread
Results 1 to 21 of 21

Thread: Cruise Control

Hybrid View

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

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

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

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

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    Hi,
    Another option (still involving interrupts though) is to feed the pulses to the input of TMR1 and set that up as a counter. That way the the pulses are counted in hardware and you can just "collect" the count at a suitable interval - which is where the interrupt comes in (or you could use PAUSE if you don't need to do anything else at the same time).
    Code:
    TMR1H = 0  'Clear count
    TMR1L = 0
    T1CON.1 = 1  'Set TMR1 as counter, clock on T1CKI
    Now the TMR1 will count the pulses on the T1CKI-pin and you can read it like
    Code:
    PulseCount VAR WORD
    PulseCount.HighWord = TMR1H
    PulseCount.LowWord = TMR1L
    If you don't want to reset the TRM1 count each time you can just take the difference between 'this' reading and the 'last' reading
    Code:
    oldCount VAR WORD
    oldCount = PulseCount
    PulseCount.HighWord = TMR1H
    PulseCount.LowWord = TMR1L
    PulseCount = PulseCount - oldCount
    If you call this code at a specified interval (by timer interrupt or a simple PAUSE) you'll always have the current 'speed' in the variable PulseCount. This could be done with ON INTERRUPT but DT-INTS would be 'better'. We tend to say it's easy, which it is once you know how to do it but it can be intimidating at first. However there are many examples for DT-INTS and timer interrupts on the forum. If you can't find it and/or you need help that's what we're here for but give it a try first - if this is a suitable approach to your project of course.

    /Henrik.

  6. #6
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    Thanks Henrik,
    Now I can understand this code. Using the TMR1 is exactly what I need to do. I notice that you use both a Highword and a low word, I assume this detects the rising and falling edges of the signal. But I'm still a little confused, do I add the high and low counts together? AAAAgggg.... I'm thinking of getting Flowcode 5 and throwing PBP away. Any thoughts?

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    Hi,
    No, TMR1 is 16bits wide so it consists of two bytes, TMR1H and TMR1L, meaning it can count from 0 to 65535 pulses before it rolls over. These two bytes gets "put together" into the WORD size variable called PulseCount.

    /Henrik.

    EDIT: Get Flowcode, perhaps.... Throw away PBP, not a chanse! Learning curve, yes of course but you'll get the hang of it. I bet Flowcode comes with a learning curve as well.
    Last edited by HenrikOlsson; - 7th March 2012 at 07:36.

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