reading input voltage on ATmega32A

Status
Not open for further replies.

Georg

New Member
Dear friends!

What should be a C program to read signal from the input port on Atmega32A ?
 
Dear friends!

What should be a C program to read signal from the input port on Atmega32A ?

try this:
Code:
void adc_init (void) {
	// ADC Clock frequency: 1000.000 kHz
	// ADC Voltage Reference: AVCC pin
	// ADC Auto Trigger Source: Free Running
	ADMUX=0x40;
	ADCSRA=0xA3;
	SFIOR&=0x1F;
}

unsigned int adc_read (unsigned char channel) {
	ADMUX=channel | 0x40;
	_delay_us(10);					// Delay needed for the stabilization of the ADC input voltage
	ADCSRA|=0x40;					// Start the AD conversion
	while ((ADCSRA & 0x10)==0);		// Wait for the AD conversion to complete
	ADCSRA|=0x10;
	return ADCW;
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…