Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 688 → Rev 689

/branches/V0.68d Code Redesign killagreg/rc.c
34,6 → 34,12
DDRD &= ~(1<<DDD6);
PORTD |= (1<<PORTD6);
 
// Channel 5,6,7 is decoded to servo signals at pin PD5 (J3), PD4(J4), PD3(J5)
// set as output
DDRD |= (1<<DDD5)|(1<<DDD4)|(1<<DDD3);
// low level
PORTD &= ~((1<<PORTD5)|(1<<PORTD4)|(1<<PORTD3));
 
// Timer/Counter1 Control Register A, B, C
 
// Normal Mode (bits: WGM13=0, WGM12=0, WGM11=0, WGM10=0)
127,10 → 133,10
PPM_in[index] = tmp; // update channel value
}
index++; // next channel
// demux sum signal fpr channels 5 to 7
if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20; // Servosignal an J3 anlegen
if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10; // Servosignal an J4 anlegen
if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08; // Servosignal an J5 anlegen
// demux sum signal for channels 5 to 7 to J3, J4, J5
if(index == 5) PORTD |= (1<<PORTD5); else PORTD &= ~(1<<PORTD5);
if(index == 6) PORTD |= (1<<PORTD4); else PORTD &= ~(1<<PORTD4);
if(index == 7) PORTD |= (1<<PORTD3); else PORTD &= ~(1<<PORTD3);
}
}
}
/branches/V0.68d Code Redesign killagreg/timer2.c
33,9 → 33,9
 
// Timer/Counter 2 Control Register B
 
// Set clock divider for timer 2 to SYSKLOCK/8 = 20MHz / 8 = 2.5MHz.
// Set clock divider for timer 2 to SYSKLOCK/8 = 20MHz / 8 = 2.5MHz
// The timer increments from 0x00 to 0xFF with an update rate of 2.5 MHz,
// hence the timer overflow interrupt frequency is 2.5 MHz / 256 = 9.765 kHz
// hence the timer overflow interrupt frequency is 2.5 MHz / 256 = 9.765 kHz or 0.1024 ms
 
// divider 8 (Bits: CS022 = 0, CS21 = 1, CS20 = 0)
TCCR2B &= ~((1<<FOC2A)|(1<<FOC2B)|(1<<WGM22));
65,33 → 65,33
 
if(!timer--)
{
// enable PWM on PD7 in non inverting mode
TCCR2A = (TCCR2A & 0x3F)|(1<<COM2A1)|(0<<COM2A0);
// enable PWM on PD7 in non inverting mode
TCCR2A = (TCCR2A & 0x3F)|(1<<COM2A1)|(0<<COM2A0);
 
ServoValue = Parameter_ServoNickControl;
// inverting movment of servo
if(ParamSet.ServoNickCompInvert & 0x01)
{
ServoValue += ((int32_t) ParamSet.ServoNickComp * (IntegralNick / 128)) / 512;
}
else // non inverting movement of servo
{
ServoValue -= ((int32_t) ParamSet.ServoNickComp * (IntegralNick / 128)) / 512;
}
ServoValue = Parameter_ServoNickControl;
// inverting movment of servo
if(ParamSet.ServoNickCompInvert & 0x01)
{
ServoValue += ((int32_t) ParamSet.ServoNickComp * (IntegralNick / 128)) / 512;
}
else // non inverting movement of servo
{
ServoValue -= ((int32_t) ParamSet.ServoNickComp * (IntegralNick / 128)) / 512;
}
 
// limit servo value to its parameter range definition
if(ServoValue < ParamSet.ServoNickMin)
{
ServoValue = ParamSet.ServoNickMin;
}
else if(ServoValue > ParamSet.ServoNickMax)
{
ServoValue = ParamSet.ServoNickMax;
}
// limit servo value to its parameter range definition
if(ServoValue < ParamSet.ServoNickMin)
{
ServoValue = ParamSet.ServoNickMin;
}
else if(ServoValue > ParamSet.ServoNickMax)
{
ServoValue = ParamSet.ServoNickMax;
}
 
// update PWM
OCR2A = ServoValue;
timer = ParamSet.ServoNickRefresh;
// update PWM
OCR2A = ServoValue;
timer = ParamSet.ServoNickRefresh;
}
else
{