Hello, I was wondering if anyone has experiencing using a potentiometer to decrease/increase the speed of a motor. I am using the cortex microcontroller with a 2-wire 393 motor. In order to do this, what code do you need to write for the potentiometer?
Potentiometer goes from 0-4095 but has a lesser set of values that is generally in practical range.
Set up a math function to have 0 be -127 motor value and your max value (let’s say 4000) go to +127 for the motor. I need some time to think but a conversion function will look something like…
int pot_val = SensorValue[my_pot];
float scale_factor = 0.064;
int motor_val = (pot_val*scale_factor) - 127;
The range you want to cover is 4000 pot values over 255 motor values. So 255/4000 gives 0.064 You can choose a shorter range if you want and code in a deadband if you want as well with some if statements. All up to you. Verify the values in Excel with this formula or in the debug window.
Late reply, but this code seems to work perfectly for what I need. Thank you so much!