PBP projects for R/C models


Closed Thread
Results 1 to 40 of 772

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Hey Ken, you can either take the serial out, or change it a bit. Here is one to use a slower baudrate, without using the baudcon.3 setting.

    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 64 ' 19200 Baud @ 20MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically

    I use a program from Mister E, called Mister E PIC Multi-Calc that spits all these above settings out after you pic a baud rate. Pretty cool! http://www.picbasic.co.uk/forum/show...9&postcount=38

    Sometimes PIC chips can be a pain because the newer chips will move things around on us. So when we try to learn a different chip, or upgrade to a different part, things do not work without a bit of leg work.

    I was using a PIC18F2520, which had a register called T0CON for adjusting the Timer0 or TMR0. That sounds like it makes sense. However, on the PIC16F887 that you are using, the same Timer0 TMR0 is adjusted by using .... the Option Register. Not quite making as much sense, is it.

    Anyway.... HOW do I know this? Answer: I do not. I have to look up both data sheets for each of those pic chips, and compare them. Not all 375 pages, but just whatever portions I think are giving me trouble. In this case, the Timer0. Then I have to see that everything that is set in the PIC18F2520 for the timer, is set for the PIC16F887. Then I will probably have to do the same thing for the other timers. AND, it will probably not work when I first try it, because I will probably miss something.

    So, looking at page 77 of your data sheet, and page 125 of my data sheet, lets see what we can screw up, I mean "test".

    Well I had it set to:

    TMR0ON - off
    T08Bit - configured as a 16 bit timer (this could be a problem)
    T0CS - Internal instruction cycle clock
    T0SE - increment on low to high transition of clock pin
    PSA - use prescaler selection bits
    T0PS - 1:4 prescaler selection bits

    Now lets see what we have for the Option register...
    Well, looking at the data sheet, your chip's T0 is only 8 bit, but if we are lucky, we will just have lower resolution. Timer0 is the time base for creating a servo pulse out from 1 to 2 ms.

    Option_Reg
    RBPU - Port B pull ups (nothing to do with timer) probably leave off - 1
    INTEDG - Nothing to do with timer
    T0CS - keep at 0 like above
    T0SE - keep at 0 like above
    PSA - keep at 0 like above
    PS - we can start at 001 like above, but we might have to change things up since this
    is not a 16 bit timer.....If I was smarter about how these worked, I could mathematically figure this out.....

    Now, how do we start this timer0, because it looks like bit 7 is NOT going to do this for us...

    To be continued .....
    Last edited by ScaleRobotics; - 18th January 2010 at 05:34.

  2. #2
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    Scalerobotics,

    Bravo! very well laid out explanation (well at least part one). That is the kind of stuff that drives newbees nuts and makes them give up in frustration. There is no easy place to learn it if you don't have a mentor. Patient, concise, and relevant. Nice job.

    Bo

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


    Did you find this post helpful? Yes | No

    Default Thank you both

    I awoke this morning looking out my window onto eight new inches of wind packed snow. Plenty of time to think.

    What scalerobotics said makes sense to me. In 1957 I was programming the AN/FSQ-7 SAGE Air Defense computer. We worked in machine language. It took us years to develop and distribute a symbol and subroutine library sufficient to allow us to focus on the radar data reading, intercept calculating algorithms needed to accomplish air defense. Building this subroutine library was a big task. The architecture of the machine did not change.

    This morning I said to myself, "Back to basics." It may have been a mistake for me to purchase PICbasic PRO. Without being able to tap into the developments of others on the 16F88x structure, I may be better off in ASM. That way I will be forced back to basics.

    This world of microprocessors reopens the academic importance of old fashioned "computer science". I was afraid that we had become too product oriented to care what is a "register".

    I have two PIC books:
    PIC PROJECTS by Parchizadeh and Vuksanovic
    and
    RUNNING SMALL MOTORS WITH PIC MICROCONTROLLERS by Sandhu

    Seems like I should cease dreaming of getting a prototype to blink in sync with a PWM input signal and get back to the books. I've got plenty of time. Did I mention that we are snowed in without an all wheel drive car?

    Ken

  4. #4
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    This morning I said to myself, "Back to basics." It may have been a mistake for me to purchase PICbasic PRO. Without being able to tap into the developments of others on the 16F88x structure, I may be better off in ASM. That way I will be forced back to basics.

    This world of microprocessors reopens the academic importance of old fashioned "computer science". I was afraid that we had become too product oriented to care what is a "register".
    Ken
    Ken, I hope I did not discourage, for it was my intent to encourage. But back to basics is always a good idea, no matter what path you choose. For PIC devices, it can be a difficult task to transfer a program from one type of device to another.

    A better place to start on the learning curve, might be to use Darrel Taylors interrupt code examples, and try to get the interrupt blinking led going on your device. Then try to modify it in some way that is closer to the end product you want. In that way, it forces you to learn about different registers, but only a few at a time. Here is Darrels blinky example. http://darreltaylor.com/DT_INTS-14/blinky.html

    Joe had some great advice. In trouble shooting, it is always helpful to figure out what parts of the code DO work. I always like using the serial port to help tell me what is happening in the device, and to check register values, etc.

    Let us know how we can help you.

    Walter

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


    Did you find this post helpful? Yes | No

    Default where are the ASM macros stored?

    I got Darrel Taylor's blinky to work on my PICkit 2 16F887. I had to change the output pin to the LED to match the printed circuit on the 44 pin demo board.

    Now I would like to get blinky to interrupt on the rising edge and the falling edge of a signal coming in CCP1 which is RC2.

    Darrel Taylor's blinky contains this line

    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

    Where do I look for the definition of INT_ENABLE? I used SEARCH. I had no luck at all.

    Ken

  6. #6
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    That's a great start Ken!

    INT_ENABLE is a Darrel Taylor command for his DT_INTS. This is the same as enabling, or disabling a certain interrupt. To set up CCP interrupts, you first add a line like my code had:

    Code:
    INT_Handler   CCP1_INT,      PWMeasure,   ASM,  yes
    Then enable it:
    @ INT_ENABLE CCP1_INT

    But you will also have to configure it. Make portc.2 an input. And configure your CCP1
    CCP1CON = %00000101 ;capture every rising edge

    Now I used Chuck's code to do the capture. It needs the sub16.inc include file to be included, and we will need some variables like
    Code:
    risetime var word      ;used for pulse width measure start of pw
    falltime var word      ;time at end of pulse width
    falltime_l var falltime.byte0
    falltime_h var falltime.byte1
    risetime_l var risetime.byte0
    risetime_h var risetime.byte1
    Code:
    asm
    PWMeasure
    
        BTFSS   CCP1CON, CCP1M0 ; Check for falling edge watch
        GOTO    FALL_EDGE       ; Go pick up the falling edge
        MOVF    CCPR1L,W        ; else store leading edge value
        MOVWF   _risetime_l         ; into 16 bit word risetime
        MOVF    CCPR1H,W
        MOVWF   _risetime_h
        BCF     CCP1CON, CCP1M0 ; Now capture the trailing edge
        GOTO    ISR_2           ; Exit the interrupt service routine
            
    FALL_EDGE:
        BSF     CCP1CON, CCP1M0 ; Re-set for trailing edge capture
        MOVF    CCPR1L,W        ; Store the captured value into
        MOVWF   _falltime_l         ; falltime_l and ...
        MOVF    CCPR1H,W
        MOVWF   _falltime_h       ;             ... falltime_h
        ;
        ; 16 bit subtract 
        ;     falltime = falltime - risetime
        ;
        SUB16   _falltime, _risetime
    ISR_2
        INT_RETURN
    
    endasm
    Now, if you read the data sheet, you see in 11.1 Table 11-1 that capture mode uses timer1. So you will have to set this. Looks like it may be same settings as I have in T1CON. This will also start the timer. It runs continuously, and we don't care about interrupts on T1. We just want to read the timer at interrupt high edge of CCP1, and read timer on low edge of pulse. Then we should have a value present at falltime, representing the length of the pulse.

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


    Did you find this post helpful? Yes | No

    Default Omg

    I did not expect this project to be so discombobulating.

    Thanks to this forum's help, I think I will get it.

    ken

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