Moin,
Ich habe mir für meinen Bot ein Programm zusammen geschnitten. Es soll ADC7-4 auslesen, und demendsprechend die Motoren per L293D H-Brücke ansteuernl.
Jedoch wird immer nur ein ADC-Kanal ausgelesen. Ich habe echt keine Ahnung, woran das liegen kann.
Könnte mir mal bitte jmd. über das Programm schauen?
http://rafb.net/p/LbsHLK81.html
Code:#include <avr/io.h> #include <stdlib.h> #include <inttypes.h> #include <avr/interrupt.h> #include <util/delay.h> volatile unsigned char servopos0; #define SERVO_0_PIN 7 #define SERVOPORT PORTC #define DDRSERVO DDRC #ifndef F_CPU #define F_CPU 8000000UL #endif void servo_init() { TIMSK|=(1<<OCIE2); TCCR2 |= (1<<WGM21) | (1<<CS20); OCR2 = F_CPU/100000; DDRSERVO |= (1<<SERVO_0_PIN); } ISR(TIMER2_COMP_vect) { char cSREG; cSREG = SREG; static int scount; if(scount>servopos0)SERVOPORT&=~(1<<SERVO_0_PIN); else SERVOPORT|=(1<<SERVO_0_PIN); if(scount<2000)scount++; else scount=0; SREG = cSREG; } uint16_t readADC(uint8_t channel) { uint8_t i; uint16_t result0 = 0; uint16_t result1 = 0; uint16_t result2 = 0; uint16_t result3 = 0; ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1); ADMUX = channel; ADMUX |= (1<<REFS1) | (1<<REFS0); ADCSRA |= (1<<ADSC); while(ADCSRA & (1<<ADSC)); for(i=0; i<3; i++) { ADCSRA |= (1<<ADSC); while(ADCSRA & (1<<ADSC)); result0+= ADCW; result1+= ADCW; result2+= ADCW; result3+= ADCW; } ADCSRA &= ~(1<<ADEN); result0/= 3; result1/= 3; result2/= 3; result3/= 3; return result0; return result1; return result2; return result3; } /***************************Hauptprogramm***************************/ int main (void) { DDRD = 0xFF; PORTA = 0b00001111; uint16_t result0 = 0; uint16_t result1 = 0; uint16_t result2 = 0; uint16_t result3 = 0; servo_init(); sei(); while (1) { servopos0 = 100; result0= readADC(4); result1= readADC(5); result2= readADC(6); result3= readADC(7); if(result0 >=300, result1 >= 300, result2 >= 300) { PORTD |= (1<<PD5); PORTA |= ((1<<PA0) | (1<<PA1) | (1<<PA2) | (1<<PA3)); _delay_ms (100); PORTA |= ((1<<PA0) | (1<<PA2)); PORTA &=~ ((1<<PA1) | (1<<PA3)); _delay_ms (100); PORTA |= ((1<<PA0) | (1<<PA1)); _delay_ms(100); } else { PORTD |= (1<<PD5); PORTA |= ((1<<PA1) | (1<<PA3)); PORTA &=~ ((1<<PA0) | (1<<PA2)); } } }
Mfg JeyBee







Zitieren

Lesezeichen