PBP projects for R/C models


Closed Thread
Results 1 to 40 of 772

Hybrid View

  1. #1
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default A definition pleas...

    Can anyone point me to a definition of "prescaler".
    What I thought it meant does not seem to jive with what I am seeing.

    Ken

  2. #2
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default My book fell open to the correct page.

    "Running Small Motors with PIC Microcontrollers" says, on page108

    "A pre-scaler is applied to the system clock and affects the timer by slowing down the system clock as it applies to the timer. Normally the timer is fed by a fourth of the basic clock frequency, which is called Fosc/4. In a system running a 4 MHz the timer sees a clock running at 1 MHz. If the pre-scaler is set for 1:8, the clock will be slowed down by another eight times, and the timer will see a clock at 125kHz."

    "The post-scaler setting determines how may overflows will go by before an interrupt is triggered."

    If I pre-scale TMRO 1:256 I will get overflows at about 4K per second. If I add a post-scaler of 1:64 I will end up with about 62 interrupts per second.

    Close enough for government work?

    Ken

  3. #3
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default OOPs. There is only one scaler.

    I just found in DS33023 section 11.6.

    "There is only one pre-scaler available which is mutually exclusively shared between Timer 0 and Watchdog Timer."

    So I have to count the 4000 Interrupts per second using a

    FOR CNT To 80
    NEXT

    loop. That will give me much closer to 50 pulses per second.

    Correct?

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    See my post #84 above. Which part is unclear to you?

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Hi Ken,

    I always get confused with this part of things too, so I will just point you to a couple of threads that I refer to when the need arises.

    I think maybe the parts about
    TMR1L
    TMR1H
    are the things you need to look at???

    http://www.picbasic.co.uk/forum/showthread.php?t=961
    http://list.picbasic.com/forum/messa...tml?1049090059
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    You could simplify this a great deal if your PIC has Timer1 available, and Compare,
    Capture, PWM .. by just using the Compare peripheral.

    Here's an example:
    Code:
        DEFINE OSC 4
    
        Match VAR WORD
        
        Match   = 20000         ' 20,000 * 1uS = 20mS until compare match
        CCPR1H  = Match.HighByte' Load compare register high
        CCPR1L  = Match.LowByte ' Load compare register low
        CCP1CON = %00001011     ' Compare mode, auto reset Timer1
        
        '/ TRIS & Port Setup
        PORTB.0=1
        TRISB = $FE  ' PORTB.0 output, rest inputs
        
        '/ disable interrupts
        INTCON.7 = 0 ' Disable global ints
        INTCON.6 = 0 ' Disable peripheral ints
        PIE1.0   = 0 ' Disable Timer1 int
        PIE1.2   = 0 ' Disable CCP1 int
    
        T1CON = %00000000 ' Timer1 off, internal clock, 1:1 prescale
        TMR1H = 0         ' Clear Timer1 high
        TMR1L = 0         ' Clear Timer1 low
        
        T1CON.0 = 1  ' Turn on Timer1
    
    LOOPS: ' NOTE: PIR1.2 is the CCP1IF compare interrupt flag bit.
           ' this bit is set when Timer1 reaches the value in
           ' CCPR1L & CCPR1H
        IF PIR1.2 = 1 THEN   ' If CCP1 to TMR1 compare match occured
           PORTB = PORTB ^ 1 ' Toggle PORTB.0
           PIR1.2 = 0        ' Clear compare interrupt flag bit
        ENDIF
        GOTO LOOPS
    
        END
    Just 1 single interrupt could take care of your 20mS timing VS a bunch to accumulate the
    total 20mS time period.

    A single interrupt every 20mS & no reloading anything. Timer1 is automatically cleared on
    match, and the CCPR1L/CCPR1H registers contain the value loaded into them until you
    change it.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    For 20mS timing, you can do it with a single interrupt with any of the 3 timers on the PIC16F887.

    Timer0 - Set prescaler to 1:256
    Timer1 - As shown above by Bruce
    Timer2 - Set prescaler to 1:16, set postscaler to 1:16

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP Extensions, What are they?
    By PJALM in forum PBP Extensions
    Replies: 9
    Last Post: - 28th September 2021, 11:26
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. Making PBP code more modular
    By forgie in forum General
    Replies: 30
    Last Post: - 25th October 2005, 16:24

Members who have read this thread : 1

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