change pwm range preserve input sensitivity

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 254. I want my PWM (PWM_2) output to the victor to be 100 to 254. 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*154/254) + 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 out.

Well lets start with the basics:
127 is nuetral

127-254 is one direction

0-127 is in another direction

so you want the to have a range control between either 0-127 or 127 - 254 (depending on the direction you want to spin)

second analog input form the OI (operator interface gets converted into) to one of the these values defined in ‘ifi_aliases.h’ not PWMs

  1. This controller can do floating point trig calculations so I dought this will be taxing in anyway. If fact this is the type of code is quite basic.

3)All the physical variables you can use are defined in ifi_aliases.h. p1_y and so on are the values form the OI ports(joysticks for example). pwms are the this being outputed at the pins. Look at the default_code in the user_routines.c. You can add tons more software variables like the ones you stated. Read:

*---------- Aliases for each OI analog input ---------------------------------------------------------

  • Below are aliases for the analog inputs located on the Operator Interface.
    #define p1_y rxdata.oi_analog01
    #define p2_y rxdata.oi_analog02
    #define p3_y rxdata.oi_analog03
    #define p4_y rxdata.oi_analog04
    #define p1_x rxdata.oi_analog05
    #define p2_x rxdata.oi_analog06
    #define p3_x rxdata.oi_analog07
    #define p4_x rxdata.oi_analog08
    #define p1_wheel rxdata.oi_analog09
    #define p2_wheel rxdata.oi_analog10
    #define p3_wheel rxdata.oi_analog11
    #define p4_wheel rxdata.oi_analog12
    #define p1_aux rxdata.oi_analog13
    #define p2_aux rxdata.oi_analog14
    #define p3_aux rxdata.oi_analog15
    #define p4_aux rxdata.oi_analog16

you need to select the one of these, they are based on the input pins on each port. p1,p2… are the ports on the OI

are available on the joysticks

Read this completely before you start soddering.

Hi, to clarify the output I want, the shooter direction I want is my forward from 127 to 254, I also want to preserve part of the reverse from the 126 down to 100. Hope this helps clarify. I have chosen to use #define p3_aux rxdata.oi_analog15 as the input via the pot on the console. The pot is a stand-alone device on the console not related to the two joysticks
Thanks Jeff

To be more specific, you should range the PWM from about 136 to 232. The Victor has a deadband from 117 to 137, and it reaches 100% output at 232. All detailed at the IFI FAQ:

EDIT: Strike that, didn’t see you still wanted reverse on there. You can range from 100 to 232. Note that you’ll get a max of about 20% power in the reverse direction.

You have exactly the right idea – multiply by the desired output range, divide by the available input range, and add an offset to get it to start where you want.

I will give you two warnings. First, the OI doesn’t really want to see a potentiometer giving it a voltage. It wants to see a variable resistance. You won’t necessarily get the full 0-254 range of values in either case, so you might need to tweak your formula slightly to compensate.

Second, the compiler is notorious for overflowing intermediate results when you do things like multiplying values that each fit in eight bits. A bit of (int)-casting will force the code to do 16-bit arithmetic, and you should be fine.

  pwm02 = (int)p3_aux * 154 / 254 + 100;

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.


This helped greatly, thanks to all involved, we are off to the test arena.
Thanks, Jeff