|
Re: Need help with PWM 1-2ms pulse control
on the software side, heres my take.
I read that you want to map the analog pot directly to the pwm out right, so heres what I'd do:
pwm01 = Get_Analog_Value(rc_ana_in01) >> 2;
Now for the question on having two "sets".
Assuming you are getting full 10 bits range now and you want two sets
char set = 1; // set to 0 for the other set, or hook a switch up to this variable.
if(set == 1) {
// 127 to 254
pwm01 = (Get_Analog_Value(rc_ana_in01) >> 3) + 127;
} else {
// 127 to 0
pwm01 = 127 - (Get_Analog_Value(rc_ana_in01) >> 3);
}
maybe you need to add some casting above but on overall it should be correct.
Explanation:
Get_Analog_Value(rc_ana_in01) >> 3
Previously it was '>> 2', because I'm doing a bit shift so that the range from 0-1023 becomes 0-254 (8bits)
Now its >>3 as I'm sizing the range to 0-127 (7 bits) to be used in the calculation to scale set 1 (127 to 254) or set 2 (127 to 0).
|