View Single Post
  #6   Spotlight this post!  
Unread 07-02-2006, 22:33
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: change pwm range preserve input sensitivity

Quote:
Originally Posted by Superstitions
I am using analog input (pot) from the user console to control a motor speed through a victor speed control. The analog gets converted to PWM_1= 0 to 255. I want my PWM (PWM_2) output to the victor to be 100 to 255. We are controlling ball distance by changing speed of ball shot with victor to a motor. I want input to this to be from the pot and want to presrve the ability to be able to go in reverse a little if the shooter gets jammed. I have come up with a formula for the conversion:
(PWM_1*155/255) + 100 =PWM_2.
My questions are
1) will this be excessively taxing on the RC program
2) is this the best way to make full use of the 0 to 5 volt analog input
3) do I need to use the terms PMW_1 and PMW_2 or can I use a term (PMW_1 temp)
Thanks in advance, please take it easy on me I am just starting outhttp://www.chiefdelphi.com/forums/newthread.php?do=newthread&f=51#
Confused
How about something like:

unsigned char PWM_1; // 0-255 input from joystick
unsigned char PWM_2; // 100-255 output to victor
unsigned int temp; // temporary storage

temp = 39 * (unsigned int)PWM_1;
temp >>= 6; // right shift six bits, which is the same as dividing by 64
PWM_2 = (unsigned char)temp + 100;

Notice that 39/64 is an approximation of 155/255.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org

Last edited by Kevin Watson : 07-02-2006 at 22:36. Reason: icky math