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?
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.
As I said, the wheels go round, but...
The wheels are not going round and round in the pattern I expected. In particular they only go backwards. The code claims to sweep from 20% to 80% cuty cycle.
SOOO, can I use my USB connection and PICkit 2 Logic and Analyze Tool to see what is actually happening?
Ken
I believe you are using the PWM example here: http://www.melabs.com/resources/samples/pbp/hardpwm.bas
This is a PWM that is not supposed to work with RC servo's. It's wave form is different. It is used to dim LED's etc. I am a little surprised that it can turn the wheels at all. I have a scope to help me view wave forms. I have tried for a few minutes to see what the pickit's logic tool can do, but I have not had any success. I am pretty sure it is just a problem with the operator (me).
Last edited by ScaleRobotics; - 22nd January 2010 at 23:00.
This is what the program header says:
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.Code:' PicBasic Pro Program to demonstrate hardware PWM. ' Output is a 1Khz signal with duty cycle sweeping ' from 20% to 80% once per second
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
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
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
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
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
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):
![]()
Last edited by ScaleRobotics; - 26th January 2010 at 18:18.
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
Bookmarks