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.

ATmega8 ADC and PORT Enabling

Status
Not open for further replies.

imranahmed

Advanced Member level 3
Advanced Member level 3
Joined
Dec 4, 2011
Messages
822
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Karachi,Pakistan
Visit site
Activity points
6,533
Please can anyone explain me this lines below:

#define PORT_ON(port,pin) port |= (1<<pin)
#define PORT_OFF(port,pin) port &= ~(1<<pin)


And how to enable ADC of ATmega8 and AREF and AVCC pins purpose.
 

Concerning the first part of your inquiry.

The following is simply a macro:

Code:
#define PORT_ON(port,pin) port |= (1<<pin)

During the preprocessing phase of compilation, if the following is encountered within your code with the parameters port and pin replaced with appropriate symbols/values:

Code:
PORT_ON(port,pin);

It is simply replace by the following, with symbols/values for port and pin utilized in the first instance:

Code:
port |= (1<<pin);

It's a method of generic macro expansion, in contrast to actually writing an actual function or subroutine.

For appropriate symbols/values for port and pin, reference the device specific header file of your specific device, in this case the ATMega8.

The AREF is utilized to supply the Vref to the ADC, which in some cases may differ from the Vcc supply of the device.

For example if you want to limit the range of the devices ADC to 0V to 2V, rather than 0V to Vcc, typically 5V or 3.3V of the devices power rail.

You can also utilize a precision voltage source by applying its output to AREF.

The AVCC pin is simply the power to the ADC which is typically the same as Vcc of the device, 5V or 3.3V.

The AVR Analog to Digital Converter (ADC)

Using the AVR Analog To Digital Converter.


BigDog
 
Thank you for knowledgeable reply,

Please let me know that, I want to make Ammeter Atmega8 based Current Transformer Operated.
Please refer me some examples and techniques.
 

Please can anyone tell me about ADC of ATmega8 of 10-bit resolution.

I have to set prescaler value of 32 at 8 MHz internal oscillator, AVCC and AREF connected, with 3-digit 7-segment display.
How to calculate voltage divider values for 1V,2V......400V input voltage will show 1,2....400 respectively on 7-segment display.
 

Please anyone tell what is the problem occur in the program given with PORTD, when I assign PORTD pins PD4-PD7 as output with pull-ups high,that pins could not high and I cannot connect LED.

Code:
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "buttondebounce.h"

unsigned char n,p;
unsigned int Red=0,Yellow=0,Blue=0;



void DisplayDigits(unsigned int n)
{
unsigned char x[]={~0x3f,~0x06,~0x5b,~0x4f,~0x66,~0x6d,~0x7d,~0x07,~0x7f,~0x67};
unsigned char B,C,D;
unsigned int A;
   
    A=n/100;     //Quotient   251/100==> 2 <==
    B=n%100;     //Remainder  251%100==> 51 X
    C=B/10;      //Quotient    51/10==> 5 <==
    D=B%10;      //Remainder   51%10==> 1 <==
    
    PORTD=1<<PD0;
    PORTB=x[A];
    _delay_ms(8);
	
    PORTD=1<<PD1;
    PORTB=x[C];   
    _delay_ms(8);
    
    PORTD=1<<PD2;
    PORTB=x[D];   	
    _delay_ms(8);

}

unsigned int read_adc(unsigned char adc_input)
{
    ADCSRA  = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1);
	
	// clear the channel bits and set the new channel
    ADMUX =  (ADMUX & 0xF8) | adc_input;
    
    // Delay needed for the stabilization of the ADC input voltage
    _delay_us(10);
    
    // Start the AD conversion
    ADCSRA |= 0x40;
    ADMUX |= 0x40;
    // Wait for the AD conversion to complete
    while (ADCSRA & (1 << ADSC)) 
 
    // return result
    return ADCW;
}



int main( void )
{
    Timer_Init();
    DDRD = 0xf7;   //0b11110111
    PORTD = 0xff;  //0b11111111	
    DDRB = 0xFF;
    PORTB = 0x00;
    DDRC = 0x00;
    PORTC = 0x00;
    n = 0;
    p = 0;
	   
  while(1)
  {                                      
    
      n = get_key_press( 8 );      
      if(n==8)
	  {
	  p++;
	  }
      
	  switch(p)
      {
     
	      case 0:
              PORTD = 1<<PD4;
              Red=read_adc(0);
   	      DisplayDigits(Red);
	      break;
    
	      case 1:
              PORTD = 0<<PD4 | 1<<PD5;
	     Yellow=read_adc(1);
   	      DisplayDigits(Yellow);	     
	      break;

          case 2:
              PORTD = 0<<PD4 | 0<<PD5 | 1<<PD6;
	      Blue=read_adc(2);
   	      DisplayDigits(Blue);	      
	      break;
 
		  
	      default:
              p=0;
	      break;	  
      
             }
      }
 }
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top