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.

[SOLVED] ADSC not rest in avr32 (adc read problem

Status
Not open for further replies.

thannara123

Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,580
Helped
122
Reputation
244
Reaction score
114
Trophy points
1,353
Location
India
Activity points
10,376
I am trying to read ADC in atmeg 32 .Displaying the data to lcd to a vlot /ammeter project .
my problem whenever simulate it on proteus it will hangup on the checking of ADSC conversion

Code:
/*
 * vmam.c
 *
 * Created: 14-Oct-15 6:44:15 PM
 *  Author: Krishna
 */ 
#define F_CPU 16000000UL
#include <avr/io.h>
#include<util/delay.h>
#include"lcd.h"


int main(void)
{
   DDRD = 0xFF;
   int adc_value=0x00;
   char ch_sec =0;
   void adc_init();
   lcd_init();
   string("ADC Reading ");
   
   adc_value = read_adc(0);  // reading adc value
   LINE2
  lcd_data(adc_value+0x30);
   while(1);
}


adc.h file

Code:
/*
 * adc.c
 *
 * Created: 14-Oct-15 7:39:18 PM
 *  Author: Krishna
 */ 
#include <avr/io.h>
#define F_CPU 16000000UL
#include<util/delay.h>


void adc_init()
{
ADMUX |= (REFS0); // AVcc with external capacitor at AREF
 // Set the ADC prescaler to 128 (i.e., 16MHz/128 = 125KHz)
 ADCSRA |= ( 1 << ADPS2 )|( 1 << ADPS1 ) | ( 1 << ADPS0 );
 ADCSRA |= ( 1 << ADEN ); // ADC ON    
 ADCSRA |= (1<<ADSC); 
}


unsigned int read_adc(unsigned int ch_selection)
{
    ch_selection &= 0b00000111;  // AND operation with 7
    ADMUX = (ADMUX & 0xF8)|ch_selection; // clears the bottom 3 bits before ORing
     ADCSRA |= (1<<ADSC);                //Starts a new conversion
     while(ADCSRA & (1<<ADSC));            //Wait until the conversion is done
     return ADCW;
}

the avr studio whole file and proteus simulation file attaching here
https://www.edaboard.com/attachment.php?attachmentid=122356&stc=1&d=1444875677

 

Attachments

  • voltmeter & ammetter.rar
    38.6 KB · Views: 122


Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top