Code:
volatile unsigned char ServoTimesA[8];
volatile unsigned char ServoCountA;
volatile unsigned char ChannelCount;
volatile unsigned char ADCInited;
ISR(SIG_ADC)
{
cli();
if (ADCInited == 1){
ServoTimesA[ChannelCount] = (ADC/12)+58; //WENN icH DAS HIER AUSKOMMENTIER ODER EINE EINFACHE VARIABLE NEHME IST DER SERVO STABIL
ChannelCount++;
}
else {
ADCInited = 1;
}
// ADMUX = (ADMUX & 0b11100000) + ChannelCount;
ADMUX = (ADMUX & 0b11100000);
if (ChannelCount >= 8) ChannelCount = 0;
sei();
}
ISR(SIG_OUTPUT_COMPARE2)
{
cli();
PORTC = ~(1<<ServoCountA);
OCR2 = ServoTimesA[ServoCountA];
ServoCountA++;
if (ServoCountA >= 8) ServoCountA = 0;
sei();
}
int main()
{
ChannelCount = 0;
ADCInited = 0;
ADMUX = (1<<REFS0) | 0b00011111;
ADCSRA = (1<<ADEN) | (1<<ADIE) | (1<<ADPS0) | (1<<ADPS1) | (1<<ADPS2) | (1<<ADATE) | (1<<ADSC);
SFIOR = 0;
ServoTimesA[0] = 60;
ServoTimesA[1] = 100;
ServoTimesA[2] = 140;
ServoTimesA[3] = 100;
ServoTimesA[4] = 100;
ServoTimesA[5] = 100;
ServoTimesA[6] = 100;
ServoTimesA[7] = 100;
ServoCountA = 0;
sei();
DDRC = 0xFF;
DDRA = 0;
TCCR2 = /*(1<<WGM20) |*/ (1<<WGM21) | /*(1<<COM20) | (1<<COM21) |*/ (1<<CS22) | (1<<CS20);
OCR2 = 200;
DDRD = (1<<PD7) | (1<<PD4) | (1<<PD5);
TIMSK = (1<<OCIE2);
TCCR1B = (1<<CS11) | (1<<CS11);
TCCR1A = (1<<COM1B1) | (1<<COM1A1) | (1<<WGM12) /*| (1<<WGM11)*/ | (1<<WGM10);
OCR1A = 200;
OCR1B = 255;
while(1);
return 0;
}
Lesezeichen