Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to have Pwm and Adc with atmega8

Status
Not open for further replies.

greentree

Member level 5
Member level 5
Joined
Sep 25, 2011
Messages
86
Helped
13
Reputation
26
Reaction score
13
Trophy points
1,288
Location
The center of world!
Visit site
Activity points
1,739
hi*
I will use mcu for pwm and adc .
when voltage in adc0 is more than 2.5v D.C become low and reverse ...
i could make pwm with timer 1 with atmega8 , but about adc i don't know why i can't...!?

Best regards
 

What is the problem you are facing?

The ATMEGA8 has an internal 10-bit ADC module that you can easily use. You can find all necessary information in the datasheet. For your convenience, here's the ADC section of the ATMEGA8: **broken link removed**

Hope this helps.
Tahmid.
 

Here's a code for using the ADC. I wrote it in mikroC, but you should be able to port it to CodeVision.

Code:
unsigned char ADRL, ADRH;
unsigned int ADR;

void main() {
     DDRD = 0xFF;  //PORTD all outputs
     DDRC = 0xFE;  //PORTC0 input
     
     ADMUX = 0x00; //Channel 0 to be sampled; VREF is AREF
     ADCSRA = 0x85; //ADC enabled; free run mode disabled; prescaler factor 32
     
     delay_ms(10);
     
     while (1){
           ADSC_bit = 1; //Start conversion by setting bit 6 of
                         //                 ADSRA register - ADSC
           while (ADSC_bit == 1); //Wait for end of conversion
           ADRL = ADCL; //Read ADLARL first
           ADRH = ADCH; //Read ADLARH after ADLARL
           ADR = (ADRH << 8) | ADRL; //Compile the 2 into 16-bit register
           PORTD = ADR >> 2; //Send an 8-bit result to PORTD
           delay_ms(1000); //Just wait 1ms
     }
}

The clock frequency is 8MHz. PORTC0 (ADC0) is sampled. The corresponding 8-bit data is sent to PORTD. You can use this code as your reference and then make your own code as required.

Go through the datasheet to make sure you understand what I did and also so you know about the other settings and modes of operation.

Hope this helps.
Tahmid.
 
when i simulate this code on proteus it gives error message
"[AVR AD converter ]Reference =0"
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top