PBP projects for R/C models


Closed Thread
Results 1 to 40 of 772

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Hi Ken,

    I may have a solution to your problem, or part of a solution...

    I picked up a PING module the other day and did some playing and watched the last video you posted very close.

    My conclusion is you need to run the PIC at 20MHz.
    I am running a very basic code to calculate distance so my findings may not be a total solution.

    Watching the video it appears the car is pointing more at the corner the first time through, and the second time when it does not hit the wall it is just a bit to the right and a little more straight on. When I try corner targets the reading becomes very erratic. Maybe for you have the front sensor pivot slightly from left to right. Could be done with a spring and a cam bumping on the wheels?

    Back to the software. I am using a PIC running a 20MHz.
    When I set the PULSOUT at 10 giving the 20us you have in your code the readings become inaccurate with a great deal of fluctuation and slow to respond.

    When I set the PULSOUT at 2 giving a 4us pulse the accuracy is within an inch and very very quick to respond.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Question Dave, thanks!

    First, my oscillator. I have been using the 16F887's internal oscillator. I think if I do nothing my prescaler is set at 4:1. The PIC has an 8mhz internal oscillator. Figure 4-1 on Page 61 of DS41291F (the x887 gospel) indicates that by setting OSCCON = %01110111 I can get the internal 8mhz oscillator and the prescaler of 1:1. Does this seem correct to you all? I will try this evening.

    What do I need circuit-wise to implement the 20Meg external crystal oscillator?

    Second, the placement of my forward looking SRF05. I thought I found that slanting them to the left just a bit makes less possible reflection from the side wall coming into the front pingers. That seemed to work on the bench, but again confusion in the real world. I have not thought through what the side pingers should be hearing while the car is turning left. For racing I have moved the desired track out to 24 inches away from the side wall.

    Using a carpenters measuring stick I have calibrated my pingers. They seem consistent (again on my bench).

    Ken

  3. #3
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    First, my oscillator. I have been using the 16F887's internal oscillator. I think if I do nothing my prescaler is set at 4:1. The PIC has an 8mhz internal oscillator. Figure 4-1 on Page 61 of DS41291F (the x887 gospel) indicates that by setting OSCCON = %01110111 I can get the internal 8mhz oscillator and the prescaler of 1:1. Does this seem correct to you all? I will try this evening.

    Ken
    The oscillator (whether internal or external) frequency is always divided by 4 in these PIC's to get the instruction clock - it does not have anything to do with pre-scalers. Also, OSCCON.3:1 is read only.

  4. #4
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Yep, you got it. But no point in setting bits 1&2... they're read only.
    This is what I use to set the 16F887 to 8MHz.:
    OSCCON = %01110001 'Set Osc to 8MHz.

    And don't forget to add to your define list: DEFINE OSC 8


    For external xtal you will need a 20MHz crystal connected to OSC1 & OSC2 (RA7, RA6) and a small capacitor from each pin to ground. The recommended capacitor size will be in the xtal data sheet, but is typically a couple dozen pF or less.

    steve
    Last edited by Byte_Butcher; - 4th April 2010 at 02:45. Reason: don't forget to add DEFINE OSC 8

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


    Did you find this post helpful? Yes | No

    Default

    When bumping up to 8MHz try
    Code:
    pulsout trigfront,1
    That should give you 5uS trigger. I was doing 4.

    For external OSC I like ceramic resonators, good and bad to everything but with these you do not have to mess with capacitors, that is why I like them.
    http://www.allelectronics.com/make-a...ATORS/-/1.html
    The two outside pins will go to RA6 and RA7, the center to the zero rail (ground).
    The problem with the 44 pin demo board is Micro Chip did not "ground" the via between RA6 and RA7, so you will have to run a jumper if you go this route.
    Attached Images Attached Images  
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default It surely did change the behavior.

    Bed time here on the east coast.

    I tried both
    OSCCON = %01110111
    and
    OSCCON = %01110001

    I got the PIC to read the PWM signal from the radio channel 3 by doubling the threshold for differentiation. I can toggle between PIC and radio control.

    But I have not been able to get the HPWM to behave. I tried using the original duty cycle. This made the wheels go backwards very fast no matter what was in the HPWM command. I tried doubling the duty cycle (to account for cutting in half the clock rate and the wheels did not turn at all. The Electronic Speed Control wants this PWM signal to arrive at 50 hz. In fact it is probably at 489Hz (according to page 87 of MicroEngineering Labs' PICBASIC PRO book). I'll put a 'scope on it tomorrow.

    I think the book says that HPWM channel, 127, 50 will be a square wave of 489Hz. Does that agree with you guys' thinking?

    I also have not gotten the PING echos to mean anything. The little red lights on the SRF05s are blinking. But my code is not making sense of the echo responses. I thought that all I would need to do was to double the expected echo pulse duration numbers.
    Ken

  7. #7
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    Bed time here on the east coast.

    I tried both
    OSCCON = %01110111
    and
    OSCCON = %01110001

    I got the PIC to read the PWM signal from the radio channel 3 by doubling the threshold for differentiation. I can toggle between PIC and radio control.

    But I have not been able to get the HPWM to behave. I tried using the original duty cycle. This made the wheels go backwards very fast no matter what was in the HPWM command.
    did you add :

    DEFINE OSC 8

    to your code somewhere near the top?
    Otherwise the PIC thinks you're still running at the default 4MHz.


    steve

  8. #8
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    The Electronic Speed Control wants this PWM signal to arrive at 50 hz.

    Ken
    No matter how you cut it, to get 50Hz (20mS period) using hardware PWM, the maximum clock frequency you can use is 0.819MHz (819KHz)
    Attached Images Attached Images  
    Last edited by rmteo; - 4th April 2010 at 04:55. Reason: - typo in numbers.

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


    Did you find this post helpful? Yes | No

    Default

    Darn,
    I thought the SRF05 was the same thing as the PING. Now I see that the SRF05 takes a different trigger pulse.

    So it looks like I just wasted your time on that part.

    I guess on the good side rmteo noticed another possible problem.

    I wonder if a While/Wend loop using PWM would be the answer?
    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, 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