View Single Post
  #17   Spotlight this post!  
Unread 01-05-2008, 02:24
yongkimleng yongkimleng is offline
deus ex programmeur
AKA: James Yong
FTC #0747
Team Role: Mentor
 
Join Date: Aug 2006
Rookie Year: 2004
Location: Singapore, West
Posts: 134
yongkimleng is a jewel in the roughyongkimleng is a jewel in the roughyongkimleng is a jewel in the rough
Send a message via MSN to yongkimleng
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).
__________________
| jamesyong.net |
FVC2007, FTC2008