/* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ____ _ _ _____ ____ ____ _______ | _ \| | | |/ ____| | _ \ / __ \__ __| | |_) | | | | | __ ______ | |_) | | | | | | | | _ <| | | | | |_ | |______| | _ <| | | | | | | | |_) | |__| | |__| | | |_) | |__| | | | | |____/ \____/ \_____| |____/ \____/ |_| | | \ | / HOGESCHOOL VAN AMSTERDAM -(+)- / 0 \ Functie: uitleg adc auteur: Bob Ram xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx */ /* Project: Robert de Rare Ruige Razendsnelle Race Robot Functie: ADC read Standaard Mic: AtMega32 Maker: Bob Ran Datum: 26-4-2006 */ #define F_CPU 8000000UL // 8 MHz #include #define ADC_PRE16 ADCSRA |= 0x04; ADCSRA &= ~0x03 // prescaler 16 = 125kHz; configuration in ADCSRA = xxxx x100 #define ADC_INT_EN ADCSRA |= 0x08 // Interrupts #define ADC_INT_DIS ADCSRA &= ~0x08 #define ADC_EN ADCSRA |= 0x80 // Enable/Disable ADC #define ADC_DIS ADCSRA &= ~0x80 #define ADC_CONVERT ADCSRA |= 0x40 // Convert command #define ADC_BUSY ADCSRA & 0x40 #define nop() __asm__ __volatile__ ("nop" ::) void InitADC(void) { // ADCSRA = 0x84; ADC_EN; ADC_PRE16; } unsigned int ADCRead(unsigned char channel) { unsigned int adcval; ADMUX = channel; // MAYBE 20/3 cause 1 iteration per 3 clock cylces _delay_loop_1(7); //__delay_cycles(20); // settling time mux > adc ADC_CONVERT; while(ADC_BUSY) nop(); //__no_operation(); _delay_loop_1(7); //__delay_cycles(20); // settling time mux > adc //USART_Transmit(channel); // channel nummer //USART_Transmit(ADCL); // data H //USART_Transmit(ADCH); // data L adcval=ADCL; adcval+=(ADCH<<8); return adcval; } /*unsigned char adcval_high; unsigned char adcval_low; void ADC_Init(void) // initialiseer A/D converter { ADMUX = 0x40; // Select channel 1 ADCSRA = 0xEF; // A/D enable, Start conversion, inerrupt enable, division factor 128 } SIGNAL(SIG_ADC) { adcval_low = ADCL; // Zet de waarde uit het ADC low register in char adcval_low adcval_high = ADCH; // Zet de waarde uit het ADC high register in char adcval_high ADCSRA = ADCSRA | 0x40; // Trigger de ADC again }*/