On Wed, 2008-01-30 at 22:10 -0700, Mikey Sklar wrote: > I recently built a circuit board to measure the temperature of the > grease flowing through my car. The car is a old Mercedes running on > Waste Vegetable Oil from restaurant dumpsters. I was able to upload my > code and single step with gdb then I found a issue. The ADCW register > reports back 1023 despite my sensors running a wide range of values > between 1.9V - 5V. > > Has anyone else seen this behavior before? > > Setup: > - atmega169 (TQFP) > - avarice (v2.5) > - avr-gcc (4.0.2) > - avr-libc (1.4.5) > - avr-gdb (6.5) > - jtag clone serial based programmer (MK-I only) > - Mac OS/X 10.4.11 > > Code: > > #include <avr/io.h> > #include <avr/interrupt.h> > > > #define SENSORS 2 // three thermistors measuring temperature (0-2) > > > SIGNAL(SIG_ADC); > int main (void); > > > unsigned int adc_data; //variable for ADC results > unsigned int illuminate; //led display pattern > > > SIGNAL(SIG_ADC) //ADC ISR > { > > adc_data = ADCW; //read all 10 bits into variable > > > /* ADC data from thermistors translated into five different hex values. > Hex values are stored for display to appropriate output LED port. > Shows driver grease temperature by illuminating LEDs. > The more LEDs that are on, the hotter the fuel is. */ > > if ( adc_data <= 432 ) > illuminate = 0x00; // less than 65F - all lights off > else if ( adc_data > 432 && adc_data <= 530) > illuminate = 0x01; // 65F - 85F bin: 0001 dec: 1 hex: > 0x01 > else if (adc_data > 530 && adc_data <= 770 ) > illuminate = 0x03; // 85F - 105F bin: 0011 dec: 3 hex: > 0x03 > else if (adc_data > 770 && adc_data <= 827) > illuminate = 0x07; // 105F - 125F bin: 0111 dec: 7 hex: > 0x07 > else if (adc_data > 827 && adc_data <= 1023) > illuminate = 0x0F; // 135F+ bin: 1111 dec: 0 hex: > 0x0F > else > illuminate = 0x00; //error all lights off > > > if ( ADMUX == 0 ) { > PORTA = illuminate; //store sensor results for display > } > else if ( ADMUX == 1 ) { > PORTC = illuminate; //store sensor results for display > } > else if ( ADMUX == 2 ) { > PORTD = illuminate; //store sensor results for display > } > else { > PORTA = 0x0A; //MUX Error: 0101 (led pattern) > PORTC = 0x0A; //MUX Error: 0101 (led pattern) > PORTD = 0x0A; //MUX Error: 0101 (led pattern) > } > > > // rotate through sensors > if ( ADMUX < SENSORS ) > ADMUX += 1; //change mux to next sensor > else > ADMUX = 0; //reset mux to first sensor > > > ADCSRA = ADCSRA | 0x40; //start the next conversion > > } > > > int main(void) > { > DDRA=0x0F; //LED output (first four pins) > DDRC=0x0F; //LED output (first four pins) > DDRD=0x0F; //LED output (first four pins) > ADCSRA=0xCE; //ADC on, /64, interrupt enable, and started > ADMUX=0x00; //ADC registers PF0, PF1, PF2 one at a time You've cleared the bits REFS0 and REFS1 so you must connect a refrence voltage to AREF (pin 62). > > PORTA = 0x0F; //power on: 1111 (led pattern) > PORTC = 0x0F; //power on: 1111 (led pattern) > PORTD = 0x0F; //power on: 1111 (led pattern) > > sei(); //global interrupt enable bit > > while(1) { > } > }
__ Ormund _______________________________________________ AVR-chat mailing list AVR-chat@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-chat