Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

reading input voltage on ATmega32A

Status
Not open for further replies.
Dear friends!

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

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.

Latest threads

New Articles From Microcontroller Tips

Back
Top