Subversion Repositories FlightCtrl

Compare Revisions

Regard whitespace Rev 1126 → Rev 1127

/branches/thjac/V1_10/timer0.c
24,61 → 24,55
T0_RISING_EDGE = 7
};
 
 
SIGNAL (SIG_OVERFLOW0) // 8kHz
{
static unsigned char cnt_1ms = 1,cnt = 0;
unsigned char pieper_ein = 0;
// TCNT0 -= 250;//TIMER_RELOAD_VALUE;
if(SendSPI) SendSPI--;
if(!cnt--)
{
cnt = 9;
cnt_1ms++;
cnt_1ms %= 2;
if(!cnt_1ms) UpdateMotor = 1;
if (SendSPI)
SendSPI--;
if (!cnt--) {
// cnt = 9; // Wenn der Kommentar 8kHz oben stimmt, muß durch 8 geteilt werden, nicht durch 10!
cnt = 7;
// cnt_1ms++;
// cnt_1ms %= 2;
cnt_1ms = !cnt_1ms; // So ist das etwas einfacher
if (!cnt_1ms)
UpdateMotor = 1;
CountMilliseconds++;
}
 
if(beeptime > 1)
{
if (beeptime > 1) {
beeptime--;
if(beeptime & BeepMuster)
{
pieper_ein = 1;
}
else pieper_ein = 0;
}
else
{
pieper_ein = 0;
} else {
pieper_ein = 0;
BeepMuster = 0xffff;
}
 
 
if(pieper_ein)
{
if(PlatinenVersion == 10) PORTD |= (1<<2); // Speaker an PORTD.2
else PORTC |= (1<<7); // Speaker an PORTC.7
}
if (pieper_ein) {
if (PlatinenVersion == 10)
PORTD |= (1 << 2); // Speaker an PORTD.2
else
{
if(PlatinenVersion == 10) PORTD &= ~(1<<2);
else PORTC &= ~(1<<7);
PORTC |= (1 << 7); // Speaker an PORTC.7
} else {
if (PlatinenVersion == 10)
PORTD &= ~(1 << 2);
else
PORTC &= ~(1 << 7);
}
if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)
{
if (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) {
if(PINC & 0x10)
{
cntKompass++;
}
else
{
if((cntKompass) && (cntKompass < 362))
{
else {
if ((cntKompass) && (cntKompass < 362)) {
cntKompass += cntKompass / 41;
if(cntKompass > 10) KompassValue = cntKompass - 10; else KompassValue = 0;
if (cntKompass > 10) KompassValue = cntKompass - 10;
else KompassValue = 0;
}
// if(cntKompass < 10) cntKompass = 10;
// KompassValue = (unsigned long)((unsigned long)(cntKompass-10)*720L + 1L) / 703L;
89,8 → 83,8
}
 
//----------------------------
void Timer_Init(void)
{
 
void Timer_Init(void) {
tim_main = SetDelay(10);
TCCR0B = CK8;
TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM
114,8 → 108,7
 
// -----------------------------------------------------------------------
 
unsigned int SetDelay (unsigned int t)
{
unsigned int SetDelay(unsigned int t) {
// TIMSK0 &= ~_BV(TOIE0);
return(CountMilliseconds + t + 1);
// TIMSK0 |= _BV(TOIE0);
122,8 → 115,8
}
 
// -----------------------------------------------------------------------
char CheckDelay(unsigned int t)
{
 
char CheckDelay(unsigned int t) {
// TIMSK0 &= ~_BV(TOIE0);
return(((t - CountMilliseconds) & 0x8000) >> 9);
// TIMSK0 |= _BV(TOIE0);
130,23 → 123,24
}
 
// -----------------------------------------------------------------------
void Delay_ms(unsigned int w)
{
 
void Delay_ms(unsigned int w) {
unsigned int akt;
akt = SetDelay(w);
while (!CheckDelay(akt));
}
 
void Delay_ms_Mess(unsigned int w)
{
void Delay_ms_Mess(unsigned int w) {
unsigned int akt;
akt = SetDelay(w);
while (!CheckDelay(akt)) ANALOG_ON;
while (!CheckDelay(akt))
ANALOG_ON;
}
 
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Servo ansteuern
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
SIGNAL(SIG_OVERFLOW2) {
 
if (ServoState > 0)
180,11 → 174,10
/* Über Parameter läßt sich zwischen "+" und "X" - Formations
* umschalten (sh. parameter.h)
*/
if( PARAM_X_FORMATION ) {
if (PARAM_X_FORMATION)
integral = IntegralNick - IntegralRoll;
} else {
else
integral = IntegralNick;
}
 
if( EE_Parameter.ServoNickCompInvert & 0x01 )
ServoValue += ( (long) ( (long) EE_Parameter.ServoNickComp * integral ) >> DIV_128 ) / ( 512L >> DIV_4 );
196,9 → 189,8
if ( ( ServoValue % 255 ) < 45 ) {
ServoValue += 77;
postPulse = 0x60 - 77;
} else {
} else
postPulse = 0x60;
}
OCR2A = 255 - ( ServoValue % 256 );
TCCR2A = (1 << COM2A1 ) | ( 1 << COM2A0 ) | 3;