PBP projects for R/C models


Closed Thread
Results 1 to 40 of 772

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Could I just substitute?

    From what I can tell the PIC18F45K20 is compatible with the PICKIT2 and MPLAB systems. I see that it comes in a 40 pin PDIP configuration.

    Do you think I could unplug my 40 pin PIC16F887 and plug in a new PIC18F45K20 40 pin PDIP, do a bit of rewiring and be ready to go hardwarewize?

    KEn

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


    Did you find this post helpful? Yes | No

    Default

    What does it give you that you don't have with the '887?
    -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

    Default I just got the impression that.....

    Scalerobotics wrote a while back:

    A 12F683 design (would require a fair amount of changes to work on your chip)
    http://www.picbasic.co.uk/forum/show...4998#post84998

    This one could not be modified for your chip, and would require a 18F2431, or 4431.
    http://www.picbasic.co.uk/forum/show...1961#post91961 (cleaner code than above)

    And the one rmteo pointed out, which would require an 18 series chip: http://www.picbasic.co.uk/forum/cont...e-Servo-Driver (Darrels, so you can't really go wrong)
    I am not enough conversant with the various Microchip models to talk intelligently about what I need or don't need.

    Ken

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


    Did you find this post helpful? Yes | No

    Default Before going to bed

    After comparing the power and the 6 pin PC connector selections of the 44 pin 16F887 in the PICKIT2 and the 44 pin 18F45K20 in its StarterKit I think I can unplug one and plug in the other. I'll bet that will be the same for the 40 pin PDIP versions also. Good for our team.

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    That's a great question Bert. Well, you being an asm guy will probably get a few laughs at my first real attempt at using more than 20 lines of asm in my program. But I will show you anyway. This uses Timer1 for PWM measurement (read servo channels in). Basically, Timer1 runs non-stop, and when a state change interrupt is detected, the timer value is read. The start timer value is subtracted from the stop timer value to get the pulse width. This is done for all channels. After all channels are read, it is time to output pulses to the servos. So I do not have a 20 ms timer, it cheats and uses the R/C receiver as the 20ms timer. If all channels have been read, it must be 20 ms. The second interrupt is timer0. That is used for pulse duration on the output. I made the pulse base 1ms, then the timer gets set for a second interrupt to complete the pulse.

    Here is an example of reading 5 R/C channels, and outputting 4 R/C channels using two timers: http://www.scalerobotics.com/PWMpassthrough.html

    Something like that could be used. And in addition to detecting servo pulse in, and interrupt on change could time a pulse from two sonars at the same time. This could also read timer1 start and end times, so no additional timers would be needed. If you did not want to use the R/C receiver as the 20 ms timer, then timer2 could be used. But that is the last timer on this chip. But then, you can still throw more on those two other timers, if you wish.
    Last edited by ScaleRobotics; - 21st November 2010 at 15:11.
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default

    Walter I never find things to laugh about in code that works! Besides, 20 lines of asm isn't really much. Thats one of the reasons I wanted to convert to a high level language. Fewer lines to type

    Ken is worried about firing both sonars at the same time cuz he may not know who the source is when it comes back.
    -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
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by cncmachineguy View Post
    Ken is worried about firing both sonars at the same time cuz he may not know who the source is when it comes back.
    Ken was thinking smarter than I. Good point. Maybe keep your sonar for front view, and for side view something like this: http://www.acroname.com/robotics/parts/gp2y0a21yk_e.pdf . Or use infra sensors for both, since you can get updates every 20 ms to keep up with the fastest that you can change your servos. Besides, they are cheaper than sonar! You do need to pick your distance range though. The one I gave a link to was 4 inches to 30 inches, which seemed ok for following a wall. If its 30 inches or more, get closer....
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default Blocking commands

    Yes, "blocking commands" is exactly the word. I figured that out while lying in bed with the LOGIC TOOL image in my head. I could see that the length of the pulse was being added to the interrupt time. I could not find any information on that in any of my documents. Please tell me where in which .INC file is the ASM code which is activated by PULSOUT. Without access to those details, PBP is just guess work.

    My plan is to insert counters into the interrupt service routine. Every four interrupts (20millisec) do a PULSOUT. Every 25 interrupts, TRIGGER one SONAR or the other alternatively. My TRIGGER is built of HIGH and LOW commands totaling 10 microseconds (or so). These are not blocking.

    I'll give this a try and see how the car reacts (if at all.....)

    Thanks again for the support.

    Ken

  9. #9
    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
    Please tell me where in which .INC file is the ASM code which is activated by PULSOUT. Without access to those details, PBP is just guess work.
    I would approach it a different way, and avoid that pain. Especially since interrupts may grow on you, and you may get rid of your pulsin/out someday ! Say you want an interrupt every 20 ms and have a single servo to control, but you want to use pulsout since you are still learning interrupts. Since we can be a little off on our 20 ms, as Bert mentioned, the easy way is to say the average servo pulse is 1.5ms, so I need to interrupt every 18.5 seconds. If you add in the time of your pulsout, it will be very close to 20 ms, and your servo will be happy and grateful.
    http://www.scalerobotics.com

  10. #10
    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
    My plan is to insert counters into the interrupt service routine. Every four interrupts (20millisec) do a PULSOUT. Every 25 interrupts, TRIGGER one SONAR or the other alternatively. My TRIGGER is built of HIGH and LOW commands totaling 10 microseconds (or so). These are not blocking.
    If that plan is just for testing, it sounds like a great plan. But if you plan to use it while doing 20 mph, you will be doing a "ping" every 3.66 feet, or 8 times per second. If your reflexes are quick, you might be able to blink your eyes quickly at about 8 times per second. While your R/C car is doing 20 mph around a turn, try blinking your eyes as fast as you can, while steering your R/C car. I think your results might be similar to the ones we saw in the video.
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default

    ken, I think you should stick with the '887. You already have lots of experience with it and really it can suit your needs just fine.

    If you want to jump up to the 18F, you may find yourself feeling like WOW, how do I do this. From what I have found, the 18F's just left me feeling like I had just stepped into a new world with regards to setting up and configuring it just to get it to run. You are doing basic stuff, ie no USB or 4 way PWM with encoder feedback. So the 887 can do that just fine.

    BTW, I don't remember how fast you are running the PIC. Whats your osc speed?
    -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!

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


    Did you find this post helpful? Yes | No

    Default I have not played with oscillator speed.

    My oscillator is 4Mhz (I think). I have done nothing to change it. Whatever it does naturally is what it is.

    My guess is that SONAR triggering four times per second is sufficient.

    Question: How do I create an interrupt every 1/4 second?

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    This is very helpful.
    http://www.picbasic.co.uk/forum/cont....-PICMultiCalc

    Probably the easiest way to get started is with ON INTERRUPT. It is not the most accurate, it will only interrupt when nothing else is going on. Sound silly but..
    An example would be a long PAUSE, the ON INTERRUPT will flag and run when the PAUSE is finished. ASM interrupts or DT's instant interrupts will work as true interrupts, but for your case ON INTERRUPT should be close enough.

    This should be close. Run it on your board and see what happens.
    Code:
    'FL PIC16F887
    '16F887 INT RUPT
    '44 PIN DEMO BOARD
       @ __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
       INTCON.5 = 1
       OSCCON = %01110000 '8 Mhz
       DEFINE OSC 8
       OPTION_REG = %01000111  ' 1:256 PRESCALE
       ON INTERRUPT GOTO TLOOP
       CNT  VAR BYTE
       D    VAR BYTE
       D = 0
       DATA @10,10,20,30
       TCNT  VAR    BYTE
       
       START:
       FOR CNT = 0 TO 150
       PWM PORTD.7,D,10
       D = D + 2
       NEXT CNT
       GOTO START
       
       DISABLE
       TLOOP:
       TCNT = TCNT + 1
       INTCON.2=0
       IF TCNT = 8 THEN
       TOGGLE PORTD.4
       TCNT = 0
       ENDIF
       RESUME
       ENABLE
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    I agree walter, if going to the trouble, why not be correct.

    Ken, heres something I was thinking,
    Set up a 5msec interupt timer.
    on each int, increment a counter
    first count (@5msec) ping sonar 1
    second count (@10msec) update servos
    third count (@15msec) ping sonar 2
    fourth count (@20msec) reset counter, write things (from looking at your code), adjust pulse times for next servo update.

    so your int handler will do:
    reload timer, inc counter, clear jump flags, retrun

    main will do something like this:
    if counter =1 and sonar1flag=0 then ping sonar 1
    if counter =2 and update flag=0 then updateservos
    if counter = 3 and sonar2flag=0 then ping sonar 2
    if counter =4 and mathflag=0 then math stuff

    in each subroutine first thing to do is set the flag, then do the routine.
    -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!

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


    Did you find this post helpful? Yes | No

    Default

    Great job Ken. What you are doing is the best way to learn about the interrupts. You have to play with them. That is a great start.

    I believe both pulsin and pulsout are blocking commands. While they run, nothing else can happen on your chip. Once they are finished, sure, things resume and the program takes over. For a single servo, this is fine. But once you start throwing in sonar, multiple servos, other things you have thought of, and some you haven't thought of yet ... then you start to run out of time to do all these things using blocking commands. Especially if you want to go 20 mph.

    As it stands, 20mph is half a foot for each 20ms (that is every chance you get to make an R/C correction). For your sonar, it takes a bit over 20ms, so if that is the only input, the best your chip can do is determine a correction every other 20 ms, or every foot.

    In fact, just listening to the echo pulse on your sonar takes up to 25 ms, so that alone screws up everything if we use blocking commands like pulsin. (and double the screwed if you are listening to two of these!)

    So, in the long run I think it is best to use interrupts for listening to your sonars, as well as outputting to your servo's. I can't remember how you are switching your transmitter for R/C control vs pic control, but that too might as well go on interrupts.

    If you do, you have all kinds of time. You can be listening for two sonars at the same time, chewing on some math to determine the amount of turn, etc. If you want speed, it is most definitely the way to go.

    That said, exactly what you are currently doing to learn is what I would recommend. Use the commands you know with interrupts to make things happen, and see how they work, and how to adjust them. Later on, when you feel comfortable with them, try adding in another interrupt timer to control a servo pulse.
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default

    Hi Walter, I love what you are saying about using int instead of pulsein/out. I am having trouble visualizing how to do that.

    In my head, something has to be the overall clock, thats where my suggestion of 5msec came from. when I think about what you are saying, all I seem to be able to see is all these events started waiting for an int to make them stop. so I see like 6 different timers going all at once.

    Or maybe you have 1 timer going for the 20ms, then do everything else sequencially using a different timer.

    EDIT: The slow sonars are gonna definitly limit the top speed! Maybe as an upgrade once it works slowly, infra red emitters and detectors. This way they could also be used at the same time by sending different signals on each.
    Last edited by cncmachineguy; - 21st November 2010 at 14:07.
    -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!

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