PBP projects for R/C models


Closed Thread
Results 1 to 40 of 772

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    see, this is one of the reasons I love this stuff. To do what Walter describes, with the same resources (1 interupt and pulsout), I would set my timer for 20 ms. My int handler would set a flag, and I would get out. Then in my Main, if the flag is set, hit my pulseout routine and clear the flag. This way I would get a new pulse every 20 ms on the dot. But mostly cuz I just always want to get out of the handler. I seem to feel like by name "Interupt" I was busy doing something before I went there. Maybe it was important and I need to get back to it.

    As for PBP being guess work, I don't think thats the case. Pulseout/in serout/in and the rest of them, take exactly as long as you think. if you PULSEOUT for 1 ms, thats how long it will take.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Walter, I like your idea of the 18.5 ms plus servo out to make up the 20ms loop. I need just that for my project. I will want to use 1 timer to control the loop and the pulse, so that seems the best idea to me.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Red face I've come to a screeching halt

    "Verification of Program Memory failed at address 0x00000000"

    I tried some old code that I KNOW loaded. Not today.

    I swapped out the PIC. That was not the problem. I reseated all the patch wires. That made no difference.

    I restarted the PICKIT2 programmer. That did not help.

    I tried with a PICKIT2 board - the one on which I ran the blinkys - no problem. It liked to load and blink.

    Where do I start?

    Ken

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


    Did you find this post helpful? Yes | No

    Smile Fixed it!!

    It was a wire I had added to give the LOGIC TOOL more information. I do not understand why the PICKIT objected. But all is well.

    The interrupt driven system sort of works. We'll see more tomorrow.

    Thanks again for your help and support.

    Ken

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


    Did you find this post helpful? Yes | No

    Default Works as good as before

    I've got the system working interrupt driven. I do not have proportional controls implemented - yet.

    On the bench the car seems as responsive as before. We'll see when I take it to the gym.

    One thing I have not figured. How, now, to I disable interrupts when the radio transmitter has been
    turned ON? At the very end of this code pack is my old WHILE loop that worked - in the day.

    Code:
    symbol trigright = PORTB.0 ' Define output pin for Trigger pulse
    symbol trigfront = PORTB.1 ' Define output pin for Trigger pulse
    symbol trigleft  = PORTB.3 ' Define output pin for TRigger pulse
    symbol echoright = PORTC.6 ' Define input pin for Echo pulse
    symbol echofront = PORTC.5 ' Define input pin for Echo pulse
    symbol echoleft  = PORTC.7 ' Define input pin for Echo pulse
    SYMBOL channel3  = PORTC.4 ' Define input pin for Channel 3 PWM
    ' PORTC.0 'High is R/C.  Low is PIC control
    TRISC = %11110000
    DATA $C0,$0C 'his version's checksum goes here.
    define ADC_BITS 8
    TRISA.0 = 1 'PORTA.0 as analog input for POT
    ANSEL.0 = 1
    ADCON1 = %00000000  'left justified 
    ' We use low eight bits.  0 -> 255.
    ADCON0 = %01000001  'divide 4Mhz clock by 8.
    
    '------------
    OSCCON = %01100000 '4 Mhz
    DEFINE OSC 4
    
    LED1    VAR PORTD.4
    wsave VAR BYTE $70 SYSTEM
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
          
    '------------
    
    '5.0 mSec OR 200 Hz INTERRUPTS
    T1CON = %00000001         'Prescaler = 1:1, TMR1ON
    'PRELOAD 60543
    PreLoad     VAR WORD
    PreLoad =  60543
    TMR1L = PreLoad.LowByte
    TMR1H = PreLoad.HighByte
    '@ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    '------------
    WHEELS VAR WORD
    STEERING VAR WORD
    
    'The following may be a big part of the wall hugging probllem
    Potread var word
    Forward var word ' was fixed 122. Now sweeps 7 steps. See Checkpot
    HalfForward VAR WORD ' Potread/2 +x + 1. See Checkpot
    Back VAR WORD 'See Checkpot
    HalfBack VAR WORD 'See Checkpot
    Brake con 100 'Only used just before Main.
    
    Straight con 150 '?
    Right CON 130     '?
    HalfRight con 135 '?
    QuarterRight CON 140 '?
    Left con 170     '?
    HalfLeft con 165 '?
    QuarterLeft con 160 '?
    
    '---------------------------
    frontdanger var word
    stopreversing var word
    frontfree var word
    desiredtrack var word
    outertrack var word 
    
    '---------------------------
    
    'some of the following are not used.
    CNT  VAR BYTE 'counts interrupts for TRIGGERS
    cnt = 0
    CNT2  var byte ' counts interrups for wheels and steering
    CNT2 = 0
    b0 VAR word
    rangeright var word
    rangeright = 100  'about 6 inches preset
    rangefront var word
    oldrangeright var word
    oldrangefront var word
    reversing VAR WORD
    reversing = 0
    switchtoPIC VAR WORD
    switchtoPIC = 1
    radiocontrol var word
    radiocontrol = 0
    steeringleft var word
    steeringleft = 0
    steeringright var word
    steeringright = 0
    
    '-------------------
    Checkpot:
    ' I think Potread goes from 0 to 6.
    adcin PORTA.0, Potread
    Potread = Potread/37
    Forward = 160+Potread
    HalfForward = 155+(Potread/2)  'seems to work.
    Back = 140-Potread
    HalfBack = 145-(Potread/2)
    '----------
    frontdanger = 210 + Potread*55 '210-540, 14-36 inches 
    stopreversing = 180 + Potread*25 '180-330, 12-22 inches
    frontfree = 700 + Potread*60 '700-1060, 48-70 inches
    desiredtrack = 180 + Potread*20 '180-300, 12-20 inches 
    outertrack = 360 + Potread*15 '360-450, 24-30 inches
    
    '----------
    write 2, word Potread
    write 4, word frontdanger
    write 6, word stopreversing
    write 8, word frontfree
    write 10, WORD desiredtrack
    write 12, word outertrack
    
    '-------------------
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    '-------------------
    low PORTC.0
    'hpwm 1,Straight,50
    STEERING = Straight
    'hpwm 2,Brake,50
    WHEELS = Brake
    'pause 4000 'Wait so I can put the car down and get out of the way.
    '-------------------
    
    main:
    
    CheckIfInDanger:
    if rangefront < frontdanger then
    STEERING = Straight
    WHEELS = back
    reversing = 1
    goto reverseoutoftrouble
    ' loop till this is secured
    endif 
    '-------------------
    tryleftturn:
    if rangefront < frontfree then
    'something ahead - turn hard left.
    STEERING = left
    WHEELS = halfforward
      steeringleft = 1
     goto main 'loop till this is secured
    endif
    
    '------------------- 
    goingforward:                          
    STEERING = straight
    WHEELS = forward
    
    '-------------------
    keepgoingforward: '----Compare to right wall
    if rangeright > outertrack then
      STEERING = quarterright
    endif
    
    if rangeright < desiredtrack and oldrangeright < rangeright then
      STEERING = STRAIGHT
    endif 
      
    if rangeright > desiredtrack and oldrangeright > rangeright then
      STEERING = STRAIGHT
    endif
    
    if rangeright > desiredtrack and oldrangeright < rangeright then
      STEERING = QUARTERRIGHT
    endif
    
    if rangeright < desiredtrack and oldrangeright >= rangeright then
      STEERING = QUARTERLEFT
    endif
    
    goto main
    
    '-------------------------
    reverseoutoftrouble:
    while rangefront < stopreversing
      STEERING = RIGHT
      WHEELS = RIGHT
    wend 
    
    if rangeright > outertrack or rangeright < desiredtrack then 
      STEERING = LEFT
      steeringleft = 1
      WHEELS = HALFFORWARD
    endif
    goto main
    
    '***********INTERRUPT HANDLER************
    ToggleLED1: 
    TMR1L = PreLoad.LowByte   ' Load the timer with preload value.
    TMR1H = PreLoad.HighByte
    TOGGLE LED1
    
    '------------
    ' Trigger SONAR alternatively every 25 interrupts
    if CNT=25 then
     pulsr:
     oldrangeright = rangeright
    ' produce 10uS trigger pulse (must be minimum of 10uS)
     low trigright
     HIGH trigright
     high trigright
     high trigright
     LOW trigright
    'zero could be legal below
     pulsin echoright,1,rangeright 'measures the range in 10uS steps
     endif
    
    '-------------
    if CNT=50 then
     pulsf: 
     oldrangefront = rangefront 
     low trigfront
     hIGH trigfront
     high trigfront
     high trigfront
     LOW trigfront
     pulsin echofront,1,rangefront ' measures the range in 10uS steps
     CNT=0
    endif
     CNT=CNT+1
    
    '--------------
    if cnt2=4  then
    ' PWM pulses are between 1 and 2 millisec.
        low PORTC.1
        low PORTC.2
        pulsout PORTC.1,WHEELS  
        PULSOUT PORTC.2,STEERING   
        CNT2=0
    endif
    CNT2=CNT2+1
        
    @ INT_RETURN
    checkchannel3:
    'works with four AA batteries pack. Radio receiver puts pulses
    'on this line whenever the transmitter is turned ON.
     switchtoPIC = 2
     while switchtoPIC >= 2
        count channel3,65,switchtoPIC
        high portc.0
     wend
       low portc.0   
          
    end

  6. #6
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Code:
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    that line turns the interupt on, or enables it. there must be a simular line like INT_DISABLE maybe to turn it off.
    turn it off when the while loop is true, or when under Tx control. then turn it back on when Tx control is over.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default That's what I tried.

    For some reason disabling interrupt during the WHILE loop did not work. I could have done
    something stupid.

    What I want to know is where is the list of "blocking" commands. I do not see such a list in
    my PBP book. For example, is COUNT a blocker?

    Here is what I coded immediately after main:
    main:

    '-------------------
    checkchannel3:
    'worked with four AA batteries pack. Radio receiver puts pulses
    'on this line whenever the transmitter is turned ON.
    switchtoPIC = 2
    while switchtoPIC >= 2
    @ INT_DISABLE TMR1_INT
    count channel3,65,switchtoPIC
    high portc.0
    wend
    low portc.0
    @ INT_ENABLE TMR1_INT
    Ken
    Last edited by Kenjones1935; - 22nd November 2010 at 23:27.

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