PBP projects for R/C models


Closed Thread
Page 1 of 20 1234511 ... LastLast
Results 1 to 40 of 772
  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 10: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 03:22.

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

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

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

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

  12. #12
    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 06:34.

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

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

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

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

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

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

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

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


    Did you find this post helpful? Yes | No

    Default

    Yes, you have picked a very challenging project.

    The servo part broken down into basic steps of what is going on here. (Other interrupt sources, and different timers could be substituted, but this is what I am using).
    __________________________________________________ _________________________________________________
    Pulse Sensing:
    Using CCP interrupt and calculate (pulse_width = falltime - risetime) with CCP capture low byte CCPR1L and capture high byte CCPR1H (these use Timer1). To do this, bits must be changed from capture on rise, to capture on fall.

    Pulse Width Generation:
    Need to create interrupt from about 1ms to 2ms in length. To do this, we load a timer with pulse width value, bring servo pin high, start timer, when interrupt occurs, bring servo pin low. I used Timer0.

    Pulse Period Generation:
    Need to generate 20ms time frame for sending servo signals. I used Timer2. Servo out pins need to pulse every 20 ms.
    __________________________________________________ _________________________________________________

    On a side note:
    Now just to discombobulate things a little bit (more!), cheating can sometimes work. Problem is, that you want to run one of your outputs through a motor controller, and these don't like cheaters. They like very reliable 20ms time (Pulse Period) frames for the servo pulses. So, where you might have gotten away with using PBP's pulsin and pulsout commands for sensing and controlling servo's, you will not get away with using the pulsout command for controlling your motor controller.

    One place you could get away with a little cheating, is to use Pulsin command to sense your receiver's servo pulses. Then you would not have to worry about the servo Pulse Width sensing. I have used this with an RC autopilot project, and it was smooth enough to fly. But, since you are doing all this work learning about interrupts, and timers, you might as well do it the right way, and measure the pulse with an interrupt.
    Last edited by ScaleRobotics; - 19th January 2010 at 17:51.

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


    Did you find this post helpful? Yes | No

    Default I agree with using interrupts to measure time

    Scalerobotics.

    I have not been successful getting the RC knowledgeable folks to come clean with the exact signal pulse width specs. The hobby RC folks at our local RC Excitement racetracks and store

    http://www.rcexcitement.com/

    say that neutral (braking) is 130ms. This makes sense if the max pulse size is 256ms (2 to the 8th for convenient digital counting). How often that pulse is expected I am not sure. I think I read that the shortest pulse is about 50ms and the longest about 200ms. But I have no idea where or how I got that impression.

    It would be nice if I could implement a program on my PICkit such that my eyes could detect this variation by observing the glow of an LED.

    I neither own an oscilloscope nor have easy access to one. I do have some contacts at the Fitchburg State College Computer Science Department. I could call them and take over my car for a definitive answer.

    Enough talk. I'm supposed to be thinking and tinkering.
    Ken

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


    Did you find this post helpful? Yes | No

    Default

    Most of the RC stuff out there uses something like this, but there are exceptions:

    And it is done 50 times per second, or every 20ms.

    Quote Originally Posted by Kenjones1935 View Post
    The hobby RC folks at our local RC Excitement racetracks and store say that neutral (braking) is 130ms.
    I think the guys at your RC Excitement might be off by a decimal point or two if they are telling you neutral is 130ms.


    If that was neutral, it would take about 1 second to make any corrections to steering or throttle. In my mind that is a little slower than you need for a fast car like the one I saw in your other thread.

    Most RC receivers send out a pulse, one at a time, to each servo. So with the longest (2ms) pulse, an eight channel receiver can still fit all 8 x 2ms pulses in the 20ms bandwidth given by the cyclic 50 times per second update rate.

    Attached Images Attached Images  
    Last edited by ScaleRobotics; - 19th January 2010 at 23:49.

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


    Did you find this post helpful? Yes | No

    Default You are absolutely correct!

    These RC Excitement guys just said 150 and 125 and 175. They never said the units. I just surmised milliseconds.

    Last week you sent me two short programs. You also suggested that I go to Darrel Taylor's page and grab some code. I got his "blinky" to compile and work with the minor adjustments of changing the output to an LED register and the DT_INT-14.bas fix. I never got either of yours to compile and run.

    On page 125 of your 18F2520 spec I found T0CON containing TMR0ON, T08BIT, T0CS, T0SE, PSA, T0PS2 AND T0PS1. I could not relate any of this to the contents of pages near 77 of my 16F887 spec. I also could not find in any code you posted where you set these bits.

    Scalerobotics thought I might be able to measure the PWM radio receiver outputs if I converted it to a serial stream. Good idea, but I don't know what to do with a serial signal.

    I would feel successful if I could see on a flashing LED that my radio receiver is working and that the PIC can read it. (I know it is working because the car wheels turn.) This is the intent of the first code (RC-Input - 12F675) Scalerobotics sent me. It originate with Malcolm from Hertfordshire, UK.

    I'd like to get that working.

    Time out. Gotta check the TV for results of the Massachusetts special US Senatorial election.

    Ken

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


    Did you find this post helpful? Yes | No

    Default Another eureka moment

    You guys keep suggesting the serial signal. Could it be that you have a method of debugging/trouble shooting your microprocessor code on line?

    I just looked up USB on wikipedia. It is a "Universal Serial Buss" OH! I did not know that. So NOW I look at the "view" pull down menu on my MicroCode Studio GUI and discover "Serial Communicator" and "Easy HID USB Wizard".

    There is clearly a lot for me to learn in C:\PBP\USB. Is that where I should start? I just opened MPLAB IDE for which I could see no purpose. I am beginning to understand but I am not sure where to start.

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    Last week you sent me two short programs. You also suggested that I go to Darrel Taylor's page and grab some code. I got his "blinky" to compile and work with the minor adjustments of changing the output to an LED register and the DT_INT-14.bas fix. I never got either of yours to compile and run.
    Mine will only compile properly for a PIC18F device, for sure with a PIC18F2520. It will need some work to translate for PIC16F devices.

    On page 125 of your 18F2520 spec I found T0CON containing TMR0ON, T08BIT, T0CS, T0SE, PSA, T0PS2 AND T0PS1. I could not relate any of this to the contents of pages near 77 of my 16F887 spec. I also could not find in any code you posted where you set these bits.
    Sorry, it is page 75 in the datasheet, and page 77 on Acrobat. Look for the page that has:
    REGISTER 5-1: OPTION_REG: OPTION REGISTER on it. Where I set these registers is here:

    Code:
    T0CON = %00000001
    T1CON = %00000001
    T2CON = %01011111
    CCP1CON = %00000101
    Scalerobotics thought I might be able to measure the PWM radio receiver outputs if I converted it to a serial stream. Good idea, but I don't know what to do with a serial signal.
    You mean you don't have any computers laying around with a serial port? Yeah, I guess it is like that in my house too! Your PicKit2 comes with a great resource (in my opinion). It has a serial port built in, and you can use it to see what your program is doing. Or in this case, figure out what your Pulse Width Measurement is doing. With the Pickit2 software, go to tools, then choose the Uart tool. Make sure you are sending your serial data to the right pin. In this case, you will have to use the serout commands, as the pickit pins will not be connected the the hardware serial port. Follow the serout as defined in the PBP manual.

    I would feel successful if I could see on a flashing LED that my radio receiver is working and that the PIC can read it. (I know it is working because the car wheels turn.) This is the intent of the first code (RC-Input - 12F675) Scalerobotics sent me. It originate with Malcolm from Hertfordshire, UK.
    LED's can be a good trouble shooting tool. However, we do not even know if the timebase is going to be similar in your chip, or what crystal you are running, etc. The serial port will be able to tell you so much more about what is going on. I think you will feel even more satisfied seeing actual results.

    I'd like to get that working.
    Me too!

    One thing I learned about was MicroCode Studio's ICD (in circuit debugger). It is a great tool to see what your code is doing. It lets you step through, or view it, while allowing you to view registers, etc. I used it a lot in the beginning, then I started a few projects that were very time dependent, so I could not use the ICD in them, so I have not used it in a long time.

    And about that USB HID ... what about the back to basics part?

    -Walter
    Last edited by ScaleRobotics; - 20th January 2010 at 09:20.

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


    Did you find this post helpful? Yes | No

    Default

    Ken,

    Get a USB to serial converter. You do not want to mess with USB from the PIC at this time. Keep it simple.

    The use the serial terminal in MCS.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Looks like the PICkit Logic Tool is my answer

    I have discovered the Analyzer Tool in the PICkit Tool Logic Tool package.

    It looks like this tool will provide me a picture of the output of my radio receiver if I can get Scalerobotics' program to work. I have both MPLAB IDE and PICbasic PRO packages. They have some duplications. I have a book "PIC PROJECTS" which pontificates the advantages of MPLAB. I have an impressive PICkit Tool HELP menu.

    My impression is that the PICkit package is what I should focus upon. Does that make sense?

    Ken

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


    Did you find this post helpful? Yes | No

    Default I am completely lost.....

    I succeeded in getting scalerobotics second code sample to compile.

    This is the one that samples PWM incoming and puts it out the serial port. It created an .asm file that would not build. The list of errors is too large to publish here. (Besides that it does not word wrap well.)

    I am completely missing something. I do not understand PICBASIC PRO.The multiple hundred page microchip DATA SHEETS blow my mind. I try to read a section (16F887 Page 74 on SOFTWARE PROGRAMMABLE PRESCALER) and I can not put it in context.

    I am not sure where the basics are that I am meant to go back to. I have a couple of paperback books. Maybe I should read page by page.

    Ken

  29. #29
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    A good understanding of PIC's as well as a some idea of how BASIC works will be a great help to your success in getting this project going. Here are 2 free books that will give you a good start.

    PIC Microcontrollers
    Programming PIC MCUs in BASIC

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


    Did you find this post helpful? Yes | No

    Default How do you know of-->

    Scalerobotics,

    How did you know of the contents of:

    http://darreltaylor.com/DT_INTS-14/asm_ints.html

    and

    http://www.picbasic.co.uk/forum/show...39postcount=38

    Is there a centralized resource?

    Ken

  31. #31
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,619


    Did you find this post helpful? Yes | No

    Unhappy You sure ???

    Hi, Rmteo

    If your first reference is useful to understand the Pics themselves, the second is TOTALLY unadapted to help a PbP Beginner for Basic, as the two " basics" are much, much, much differents one from the other ...

    let's say ... Pbp looks like the old GWBasic - or very close to Parallax Basic ... But Mikroelektronika Basic ( did I say " Basiç " ??? ) looks very, very, very close to " C " ...

    Do not tell me " false " ... as I use those 3 Compilers !!!

    Sooooo, the best Basic course for PbP you can find is PARALLAX ... here:

    http://www.parallax.com/tabid/535/Default.aspx

    here ... you'll find a progressive and comprehensive learning curve, with level adapted examples, and OVERALL ...
    What you've learnt is directly re-usable ...

    last, but not least !

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default I think I am on my way.

    The computer architecture part of

    http://www.mikroe.com/en/books/picmcubook/ch0/

    reminded me of the lectures I received in 1957 when I was hired as a computer programmer by Lincoln Labs to work on the SAGE Air Defense computer. If you want to read what preceeded the picmcubook (above) look at:

    http://history.sandiego.edu/GEN/20th/sage.html

    I started my career coding for SAGE. I graduated from CISCO Systems as a Senior Software Engineer in 2003. Since that time my mind has not been focused on technology.

    I feel that my problem with PBP and the 16F887 is lack of access to the 'common knowledge'. How did scalerobotics know about darreltaylor?

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


    Did you find this post helpful? Yes | No

    Default

    How did scalerobotics know about darreltaylor?
    Darrel is one of the moderators of this forum and one of the largest contributors.
    Hands down he is the one with all of the "interesting" stuff.

    Hang around and you will meet him.

    Ken,
    You are doing fine for starting work on a new system. We talk about "basics". Just work on things one piece at a time, not the whole project. When all of the pieces work then put it all together.

    I get a laugh from the "Object Oriented" folks from other languages. And I even hear about "extreme programming".

    Us working with MCUs have been doing the above sort of thing for.... ever.
    Write your code in pieces, make sure each piece works, then combine the pieces.

    So in your case, reading the PWM is one part, get that working.
    Move on to running a motor with PWM, a separate little project and code.
    Work on the sensors, another separate project.
    And so on...

    Pretty soon you will have the whole thing finished and understand it all.

    Architecture... Princeton or Harvard?
    Dave
    Always wear safety glasses while programming.

  34. #34
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    You can get a lot of "common knowledge" here Microchip Technology User Forums as well as quite a few other places.

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


    Did you find this post helpful? Yes | No

    Default

    Just curious .. rmteo ... do you use PBP?
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default I am getting confuseder and confuseder

    The PICBASIC PRO compiler book that comes (for $250) with MIcroEngineering Labs product does not mention built in routines. I found a chapter in a MikroElektrnonika "Programming PIC MCUs in BASIC"on line book devoted to these. I assume they work with my system. True? I don't think so.....sigh

    http://www.mikroe.com/en/books/picbasicbook/05.htm


    The above book says,

    -------start snip---------------
    Prototype sub procedure EEprom_Write(dim Address as byte, dim Data as byte)
    Description

    Function writes byte to [Address]. [Address] is of byte type, which means it can address only 256 locations. For PIC18 MCU models with more EEPROM data locations, it is programmer's responsibility to set SFR EEADRH register appropriately.

    All interrupts will be disabled during execution of EEPROM_Write routine (GIE bit of INTCON register will be cleared). Routine will set this bit on exit

    Ensure minimum 20ms delay between successive use of routines EEPROM_Write and EEPROM_Read. Although EEPROM will write the correct value, EEPROM_Read might return undefined result.
    Example

    for i = 0 to 20
    EEPROM_Write(i, i + 6)
    next i
    -------------------end snip----------------

    I tried the following bit in my PBP compiler.

    i VAR BYTE
    for i = 0 to 20
    EEPROM_Write (i, i + 6)
    next i

    It complained that the EEPROM line has a syntax error.

    What am I just not grasping.....??? I assume the two BASIC packages differ. The question is where do I find the built in routines that come with MY PBP?

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    Ken,

    If you're working with PBP, you need to forget about anything you read for the Mikroe BASIC compiler. These are two totally different compilers.

    Everything you need to know about PBP is in the PBP manual. What you don't understand, just ask about here.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Ken,

    Have you been to this page?
    http://www.melabs.com/resources/samples.htm

    As for routines. I would say that just about every "command" listed in the PBP manual is a routine. ADCIN for example. The routine for reading the chip's ADC is built into that command.

    Keep asking questions
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Smile Success - the wheels go round

    This PWM exercise is designed just for what I have done.

    http://www.melabs.com/resources/samples/pbp/hardpwm.bas

    After loading the .hex into the RC car (carrying my PICkit2), hooking up another battery and connecting CCP1 to the electronic speed control, The wheels spin!!

    Ain't technology grande!

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    COOL!!!
    Another piece down!

    Did you get Walter's PWM reading code to work?
    If so then maybe now you can combine the two.

    If incoming PWM is X then wheels turn sort of thing?
    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, 13:55
  2. PBP Extensions, What are they?
    By PJALM in forum PBP Extensions
    Replies: 9
    Last Post: - 28th September 2021, 12: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, 20:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2005, 00:30
  5. Making PBP code more modular
    By forgie in forum General
    Replies: 30
    Last Post: - 25th October 2005, 17: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