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

    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?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    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.

  3. #3
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    O.K. but where is the interrupt in your program? I've had PBP for 5 or 6 years now and there are somethings I just don't get and I guess never will, plus people are "tight" with their code, I guess they think you might make money off of it, heaven forbid. But with Flowcode 5 they give 50 free hours of online courses, they have a forum where you can chat with the actual designers of the software and there are numerous examples covering just about every subject in-depth.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    Hi,
    There is no interrupt in my program, since using DT-Ints have been covered many many times before on this forum and is pretty well documented on Darrels web-site I thought you might have a go at it yourself. I don't think it's matter of being tight with code it's just that each and every application is a little different so it's not just a matter of here you go, use this it'll work exactly the way YOU want.

    I have no way of testing this here so this may actually be more of a problem than help but since you seem reluctant to try yourself here goes nothing.
    First you need to download the files from Darrels web-site and place them in the PBP directory (or in the project directory). Then
    Code:
    INCLUDE "DT_INTS-14.bas"
    INCLUDE "ReEnterPBP.bas"
    Then you need to configure the interrupt source and tell the system which subroutine to call when the interrupt occurs
    Code:
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR0_INT,  _UpdateCount,   PBP,  yes
        endm
        INT_CREATE            ; Creates the interrupt processor
    ENDASM
    Here we tell the system that we want to trip an interrupt when TMR0 overflows. When that happens we want the UpdateCount subroutine to be called. That subroutine is to be written in PBP and we want the system to automatically clear the interrupt flag for us.


    Now you need to actually set up TMR0 so it interrupts at a suitable interval. At 20MHz it ticks a long a 5Mhz meaning , since it's 8bits wide, it'll overflow every (1/5000000)*256 = 51.2us. That'll be a little fast for you I think but luckily TMR0 has prescaler which you can use if disable the Watchdog timer. With the prescaler set to 1:256 you'll get an interrupt rate of (1/5000000)*256*256=13.11072ms or ~76Hz.

    TMR0 is controlled thru OPTION_REG so
    Code:
    OPTION_REG.5 = 0
    OPTION_REG.4 = 0
    OPTION_REG.3 = 0
    OPTION_REG.2 = 1
    OPTION_REG.1 = 1
    OPTION_REG.0 = 1
    This should set TMR0 up in "free running mode" with a prescaler of 1:256 meaning it'll overflow every 6.5536ms.

    Then you set up TMR1 as a counter as shown before.

    Then you enable the interrupt
    Code:
    @ INT_ENABLE TMR0_INT
    Now, every time the TMR0 overflow it'll call the Interrupt Service Routine called UpdateCount
    Code:
    UpdateCount:
    Tick VAR BYTE
    PulseCount VAR WORD
    oldCount VAR WORD
    
    Tick = Tick + 1
    If Tick = 76 THEN  ' Count 76 interrupts to get roughly one second
      oldCount = PulseCount   ' Previous count
      PulseCount.HighByte = TMR1H
      PulseCount.LowByte = TMR1L
      PulseCount = PulseCount - OldCount  'Take difference between this and the previous difference.
      Tick = 0
    ENDIF
    
    @ INT_RETURN   ;Return from ISR
    Now, PulseCount will be updated with the current speed automatically, in the background, once per second.

    Don't expect this to just work. I have no way of testing it here so use it as a starting point.
    Read the datasheet and compare the settings, does it match, does it add up? Read Darrels website. Do you understand how it works.

    I wouldn't expect to buy Flowcode and NOT having to read any documentaion. There ARE numerous example (here on the forum), there ARE a lot of people here to help, Darrel (who now works for MELABS) is here and if that's not enough you can always visit the forum at MELABS website where the other guys from MELABS answers questions too. I wouldn't expect anyone to write the application for you though.

    /Henrik.

  5. #5
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    Thanks for all of your help Henrik but it will take me awhile to digest all of this, maybe forever. Well, I seem to be going in circles, I think I'll go to bed and move on to another project tomorrow, because I just don't get it.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    What exactly is it you don't "get" ?
    Is it how TMR1 works a a counter? Is how TMR0 works a timer? Is it how the prescaler works? Is it how DT-INTS works? Take one part at a time, try to understand it, ask specific questions as to what you don't understand and I'm sure people will try to help and explain, I know I will, but please keep it specific otherwise it just gets overwhelming as apparently my last post was.

    /Henrik.

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Cruise Control

    "Maybe I should just quit, throw away the development board and PBP and just watch tv all the time, would that be better?"

    no, & I'm not sure what the payoff is for you in saying that.

    "I'm thinking of getting Flowcode 5 and throwing PBP away. Any thoughts?"

    PBP is not the limitation, throw it away (for a particular program) when PBP has become the limitation.

    Henrick is looking at a different approach, so don't confuse the two.

    You understand procedure, but are not using picbasic like a real language.
    Some of the conveniences provided by PBP make it too easy.
    You are closer than you think to having your eyes opened.
    Last edited by Art; - 7th March 2012 at 15:04.

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