Go to Post Thanks and don't stay up all night waiting for Lavery Claus! - Beth Sweet [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-02-2008, 14:34
b1zkit b1zkit is offline
Registered User
FRC #2345
 
Join Date: Feb 2008
Location: Kearney
Posts: 1
b1zkit is an unknown quantity at this point
PWM Speed

This is our first year and we are having some problems with the programming. We need to set a lower maximum value for the PWM02 motor. Something like 200. We are using the default code. How would this be achieved?

Last edited by b1zkit : 18-02-2008 at 14:38.
  #2   Spotlight this post!  
Unread 18-02-2008, 15:14
psy_wombats's Avatar
psy_wombats psy_wombats is offline
Registered User
AKA: A. King
FRC #0467 (Duct Tape Bandits)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Shrewsbury MA
Posts: 95
psy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura about
Re: PWM Speed

You would probably want to scale the precision of whatever control mechanism or joystick you are using to get the full scale of motion, so this should graph that to the new maximum:

Code:
long answer; //Must be long to hold precise values
if (p1_x > 127){ //Or whatever joystick
answer = p1_x * 200 / 255;
pwm02 = (unsigned char)answer; //Cast this to the proper type
} else {
pwm02 = p1_x;
}
  #3   Spotlight this post!  
Unread 18-02-2008, 17:09
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: PWM Speed

Quote:
Originally Posted by psy_wombats View Post
You would probably want to scale the precision of whatever control mechanism or joystick you are using to get the full scale of motion, so this should graph that to the new maximum:

Code:
long answer; //Must be long to hold precise values
if (p1_x > 127){ //Or whatever joystick
answer = p1_x * 200 / 255;
pwm02 = (unsigned char)answer; //Cast this to the proper type
} else {
pwm02 = p1_x;
}
While the above code would work, you don't need to use a long variable, which I'm assuming you're using to prevent overflow. Another approach would be to just cast the result:

Code:
#define MAX_VALUE 200 //Replace 200 with whatever you want your max value to be
Put the #define at the top of your file. On compile, the compiler will insert 200 (or whatever you decide you want your value to be) wherever you write MAX_VALUE. This way, if you want to change what the max value is later, you can simply change it at the top of the file instead of fishing through your code. This is especially useful if you use it more than once.

Then, the actual solution:

Code:
if(p1_x > 127) //Replace p1_x with whatever joystick and axis you want
     pwm02 = (unsigned char)((long)p1_x * MAX_VALUE / 255);

else
     pwm02 = p1_x;
This code first casts the expression as a long so that overflow doesn't occur, then casts it back to an unsigned char so it can be assigned to pwm02. No variables are used.
__________________
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Digital out signal speed on off, almost like PWM but at max 60Hz Generalx5 Electrical 2 27-03-2007 12:26
trouble with pwm speed controller jakk Control System 4 10-01-2005 02:51
trouble with pwm speed controller jakk Electrical 4 10-01-2005 02:51
Ugh...PWM pin vs. Speed Controller archiver 2001 1 24-06-2002 00:27
Speed Controller/PWM problems.... Clark Gilbert Technical Discussion 8 08-01-2002 00:14


All times are GMT -5. The time now is 01:51.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi