|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
speed change
Hi,
What change should I make to my PBASIC default code to manifulate how fast a motor goes from 127 to 0, or from 127 to 254. Thanx |
|
#2
|
||||||
|
||||||
|
Faster != Possible
If you want to make the motor go faster, you are out of luck.
If you want to make it go slower, you just have to reduce the distance away from 127 to make the voltage to the motor less. Code below (untested off the top of my head so it may have bugs, but I think it is good to go). Also, I have resigned myself to the fact that pbasic has a certain order of operations and that that order is not the order you and I normally use. Some folks use parenthesis to try to fix this problem. The intent is to make matters clear to the reader, but in fact, in the case of pbasic, they make matters UNCLEAR, so I use them as little as I can. I am much happier this way. You should try it. It is okay... ...really. Pbasic Zen Master, Joe J. MotorPWM Var Byte ScaleNum CON 4 ScaleDen CON 4 'Total scalefactor = ScaleNum / 2^ScaleDen 'Example above Scalefactor = 0.25 or 25% 'Set MotorPWM as usual if MotorPWM < 127 ScaleReverse ForwardScale: MotorPWM = MotorPWM - 127 * ScaleNum >> ScaleDen + 127 MAX 254 goto ScaleDone ScaleReverse: MotorPWM = 127 - (127 - MotorPWM * ScaleNum >> ScaleDen MAX 127) ScaleDone: 'continue coding... 'if you want to have an adustable "gas" you can replace ScaleNum with a variable (p1_wheel for example) Joe J |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| "Automatic Transmission" | Madison | Technical Discussion | 70 | 24-11-2003 09:03 |
| Beantown Blitz game change? | Erin Rapacki | Off-Season Events | 31 | 18-06-2003 12:39 |
| Power, speed, and torque... AGH | Gui Cavalcanti | Technical Discussion | 5 | 10-11-2002 19:02 |
| How many posters does it take to change a lightbulb? | Brandon Martus | Chit-Chat | 7 | 22-02-2002 19:48 |
| Calibrating speed controllers and joysticks | thedillybar | Technical Discussion | 4 | 11-02-2002 13:24 |