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 mackrackit: where do I get your .INC

    I copied your code snip from POST #73 at 3:02 on the 28th of January.

    I noticed in the .asm code that it wanted to:

    INCLUDE "MACKRA~1.MAC"

    There is no such file in my computer. Do I need a copy? May I have one?

    Also the compiler complained that:

    Error 118: "Overwriting previous address contents (2007)

    Page 157 of DS33014K says that Error 118 occurred because "Code was previously generated for this address" I assume it is talking about address (2007). I do not see where in the .asm code this is happening. I do not even know what to look for.

    Ken

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


    Did you find this post helpful? Yes | No

    Default I need to send one pulse every 20ms

    Mackrackit,

    From what I understand your code will do a PWM every time TMR0 overflows.

    What I need to do is make this overflow happen every 20ms. That is 50 pulses per second. We have a 4 meg oscillator. If I were designing this counter I think I would have it set to 20,000 each time it overflows. I gather from page 74 of the Data Sheet that this is not possible. The biggest prescaler is 256.

    How about a routine that counts these interrupts until 1/50 of a second has elapsed then calls PWM? I would have it send one pulse out pin 1 with the duty as defined by "duty". It would look like

    PWM 1,duty,1

    I have found a section on Timers in a book called Running Small Motors with PIC Microcontrollers that has an example of MicroEngineering Labs code that makes an eight digit LCD display the time in hours, minutes and seconds. I think this code must do something like I need.

    Ken

  3. #3
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    You want 20,000 counts before it overflows. Setting the prescaler to 1:256, you will need 20,000/256 counts = 78. The counter rolls over (overflows and sets T0IF) when it reaches 255, so if you pre-load it with 255-78 = 177, then it will overflow approximately every 20mS.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    Mackrackit,
    From what I understand your code will do a PWM every time TMR0 overflows.
    The code in post #73 will toggle a LED when TMRO overflows. The LED on PORTD.7 will gradually become brighter then turn off and start over again.

    This was just an example of an interrupt working with something else going on.

    You do have to be careful with this as things will sometimes not work as expected. Like they say, the machine will do what it is told, not what you want

    This is the same code as in post #73 with some modifications to demonstrate a "pitfall".
    The START loop still has PORTD.7 PWMing the LED with PORTD.0 added to be toggled.
    Inside of the interrupt loop the same PWM that is on PORTD.7 is now on PORTD.6.

    What do you think will happen?
    What does happen?
    Code:
    '16F887 INT RUPT
    '44 PIN DEMO BOARD
    
     @ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    
     INTCON.5 = 1    'ENABLE TMR0  DATA SHEET SECTION 14.3.2
     OSCCON = %01110000 '8 Mhz
     OPTION_REG = %10000111  ' 1:256 PRESCALE
     ON INTERRUPT GOTO TLOOP
     CNT  VAR BYTE
     D    VAR BYTE
     D = 0
     HIGH PORTD.0
     PAUSE 500
    
     START:
     FOR CNT = 0 TO 150
     PWM PORTD.7,D,100
     D = D + 2
     NEXT CNT
     TOGGLE PORTD.0
     PAUSE 100
     GOTO START
    
     DISABLE
     TLOOP:
     INTCON.2=0 ' DATA SHEET SECTION 14.3.2
     TOGGLE PORTD.4
     FOR CNT = 0 TO 150
     PWM PORTD.6,D,100
     D = D + 2
     NEXT CNT
     RESUME
     ENABLE
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Code in #73 WORKS!!

    Just like you said it would.

    Now on to your next one. It compiles and works also. I see what it does. I need to figure out how.

    Thank you!!

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

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

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    I copied your code snip from POST #73 at 3:02 on the 28th of January.
    I noticed in the .asm code that it wanted to:
    INCLUDE "MACKRA~1.MAC"
    There is no such file in my computer. Do I need a copy? May I have one?
    Looks like you have the code named MACKRACKIT?
    The *.MAC file is the macro file generated by PBP. It will be in your project directory. The name is chopped to the 8.1? standards.
    Also the compiler complained that:
    Error 118: "Overwriting previous address contents (2007)
    Page 157 of DS33014K says that Error 118 occurred because "Code was previously generated for this address" I assume it is talking about address (2007). I do not see where in the .asm code this is happening. I do not even know what to look for.

    Ken
    Looks like you are setting the configs in the *.inc file. I have them in the code. Just comment that line out and it should be OK.
    Dave
    Always wear safety glasses while programming.

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 : 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