Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to interface serial ADC0831 with AVR microcontroller (ATmega16)- (Part 27/46)

By Ashutosh Bhatt February 6, 2011

ADC is an electronics device that converts the analog signals to digital number proportional to the magnitude of voltage. The ADC chips like ADC0804, ADC0809 etc., give 8-bit digital output. The controller device needs eight pins to receive the 8-bit data (For more details about ADC refer to Using Inbuilt ADC of AVR). Some applications need higher resolution ADCs, (10 or higher bits digital data output) for data accuracy.  
 
Using parallel ADCs is one option for such applications. However using parallel ADC will increase the size of the hardware as a 10-bit parallel ADC will have 10 output lines. Also you might have to use controller with higher number of pins. The other option is to use serial ADC, which needs smaller number of pins. Since the data is transmitted serially, the data transfer rate of the serial ADC is low as compared to parallel ADC. They can serve as a very good alternative in applications where speed of data transfer in not a critical point. This article explores interfacing of serial ADC0831 with ATmega16.

 


 

The ADC0831 is an 8 pin, single channel serial ADC which gives 8-bit data output. The input can be either single ended or differential type. Using the differential input option, A/D conversion can be performed for two different voltage levels. The function of each pin is described in the following table:

Pin Name and Fuctions of serialADC0831

Fig. 2: Pin Name and Fuctions of serialADC0831
1.  (Chip Select) – In order to initiate conversion a high-to-low is provided on.
2. Vin (+) (Positive Analog Input) – Positive voltage is applied at this pin. The input range for this is 0 to 5votls.
3. Vin (-) (Negative Analog input) – Negative voltage is applied at this pin.
4. GND (Ground) – This pin is connected to the ground of circuit.
5. Vref (Reference Voltage) – This pin is used to set the input voltage range of ADC.
6. CLK (Clock) – Clock pulse is provided on CLK pin for synchronization.
7. DO (Data Output) – This pin is an output pin of ADC, serial output data is available on this pin.
8. Vcc (Power Supply) – This is connected to +5 volt power supply.  
 
How serial ADC works:
Block Diagram of Serial ADC Working with AVR
Fig. 3: Block Diagram of Serial ADC Working with AVR
The above diagram shows a system in which the ADC device receives analog data from transducer. The controller is used to control ADC IC and to process the converted digital data. The analog signal is given at pin Vin(+). In differential mode, voltage at pin Vin(+) must be greater than Vin(-) otherwise output data will not be generated by the ADC. The data conversion is started by giving high to low pulse at the CS pin. At the first clock cycle, the ADC sends ‘0’ bit to the controller which shows the following bits  are the data bits. The MSB of converted data is sent first. The timing diagram of ADC0831 is shown below.
Timing Diagram of ADC0831 for serial communication in AVR
Fig. 4: Timing Diagram of ADC0831 for serial communication in AVR
Objective: To convert analog output voltage of variable resistor into digital signals using ADC0831 and display it on LCD.
 
Circuit description:
The connection of ADC0831 with ATmega16 is shown in the circuit diagram. The output of variable resistor is connected to Vin(+) and Vin(-) pin is grounded. The Pins CS, CLK and DO of ADC are connected to microcontroller.
 
Programming steps:
1. Send a high to low pulse to CS pin to initialize conversion.
2. Monitor the status of D0 bit until it goes low.
3. Send a clock pulse.
4. Receive the data bits from DO pin of ADC 0831.
5. Store the data bits in a variable by using bitwise operation.
6. When the data byte is received from serial ADC, display it on LCD. 

Project Source Code

###


// Program to interface serial ADC 0831 with AVR microcontroller (ATMEGA 16)
#include
#include
#include
 
#define DO PD2
#define CLK PD1
#define CS PD0
 
#define lcdport PORTA
#define rs PB0
#define rw PB1
#define en PB2
 
void lcd_init(void);
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void adc_conversion(unsigned char);
void twi_init();
unsigned char adc_read();
 
int main()
{
unsigned char data[12]= "ADC OUTPUT:";
 
int i=0;
unsigned char bits=0;
 
DDRA=0xFF;
DDRB=0x07;
DDRD=~_BV(DO); //DO pin is input pin and rest of the pins are output pins
DDRC=0xFF;
PORTD=0x07;
 
 
lcd_init();
while(data[i]!='�')
{
lcddata(data[i]);
_delay_ms(5);
i++;
}
 
while(1)
{
PORTD|=(1< // high-to-low pulse is provided to CS pin
_delay_ms(1);
PORTD&=~(1<
_delay_ms(1);
 
while(PIND & _BV(DO)) // wait until 0 bit is received
{
PORTD|=(1<
_delay_ms(1);
PORTD&=~(1<
_delay_ms(1);
}
 
PORTD|=(1< // a clock pusle is provided
_delay_ms(1);
PORTD&=~(1<
_delay_ms(1);
 
for(i=0;i<8;i++)
{
PORTD|=(1< // data receive when pulse is high
_delay_ms(1);
bits=bits<<1; //"bits" is variable to store data.left shift operation is perform to make place for upcoming bit
 
if(bit_is_set(PIND,DO)) // if 1 is received 
bits |=1; // bits is increment by 1
 
PORTD&=~(1< // pulse low
_delay_ms(1);
}
 
adc_conversion(bits); //
}
 
 
}
 
/* this function is written to convert interger value to their corresponding ASCII value*/
 
void adc_conversion(unsigned char adc_out)  
{
unsigned int adc_out1;
int i=0;
char position=0xC2;
 
for(i=0;i<=2;i++)
{
adc_out1=adc_out%10;
adc_out=adc_out/10;
lcdcmd(position);
lcddata(48+adc_out1);
position--;
}
}
 
void lcd_init() // fuction for LCD initialization
{
lcdcmd(0x38);
lcdcmd(0x0C);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);
}
 
void lcdcmd(unsigned char cmdout)
{
lcdport=cmdout;
PORTB=(0<
_delay_ms(10);
PORTB=(0<
}
 
 
void lcddata(unsigned char dataout)
{
lcdport=dataout;
PORTB=(1<
_delay_ms(10);
PORTB=(1<
}
 

###

 


Circuit Diagrams

CIrcuit-Diagram-of-How-to-interface-serial-ADC0831-with-AVR-microcontroller-ATmega16

Project Components

  • ATmega16
  • LCD

Project Video


Filed Under: ARM, AVR, Electronic Projects
Tagged With: adc, atmega16, avr, microcontroller
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Voltage mode pushpull is a nonsense SMPS?
  • Input impedance matching network
  • High Side current sensing
  • The comparison of different Tcl script checkers
  • Reducing "shoot-through" in offline Full Bridge SMPS?

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

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

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe