PBP projects for R/C models


Closed Thread
Results 1 to 40 of 772

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest

    Default PBP projects for R/C models

    Hi,

    Following on from a suggestion on the main PBP forum, it is hoped to get people to post up code snippets for anything RC model related. I'll start the ball rolling by posting code that makes an LED pulse like a beacon and is controllable from a transmitter. - This was a result of my own bit of code and suggestions from guys on this forum on how to use pulsein command to detect the signal from the receiver.

    Code:
    '****************************************************************
    '*  Name    : RC Input - 12F675                                 *
    '*  Author  :                                                   *
    '*  Notice  : Copyright (c) 2009                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 27/10/2009                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
    ' set up PIC config
    
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    
     __CONFIG
     _INTRC_OSC_NOCLKOUT
     _WDT_ON
     _PWRTE_ON
     _MCLRE_OFF
     _BODEN_ON
    
    OPTION_REG = %10000000                      ' Pull-ups = off, GPIO.2 = I/O, prescaler to Timer1
    GPIO = %00000000                            ' All outputs = 0 on boot
    TRISIO = %00001000                          ' GPIO.3 input, GPIO.0,2,3,4,5 output
    ANSEL = 0	                                ' Set all digital
    WPU = 0                                     ' Internal pull-ups = off
    ADCON0 = 0                                  ' A/D off
    
    ;set varibles
    
    signal VAR GPIO.3                           'GPIO.3 is used to the receiver
    pulse  VAR BYTE                             'pulse is used to store the result
    led var GPIO.0                              'GPIO.0 is the output we want to flash
    i var byte                                  'i is used for the for next loop to generate width of pulses
    getout var bit                              'used to check switch routines
    
    '-------------------------------------------------------------------------------
    
    main:
    PulsIn signal, 1, pulse                     ' reads signal from receiver
    IF (pulse >= 100) AND (pulse <= 160) Then   ' threshold for activation
    Low GPIO.0                                  ' turns LED off
    Else
    goto flash                                  'if pulse is ouside range goto flash
    EndIF
    GoTo main                                   ' do it all again
    
    flash:
    for i = 1 to 254                            ' for next loop                                             
    Pwm GPIO.0,i,1                              ' send pulse to GPIO.0 for lenght i increasing brightness
    pause 1
    if i=253 then                               ' test to see value of i
    i=1                                         ' if test is true then set 1 to 1 and getout to 1
    GetOut=1 
    if Getout=1 then goto down                  ' if getout is q then jump to down routine
    endif
    next i
    
    down:                                       ' same as flash but decreases brightness
    for i = 254 to 1 step -1                                              
    Pwm GPIO.0,i,1
    pause 1
    if i=2 then                                 ' test of value i, if i =1  then
    i=1                                         ' set i to 1 and getout to 0
    GetOut=0  
    if Getout=0 then goto main                  ' test value of getout - if 0 go to start of program
    endif
    next i

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


    Did you find this post helpful? Yes | No

    Default autonomous and RC hobby car

    Please, if you are interested, take a look at the
    "How do I give a radio control car autonomous control"
    Thread. I have a PICkit 2 and PICbasic programming package.

    Attached is a sketch of what i need to do. I think. Any suggestions would be greatly appreciated. The forum does not let me attach the same file twice.

    http://www.picbasic.co.uk/forum/atta...1&d=1263008711


    Ken Jones

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


    Did you find this post helpful? Yes | No

    Default Pulse width measurement

    For pulse width measurement, I ran across an interesting page.

    http://www.mcmanis.com/chuck/robotic...e_measure.html

    I borrowed a little bit of the code, and then added it to some DT_Interrupts. I am just measuring a servo pulse width, and sending raw tmr1 result to the serial port here, but you can change it to make it do other things. This was done with a PIC18f2520 in a LAB-X2. But the above gentleman used a PIC16F628, so it should be pretty flexible if you chose the corresponding DT_INTS include file. I would like to see more examples of pulse width measurement as well as pulse generation using interrupts, so if you have some, please share!

    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
    
    adcon1=15        ;sets all to digital
    TRISA=%00000000                         ' Set PORTA  
    TRISB=%01110000                         ' Set PortB
    TRISC=%10000100                         ' Set PortC bit.2 for input (ccp) and bit.7 for ser input
    
    INCLUDE "DT_INTS-18.bas"  ; Base Interrupt System
    INCLUDE "sub16.inc"       ; subtract 16 bit macro
                       
    LED0=0
    LED2=0
    
    risetime VAR WORD
    falltime VAR WORD
    falltime_l VAR falltime.Byte0
    falltime_h VAR falltime.Byte1
    risetime_l VAR risetime.Byte0
    risetime_h VAR risetime.Byte1
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR0_INT,   ToggleLED0,   ASM,  yes
            INT_Handler    CCP1_INT,   PulseWidth,   ASM,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T0CON = %10000100
    T1CON = %00000001
    T2CON = %00111101
    CCP1CON = %00000101
    @   INT_ENABLE  TMR0_INT      ; Enable Timer 0 Interrupts 
    @   INT_ENABLE  CCP1_INT      ; Enable Capture Compare for pulse width measurement
    
    Main:
        PAUSE 1000
        HSEROUT [DEC falltime,10]
    GOTO Main
    
    ASM
    ToggleLED0
        btg  _LED0        ;blinky light
        INT_RETURN
    ENDASM
    
    
    ASM
    PulseWidth
        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          ;this subroutine performs 16 bit subtraction
    ISR_2
        INT_RETURN
    ENDASM
    Attached Files Attached Files
    Last edited by ScaleRobotics; - 10th January 2010 at 09:21.

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


    Did you find this post helpful? Yes | No

    Default I'm in trouble..

    You all posted code specifically for the 12F675. My PIC is a 16F887.

    I am at a loss to translate from one PIC to the other. My PBP compiler (set up for 16F887) has no idea what to do with GPIO.x references. When I set it for 12F675 it is happy, but the resulting code is useless to my PICkit2.

    Is it my job to read about the 12F675 and try to figure out which register in my 16F887 is equivalent? That would be an excellent homework assignment.

    Ken

  5. #5
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    Is it my job to read about the 12F675 and try to figure out which register in my 16F887 is equivalent? That would be an excellent homework assignment.
    Well, yes... but it will take a whole lot longer to open the file than it will to hit ctrl-f and search for gpio.

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


    Did you find this post helpful? Yes | No

    Default DT_INTS-xx.BAS ?

    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

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

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

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