PBP projects for R/C models


Closed Thread
Results 1 to 40 of 772

Hybrid View

  1. #1
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    This is what the program header says:
    Code:
    ' PicBasic Pro Program to demonstrate hardware PWM.
    ' Output is a 1Khz signal with duty cycle sweeping
    ' from 20% to 80% once per second
    Since the frequency is 1KHz, its period is 1mS. The duty cycle is sweeping from 20% to 80% therefore the pulse width is varying from 0.2mS to 0.8mS. There are 2 problems here. For R/C signals, the period should be 20mS or 50Hz. Second, the pulse width should be 1.5mS for neutral, 1.0mS for extreme left (or full reverse) and 2.0mS for extreme right (or full forward). So your car is responding to a very short pulse (even less than full reverse). You have to modify the values in the program to get it to do what you expect.

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


    Did you find this post helpful? Yes | No

    Default Thank you for your analysis

    Thanks gang.

    I came to much the same conclusion myself. I have been trying to figure out what exactly this PWM code does so that I can modify it meet the RC specs. The comments in the program are fairly clear. My first attempts have not worked but I am optimistic.

    Interesting how rusty my brain has become.

    Ken

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


    Did you find this post helpful? Yes | No

    Default All Right, I get it!

    Here is the code that makes the wheels spin.

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

    There are no PBP commands that overtly make pulses. They are created by appropriately loading CCP1CON and CCPR1L. I found CCP1CON easily enough. It is listed in the INDEX of the 16F887 Data Sheet. CCPRxL and CCPRxH are not in INDEX. They are quietly mentioned on page 127. But why is there no HPWM command per page 86 in the PBP manual?


    Although I see how this might be a low cpu overhead way to create PWM, I don't want to learn about this now. I want to use PBP and ASM commands to control my motor and servo. Maybe tomorrow all this will make sense.

    Ken

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


    Did you find this post helpful? Yes | No

    Default I need help

    The code in

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

    makes the wheels of my car go backwards in bursts. The bursts last, maybe 3/4 second then the wheels stop for a 1/4 second. I look at the code . I think that it is supposed to sweep through all pulse sizes in a second. I surmise the short ones are too short so the wheels don't move. As they get longer the come up near the low end of the electronic speed control spec. They start to move. Then the second is over.

    I would like to pump PWM pulses out CCP1 that have a frequency of one every 20 msec (50 per second) and a pulse width that I can (by changing the code) vary from 1 msec to 2 msec. Am I correct in guessing that the frequency of the pulses is dictated by the PAUSE command. One pulse per loop through mainloop:

    So far all my attempts have created no forward wheel motion at all! If one of you has the time please modify hardpwm.bas so that I understand it. Or, better yet, show me how to use PULSOUT. That does not work for me either.

    Ken

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


    Did you find this post helpful? Yes | No

    Default Progress

    I've got code that searches for "duty" that runs the motor. I have found the region that drives it backwards and that keeps it motionless. So far i have not found the forward moving pulse size, but it will not be long now.

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    A DC motor needs to have the polarity reversed to change the rotation???
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Yes, that is certainly true, but

    Yes, DC motors need the polarity changed to change direction. I was led to believe that there is something magical in this electronic speed control that made it work differently. Thank you for reminding me to question assumptions.

    Ken

  8. #8
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    I gave you that info in post #44.

    Quote Originally Posted by rmteo View Post
    Since the frequency is 1KHz, its period is 1mS. The duty cycle is sweeping from 20% to 80% therefore the pulse width is varying from 0.2mS to 0.8mS. There are 2 problems here. For R/C signals, the period should be 20mS or 50Hz. Second, the pulse width should be 1.5mS for neutral, 1.0mS for extreme left (or full reverse) and 2.0mS for extreme right (or full forward). So your car is responding to a very short pulse (even less than full reverse). You have to modify the values in the program to get it to do what you expect.

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


    Did you find this post helpful? Yes | No

    Default Yes, we are all in agreement except..

    Thank you all for your help. I posted those quotes because they back up what you have been saying and what I thought I coded.

    Trouble is my PIC code only makes my car wheels go backwards and stop. I have not been able to create a PWM stream that drives the wheels forward. I know the ESC works because the wheels go fine under radio control.

    Oscilloscope, here I come.

    Ken

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


    Did you find this post helpful? Yes | No

    Default Oscilloscope = Good!

    Quote Originally Posted by Kenjones1935 View Post
    Oscilloscope, here I come.
    Great idea Ken. I don't know how much you have modified hardpwm.bas, but here it is in it's native form. First pic is about 20 percent, and second pic is about 80 percent (of a 1ms pulse):





    You will notice that the min is about 0.2ms and max is 0.8ms.

    Your servo or speed controller requires a pulse width between 1.0ms and 2.0ms. It would probably like to see these pulses every 20ms or so, not every 1 ms (as seen here).

    And here is what you want it to look like (from my rc receiver):
    Attached Images Attached Images    
    Last edited by ScaleRobotics; - 26th January 2010 at 18:18.

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


    Did you find this post helpful? Yes | No

    Default Thank you!!

    The pictures you attached match my mental picture of what I have created. First I modified the .bas to make consistant 1.35ms pulses. The PAUSE command creates the spacing in time. This drove the car quite fast backwards with no hesitations. Next 1.5ms. The wheels stopped. From that point I increased (not automatically) the pulse width up past 2ms to no avail. I never got the car wheels to turn forward.

    Where can I find the assembly language code for the Basic commands?

    I gather from reading the manual that PAUSE is not a pure interrupt driven behavior. I can not use that command if it shuts down the PIC between pulses.

    I have two plans.

    1. Study Assembly Language programming. I do not see enough explanation in the PBP manual to feel confident in what Basic Pro is actually doing. I should be able to get the PIC to better communicate to me what it is doing via the LED's.

    2. Attach CCP1 to the servo that steers the car instead of the drive wheels. I know what a servo is and I know this one works.

    3. Make the effort to find an oscilloscope. My only access at this time is the CS department at Fitchburg State College. I would rather not use them. I do not really know them that well.

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    First I modified the .bas to make consistant 1.35ms pulses. The PAUSE command creates the spacing in time.
    The "Pause 17" lets you adjust how fast it moves from 20% and 80%. However, it does not adjust the pulse width, which is what you need to be adjusting. I can't explain why it works at all though, but it might be so confused from receiving pulses every 1ms, instead of every 20ms.

    Where can I find the assembly language code for the Basic commands?
    I suppose MeLabs could have just given us all the assembly code, but that probably does not make good business sense for the company. You can TRY to read some of the assembled code after you compile, but it looks a little jiberish. It is nameofyourfile.lst . Some people have suggested getting a dis-assembler, and disassemble the hex file ... but then I think you loose syntax then.

    I gather from reading the manual that PAUSE is not a pure interrupt driven behavior. I can not use that command if it shuts down the PIC between pulses.
    In my mind, an interrupt is better, as it will not stall your processing. Pauses can work well with servo's. I have not tried them much with motor controllers. The fact that the pulse code you were using sort of worked is encouraging for simplifying code, and staying away from interrupts.

    I have two plans.

    1. Study Assembly Language programming. I do not see enough explanation in the PBP manual to feel confident in what Basic Pro is actually doing. I should be able to get the PIC to better communicate to me what it is doing via the LED's.

    2. Attach CCP1 to the servo that steers the car instead of the drive wheels. I know what a servo is and I know this one works.

    3. Make the effort to find an oscilloscope. My only access at this time is the CS department at Fitchburg State College. I would rather not use them. I do not really know them that well.
    I count three plans ..... here is my personal take on them which might be worth less than two cents...

    Your plan 1 is for someone that really wants to learn all about each register and each bit, and what they control. This will require reading a lot of the 375 page datasheet. Picbasic takes care of a lot of these details for you, making it easier for most people to create useful projects in a much smaller amount of time. Yes, it masks many of these processes from you, but to me, this is a very good thing!

    Plan 2, good idea. I still do not think you are really creating 1.5ms pulses. Why don't you PM me your code, or post it here, and I will PM you back, or post here what I see on my scope using your code.

    Plan 3 See above.

    Why don't you try this code, just don't use the analog. Change pos value to change servo, or motor controller. It will give you an idea if it only does servo's or if your motor controller will like it.

    EDIT:

    Ok this code http://www.melabs.com/resources/samp...bp/servox2.bas
    Last edited by ScaleRobotics; - 27th January 2010 at 04:27.

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


    Did you find this post helpful? Yes | No

    Default I think I should take a different tack

    I am realizing that using PAUSE can not work if my PIC is meant to do some thinking between pulses. I just discovered

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

    He is using interrupts. That is what I was hoping to do in the first place. I'll see if I can figure out what he is saying.

    Meanwhile, would you be willing to take pictures of the pulses that my code is making if I posted the code?

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    Sure! Post what you have, and I will send you some oscilloscope shots.

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