fixed an overflow issue in AP_RC

git-svn-id: https://arducopter.googlecode.com/svn/trunk@2074 f9c3cf11-9bcb-44bc-f272-b75c42450872
This commit is contained in:
jasonshort 2011-05-03 04:32:37 +00:00
parent 85d006c290
commit 6d4b77340b
1 changed files with 40 additions and 34 deletions

View File

@ -36,10 +36,10 @@ volatile int16_t timer4diff = 1500 * 2;
#define CH_4 3
volatile int8_t _rc_ch_read;
volatile uint8_t _timer_out;
volatile uint8_t _timer_ovf_a;
volatile uint8_t _timer_ovf_b;
volatile uint8_t _timer_ovf;
volatile uint16_t _timer_out;
volatile uint16_t _timer_ovf_a;
volatile uint16_t _timer_ovf_b;
volatile uint16_t _timer_ovf;
AP_RC::AP_RC()
@ -117,27 +117,33 @@ AP_RC::output_ch_pwm(uint8_t ch, uint16_t pwm)
{
switch(ch){
case CH_1:
pwm <<= 1;
pwm <<= 1; // multiplies by 2
OCR1A = pwm;
break;
case CH_2:
pwm <<= 1;
OCR1B = pwm;
OCR1B = pwm; // multiplies by 2
break;
case CH_3:
_timer_out = pwm % 512;
_timer_ovf_a = pwm / 512;
_timer_out >>= 1;
_timer_out >>= 1; // divides by 2
//OCR2A = _timer_out;
if(OCR2A != _timer_out)
OCR2A = _timer_out;
break;
case CH_4:
_timer_out = pwm % 512;
_timer_ovf_b = pwm / 512;
_timer_out >>= 1;
_timer_out >>= 1; // divides by 2
//OCR2B = _timer_out;
if(OCR2B != _timer_out)
OCR2B = _timer_out;
break;
}
}