6,9 → 6,10 |
volatile unsigned int cntKompass = 0; |
volatile unsigned int beeptime = 0; |
volatile unsigned char SendSPI = 0; |
volatile unsigned int ServoState = 40; |
|
unsigned int BeepMuster = 0xffff; |
int ServoValue = 0; |
unsigned int ServoValue = 0; |
|
enum { |
STOP = 0, |
85,7 → 86,7 |
} |
} |
|
|
//---------------------------- |
void Timer_Init(void) |
{ |
tim_main = SetDelay(10); |
97,10 → 98,11 |
//OCR1 = 0x00; |
|
TCCR2A=(1<<COM2A1)|(1<<COM2A0)|3; |
TCCR2B=(0<<CS20)|(1<<CS21)|(1<<CS22); |
// TCCR2B=(0<<CS20)|(1<<CS21)|(1<<CS22); // clk/256 |
TCCR2B=(0<<CS20)|(0<<CS21)|(1<<CS22); // clk/64 |
|
// TIMSK2 |= _BV(TOIE2); |
TIMSK2 |= _BV(OCIE2A); |
|
TIMSK2 |= _BV(OCIE2A); |
|
TIMSK0 |= _BV(TOIE0); |
OCR2A = 10; |
143,26 → 145,54 |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// Servo ansteuern |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
SIGNAL(SIG_OVERFLOW2) |
{ |
if (ServoState > 0) PORTD |= 0x80; |
else PORTD &= ~0x80; |
TCCR2A =3; |
TIMSK2 &= ~_BV(TOIE2); |
} |
|
SIGNAL(SIG_OUTPUT_COMPARE2A) |
{ |
static unsigned char timer = 10; |
|
if(!timer--) |
static unsigned char postPulse = 0x80; |
static int filterServo = 100; |
#define MULTIPLIER 4 |
if(ServoState == 4) |
{ |
TCCR2A=(1<<COM2A1)|(0<<COM2A0)|3; |
ServoValue = Parameter_ServoNickControl; |
if(EE_Parameter.ServoNickCompInvert & 0x01) ServoValue += ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
else ServoValue -= ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
|
if(ServoValue < EE_Parameter.ServoNickMin) ServoValue = EE_Parameter.ServoNickMin; |
else if(ServoValue > EE_Parameter.ServoNickMax) ServoValue = EE_Parameter.ServoNickMax; |
ServoValue = 0x0030; // Offset Part1 |
filterServo = (filterServo * 3 + (int) Parameter_ServoNickControl * 2)/4; |
ServoValue += filterServo; |
if(EE_Parameter.ServoNickCompInvert & 0x01) ServoValue += ((long) ((long)EE_Parameter.ServoNickComp * IntegralNick) / 128L )/ (512L/MULTIPLIER); |
else ServoValue -= ((long) ((long)EE_Parameter.ServoNickComp * IntegralNick) / 128L) / (512L/MULTIPLIER); |
if((ServoValue) < ((int)EE_Parameter.ServoNickMin*3)) ServoValue = (int)EE_Parameter.ServoNickMin*3; |
else if((ServoValue) > ((int)EE_Parameter.ServoNickMax*3)) ServoValue = (int)EE_Parameter.ServoNickMax*3; |
|
DebugOut.Analog[20] = ServoValue; |
if ((ServoValue % 255) < 45) { ServoValue+= 77; postPulse = 0x60 - 77; } else postPulse = 0x60; |
OCR2A = 255-(ServoValue % 256); |
TCCR2A=(1<<COM2A1)|(1<<COM2A0)|3; |
} |
else if ((ServoState > 0) && (ServoState < 4)) |
{ |
if(ServoValue > 255) |
{ PORTD |= 0x80; |
TCCR2A =3; |
ServoValue -= 255; |
} |
else |
{ |
TCCR2A=(1<<COM2A1)|(0<<COM2A0)|3; |
OCR2A = postPulse; // Offset Part2 |
ServoState = 1; |
} |
} |
else if (ServoState == 0) |
{ |
ServoState = (int) EE_Parameter.ServoNickRefresh * MULTIPLIER; |
PORTD&=~0x80; |
TCCR2A = 3; |
} |
ServoState--; |
|
OCR2A = ServoValue;// + 75; |
timer = EE_Parameter.ServoNickRefresh; |
} |
else |
{ |
TCCR2A =3; |
PORTD&=~0x80; |
} |
} |