Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 801 → Rev 802

/branches/V0.68d Code Redesign killagreg/fc.c
1011,6 → 1011,8
tmp_int = (int32_t) ParamSet.Yaw_P * ((int32_t)StickYaw * abs(StickYaw)) / 512L; // expo y = ax + bx²
tmp_int += (ParamSet.Yaw_P * StickYaw) / 4;
SetPointYaw = tmp_int;
// trimm drift of Reading_IntegralGyroYaw with SetPointYaw(StickYaw)
Reading_IntegralGyroYaw -= tmp_int;
// limit the effect
if(Reading_IntegralGyroYaw > 50000) Reading_IntegralGyroYaw = 50000;
if(Reading_IntegralGyroYaw <-50000) Reading_IntegralGyroYaw =-50000;
/branches/V0.68d Code Redesign killagreg/rc.c
67,9 → 67,9
 
// Enable Input Capture Interrupt (bit: ICIE1=1)
// Disable Output Compare A & B Match Interrupts (bit: OCIE1B=0, OICIE1A=0)
// Disable Overflow Interrupt (bit: TOIE1=0)
TIMSK1 &= ~((1<<OCIE1B)|(1<<OCIE1A)|(1<<TOIE1));
TIMSK1 |= (1<<ICIE1);
// Enable Overflow Interrupt (bit: TOIE1=0)
TIMSK1 &= ~((1<<OCIE1B)|(1<<OCIE1A));
TIMSK1 |= (1<<ICIE1)|(1<<TOIE1);
 
RC_Quality = 0;
 
77,6 → 77,19
}
 
 
// happens every 0.209712 s.
// check for at least one input capture event per timer overflow (timeout)
ISR(TIMER1_OVF_vect)
{
int16_t signal = 0;
static uint16_t lastICR1 = 0;
// if ICR1 has not changed
// then no new input capture event has occured since last timer overflow
if (lastICR1 == ICR1) RC_Quality = 0;
lastICR1 = ICR1; // store last ICR1
}
 
 
/********************************************************************/
/* Every time a positive edge is detected at PD6 */
/********************************************************************/
100,10 → 113,10
*/
ISR(TIMER1_CAPT_vect) // typical rate of 1 ms to 2 ms
{
static uint16_t oldICR1 = 0;
int16_t signal = 0, tmp;
static int16_t index;
static int16_t Sum_RC_Quality = 0;
static uint16_t oldICR1 = 0;
int16_t Noise;
 
// 16bit Input Capture Register ICR1 contains the timer value TCNT1
115,7 → 128,12
signal = (uint16_t) ICR1 - oldICR1;
oldICR1 = ICR1;
 
 
// lost frame
if(signal > 8000)
{
Sum_RC_Quality -= Sum_RC_Quality/2;
}
else
//sync gap? (3.52 ms < signal < 25.6 ms)
if((signal > 1100) && (signal < 8000))
{
126,7 → 144,7
index = 1;
}
else // within the PPM frame
{
{
if(index < 14) // PPM24 supports 12 channels
{
// check for valid signal length (0.8 ms < signal < 2.1984 ms)
137,7 → 155,8
signal -= 466; // offset of 1.4912 ms ??? (469 * 3.2µs = 1.5008 ms)
// check for stable signal
Noise = abs(signal - PPM_in[index]);
if((Noise/16) > (200-RC_Quality)) // spike detector
if (Noise > 150) Sum_RC_Quality /= 2;
else if((Noise/16) > (200-RC_Quality)) // spike detector
{
Sum_RC_Quality -= 3*RC_Quality;
Sum_RC_Quality += 3*(200 - Noise);
158,10 → 177,8
}
else
{ // invalid PPM time
Sum_RC_Quality -= Sum_RC_Quality/4;
Sum_RC_Quality /= 2;
}
if(Sum_RC_Quality < 0) Sum_RC_Quality = 0;
RC_Quality = Sum_RC_Quality/128;
index++; // next channel
// demux sum signal for channels 5 to 7 to J3, J4, J5
if(index == 5) PORTD |= (1<<PORTD5); else PORTD &= ~(1<<PORTD5);
172,6 → 189,8
}
}
}
if(Sum_RC_Quality < 0) Sum_RC_Quality = 0;
RC_Quality = Sum_RC_Quality/128;
}