Hi, if you're willing to help me out, let me be more specific with my plan/idea :D. Let say , my PWM input range is from 0.5ms to 1.5ms . so, i want to define 0.5ms as -100%, 1ms as 0% and 1.5ms as +100%, in ardunio. I will have an another input from motor feedback from potentiometer, to detect the position of motor. Let say, my feedback range is from 0 ohm to 10 ohm. so, i want to define 0ohm as -100%, 5ohm as 0% and 10 ohm as 100%, in ardunio.

After defining two inputs, i have the formula (Pwm input% - feedback% = result%). I would like two have the final output as two bits. If the result% is +ve, i want to have two bits output as bit1= 0 and bit2= 1. If the result% is -ve, i want to have two bits output as bit1= 1 and bit2= 0. Can you kindly help me with the programing for above case:D. Your help is much appreciated.

void setup() {}

void loop() { int PWMVal = digitalRead(0); int OhmVal = analogRead(1); int a, b, bit1, bit2, result;

a = map(PWMVal, 0.5, 1.5, -100, 100); b = map(OhmVal, 0, 10, -100, 100);

result = (a - b);

if (result > 0) { bit1 = 0; bit2 = 1;} else {bit1 = 1; bit2 = 0;}

}

Check the constrain() and map() functions.

Hope that helped!

a = map(PWMVal, 0.5, 1.5, -100, 100);

map takes integer arguments, so use microseconds instead of fractions of milliseconds.

digitalread is only ever going to return 0 or 1; did you mean pulseIn?

Not sure... Took a shot in the dark... Other then the digital read... is the rest of the code correct?

The second map seems a bit unlikely - you're not reading ohms, you're reading the voltage at the output of a voltage divider.

True… I see the problem.

Well that was just starting point for OP… so hopefully he/she can work it out, or another member can speak up True. I'm not sure I'd want to wire a 10 ohm pot across 5V though.

Yeah, 10 ohm pot with 5V, can you say "Smokin'!"

Power dissipated =V*V/R = 25/10 = 2.5W!