View Single Post
  #14   Spotlight this post!  
Unread 30-04-2008, 18:30
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,809
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Need help with PWM 1-2ms pulse control

Normally the signal pin measures power coming in from the +5v power pin not flowing out to ground. (Taking Ben Franklin's view of electricity)
As long as you understand that your description of how you wired the pot is incorrect for normal operation, but you're happy with it then there's no problem. You've just wired it as a voltage divider that's all. I just don't want anyone else reading this to get the wrong idea though.

If you want only the seven specific values in Set A or B then you'd use a lookup table or nested If statements. If you want variable speeds then just map 0-22 to the corresponding range of pwm values, e.g., 0-22 mapped to 0-127 for Set B.

For a lookup table, you create an array with one entry for each of the possible 23 values that your pot could be. Then you pull values from the array using the analog input as an index.
Code:
static unsigned int pwm_setB[23]={0,0,0,25,25,25,47,47,47,64,64,64,80,80,80,100,100,100,127,127,127};

pwm01=pwm_setB[Get_Analog_Value(rc_ana_in01)]; // If Set B
Nested IFs would look like:
Code:
unsigned int value;
value = Get_Analog_Value(rc_ana_in01);

if (value < 3)
   pwm01 = 0;
else if (value < 6)
   pwm01 = 25;
//etc.
P.S. Be aware that the pot value may jump around a little even if you aren't touching it, so if you're right on the edge, say 3, then you might see the servo twitching between two of your set B speeds.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 30-04-2008 at 20:43. Reason: Ben Franklin