Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 688 → Rev 689

/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
{