EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Please help me with code for using in built adc of atmega32. Its urgent.

Please help me with code for using in built adc of atmega32. Its urgent.

|

Microcontroller › AVR › Please help me with code for using in built adc of atmega32. Its urgent.

  • This topic has 1 reply, 2 voices, and was last updated 12 years, 4 months ago by AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • February 9, 2013 at 7:38 pm #2106
    techspark
    Participant

    the program is not running properly I tried it in proteus and used winavr.
    the code takes the analog value from port a and gives the output to port b.
    code as follows:

    #include<avr/io.h>
    #include<util/delay.h>

    void ADC_init(void);
    unsigned int ADC_read(unsigned char);

    //



    int main(void)
    {
    unsigned int value;
    DDRB=0xFF;
    DDRA=0x00;
    ADC_init(); // Initialization of ADC
    // ch=0;
    while(1)
    {
    value=ADC_read(0);
    PORTB=value;
    _delay_us(500);
    }
    }
    //


    void ADC_init(void) // Initialization of ADC
    {
    ADMUX=(1<<REFS0)|(1 << ADLAR); // AVcc with external capacitor at AREF
    ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
    SFIOR=(1<<PUD); // Enable ADC and set Prescaler division factor as 128 & also disabling the pull ups
    }

    unsigned int ADC_read(unsigned char ch)
    {
    ch= ch & 0b00000111; // channel must be b/w 0 to 7
    ADMUX |= ch; // selecting channel
    ADCSRA|=(1<<ADSC)| (1 << ADEN); // start conversion
    while(!(ADCSRA & (1<<ADIF))); // waiting for ADIF, conversion complete
    ADCSRA|=(1<<ADIF); // clearing of ADIF, it is done by writing 1 to it

    return (ADC);
    }

    February 11, 2013 at 4:49 pm #9118
    AJISH ALFRED
    Participant

    Please try it on real hardware and update the result.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Raise your hand if your car had one of these: July 8, 2025
  • Tektronix 2235 channel 1 trace unstable July 8, 2025
  • How to make string LEDs? July 8, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz July 8, 2025
  • The Analog Gods Hate Me July 8, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise