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

    Quote Originally Posted by Kenjones1935 View Post
    I do not have all the necessary includes. Judging from the code snip offered by scalerobotics I need the base interrupt system for the 16 bit machines.

    "INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
    INCLUDE "sub16.inc" ; subtract 16 bit macro"

    I have a PICkit 2 with a 16F887.
    Does a DT_INTS-16.BAS exist? Where?

    ken
    Hello Ken,

    The DT_INTS-14.bas covers the PIC16 devices. The newest version 1.00 can be found here (at botom left). http://darreltaylor.com/DT_INTS-14/intro2.html The code should be able to be modified for your chip, but there are PIC chips with more timers, and more ccp pins out there.

    It might be best to try out some of the ready made samples that Darrel gives, just to get the hang of using his interrupts, and making sure your includes, and configs are working.


    I am working on a DT_INTS based RC servo passthrough (servo pulse measurement and pulse generation, but it is a little jittery right now, so I have try to trouble shoot that.
    Last edited by ScaleRobotics; - 17th January 2010 at 02:22.

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


    Did you find this post helpful? Yes | No

    Default Maybe I should change my design

    Mr or Ms scalerobotics,

    My original idea for an RC car that could toggle between RC control and autonomous control was to have DPDT relays switching between the RC receiver PWM outputs and the PIC PWM outputs. Please see:

    http://www.ziplink.net/users/kjones/...color_copy.jpg

    I discounted the idea of routing the RC commands through the PIC as that route might be slow and/or noisy. It sounds like that is exactly what you are designing. Please keep me in touch with your progress.
    I think that design would force me to choose another PIC as it would require three inputs from the radio receiver and two outputs to the electronic speed control and the steering servo. -- all interrupt driven I would think.

    I am sort of stuck with the PICkit 2 since I have purchased three of them. They are also not toooo big. If I could get more confidence prototyping I might consider building my own PIC carrier, but just getting the prototyping bits, parts and pieces entails an hour's drive to a store with which I am not familiar.

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    Hey Ken, OK, now I understand your project, and the use of the PicKit's!

    Well, I was able to correct my servo jitter, an error on my part of course.

    Here is some code for a single servo channel pass through, using DT_INTS. Next I will try adding the other CCP pin.



    Code:
    define OSC 20
    DEFINE LOADER_USED 1         
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 42  ' 115200 Baud @ 20MHz, 0.94%
    SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    
    LED0 var portb.0
    LED1 var portb.1
    LED2 var portb.2
    halftime_bit var bit
    adcon1=15               ;sets all to digital
    TRISA=%00000000         ' Set PORTA  
    TRISB=%01110000         ' Set PortB switch inputs (not used)
    TRISC=%10000100         ' Set PortC.2 to input for ccp1
                            ' set portC.7 to input for serial port
    
    INCLUDE "DT_INTS-18.bas"  ; Base Interrupt System
    include "sub16.inc"       ; subtract 16 bit macro
    
    LED1=1                    ; Set to Output Low
    LED0=0
    led2=1
    portb.3 = 0
    servo_out var portb.3
    
    risetime var word      ;used for pulse width measure start of pw
    falltime var word      ;time at end of pulse width
    timer0 var word        ;used to load tmr0l and h bytes
    falltime_l var falltime.byte0
    falltime_h var falltime.byte1
    risetime_l var risetime.byte0
    risetime_h var risetime.byte1
    
    
    pause 1000
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            ;INT_Handler   TMR1_INT,   ToggleLED1,   ASM,  yes
            INT_Handler   TMR0_INT,     _PWMout,      ASM,  yes
            INT_Handler   CCP1_INT,      PWMeasure,   ASM,  yes
            INT_Handler   TMR2_INT,      _twentyMs,   ASM,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    T0CON = %00000001
    T1CON = %00000001
    T2CON = %01011111
    CCP1CON = %00000101
    ;@   INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts 
    @   INT_ENABLE  TMR0_INT 
    @   INT_ENABLE  CCP1_INT
    @   INT_ENABLE  TMR2_INT
    
    Main:
        NOP
        
    GOTO Main
    
    twentyMs:  ;really 10ms, but only acted on half the time
        toggle halftime_bit 
        if halftime_bit  = 1 then ;only perform this every other time this is called  
            timer0 = falltime/4   ;measured pulse length, send to 
            ;hserout [dec timer0,",",dec falltime,10,13]
            tmr0h = 255 - timer0.byte1
            tmr0l = 255 - timer0.byte0
            T0CON.7 = 1    ;start t0
            servo_out = 1     ;set servopin high        
        endif   
        @ INT_RETURN
        
    PWMout:
        T0CON.7 = 0 
        servo_out = 0         ;at completion of timer set servo pin low
        @ NOP
        @ INT_RETURN
    
    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
    Walter

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


    Did you find this post helpful? Yes | No

    Default I am stuck..

    Scalerobotics,

    The code you sent me has some incompatibilities with my system. I can fix some. Others....

    You include DT_INTS-18.bas. I have DT_INTS-14.bas a la Derral Taylor. I changed the code.

    You use "BAUDCON.3 = 1 ' Enable 16 bit baudrate generator". My compiler kicks that out. I do not know how to find out whether I have the equivalent. I do not even know how to start.

    You use T0CON.7. My system has no such thing. Again I have no idea how to find out what is my equivalent.

    Nuts! Ken

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


    Did you find this post helpful? Yes | No

    Default No BAUDCON in PIC16F8x series.

    I searched all the .inc files in the microchip/MPASM suite directory for the string BAUDCON. I got many hits. None were from the PIC16F8xx set of microprocessors.
    The hits mostly said "BAUDCON EQU h'019f'" in BANK 3.

    There are no such entrees in the PIC16F8xx .inc files.

    How do I find out what BAUDCON means in its context so that I can translate to my PICkit 2 context?

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    There are no such entrees in the PIC16F8xx .inc files.

    How do I find out what BAUDCON means in its context so that I can translate to my PICkit 2 context?
    Hi Ken,
    He is using an 18F part, look in the data sheet for the chip he is using.
    For your code just comment that line out and try it. I think I would try different settings in the defines which control the Baud Rate of the hardware serial port as he set up for 19200, but you could use that.
    Ok, 18F4520 has EUSART which uses BAUDCON and reconfigures pin as both input/output on the fly . . .
    You got snow, we got rain . . .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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

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

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

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