100% found this document useful (2 votes)
111 views57 pages

DC Power Monitor With INA209 and Arduino

This document provides an overview of using an Arduino board to measure DC voltage, current, and power. It describes connecting a current shunt and power monitor chip to an Arduino Uno board and displaying the readings on an LCD screen. Background information is also given on Arduino boards and their components.

Uploaded by

jp2udhaya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
100% found this document useful (2 votes)
111 views57 pages

DC Power Monitor With INA209 and Arduino

This document provides an overview of using an Arduino board to measure DC voltage, current, and power. It describes connecting a current shunt and power monitor chip to an Arduino Uno board and displaying the readings on an LCD screen. Background information is also given on Arduino boards and their components.

Uploaded by

jp2udhaya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 57

DC Power Monitor with INA209 and Arduino

You can measure DC Voltage, Current and Power in a voltage range from 0V to 26V. This
circuit use a high-side current shunt and power monitor with an I2C interface INA209 from
Texas Instruments and an Arduino UNO as microcontroller. The values are shown on a 2x16
LCD display. 

Introduction

Arduino is an open-source platform used for building electronics projects.

Arduino consists of both a physical programmable circuit board (often referred

to as a microcontroller) and a piece of software, or IDE (Integrated

Development Environment) that runs on your computer, used to write and

upload computer code to the physical board.

The Arduino platform has become quite popular with people just starting out

with electronics, and for good reason. Unlike most previous programmable

circuit boards, the Arduino does not need a separate piece of hardware (called a

programmer) in order to load new code onto the board – you can simply use a

USB cable. Additionally, the Arduino IDE uses a simplified version of C++,

making it easier to learn to program. Finally, Arduino provides a standard form

factor that breaks out the functions of the micro-controller into a more

accessible package.
This is an Arduino Uno

The Uno is one of the more popular boards in the Arduino family and a great

choice for beginners. We’ll talk about what’s on it and what it can do later in

the tutorial.
This is a screenshot of the Arduino IDE.

Believe it or not, those 10 lines of code are all you need to blink the on-board

LED on your Arduino. The code might not make perfect sense right now, but,

after reading this tutorial and the many more Arduino tutorials waiting for you

on our site, we’ll get you up to speed in no time!

You Will Learn


In this tutorial, we’ll go over the following:

 What projects can be accomplished using an Arduino

 What is on the typical Arduino board and why

 The different varieties of Arduino boards

 Some useful widgets to use with your Arduino

Suggested Reading

Arduino is a great tool for people of all skill levels. However, you will have a

much better time learning along side your Arduino if you understand some basic

fundamental electronics beforehand. We recommend that you have at least a

decent understanding of these concepts before you dive in to the wonderful

world of Arduino.

 What is Electricity?

 Voltage, Current, Resistance, and Ohm’s Law

 What is a Circuit?

 Polarity

 Integrated Circuits (ICs)

 Logic Levels

 Digital Logic

 Analog vs. Digital


What Does it Do?

The Arduino hardware and software was designed for artists, designers,

hobbyists, hackers, newbies, and anyone interested in creating interactive

objects or environments. Arduino can interact with buttons, LEDs, motors,

speakers, GPS units, cameras, the internet, and even your smart-phone or your

TV! This flexibility combined with the fact that the Arduino software is free,

the hardware boards are pretty cheap, and both the software and hardware are

easy to learn has led to a large community of users who have contributed code

and released instructions for a huge variety of Arduino-based projects.

For everything from robots and a heating pad hand warming blanket to honest

fortune-telling machines, and even a Dungeons and Dragons dice-throwing

gauntlet, the Arduino can be used as the brains behind almost any electronics

project.

And that’s really just the tip of the iceberg – if you’re curious about where to

find more examples of Arduino projects in action, here are some good resources

for Arduino-based projects to get your creative juices flowing:

 Instructables

 Bildr

 Arduino Playground

 The ITP Physical Computing Wiki


 LadyAda

 Make: Projects

 and, of course, you can find plenty more Arduino tutorials here at

learn.sparkfun.com.

What's on the board?

There are many varieties of Arduino boards (explained on the next page) that

can be used for different purposes. Some boards look a bit different from the

one below, but most Arduinos have the majority of these components in

common:
Power (USB / Barrel Jack)

Every Arduino board needs a way to be connected to a power source. The

Arduino UNO can be powered from a USB cable coming from your computer

or a wall power supply (like this) that is terminated in a barrel jack. In the

picture above the USB connection is labeled (1) and the barrel jack is labeled

(2).
The USB connection is also how you will load code onto your Arduino board.

More on how to program with Arduino can be found in our Installing and

Programming Arduino tutorial.

NOTE: Do NOT use a power supply greater than 20 Volts as you will

overpower (and thereby destroy) your Arduino. The recommended voltage for

most Arduino models is between 6 and 12 Volts.

Pins (5V, 3.3V, GND, Analog, Digital, PWM, AREF)

The pins on your Arduino are the places where you connect wires to construct a

circuit (probably in conjuction with a breadboard and some wire. They usually

have black plastic ‘headers’ that allow you to just plug a wire right into the

board. The Arduino has several different kinds of pins, each of which is labeled

on the board and used for different functions.

 GND (3): Short for ‘Ground’. There are several GND pins on the

Arduino, any of which can be used to ground your circuit.

 5V (4) & 3.3V (5): As you might guess, the 5V pin supplies 5 volts of

power, and the 3.3V pin supplies 3.3 volts of power. Most of the simple

components used with the Arduino run happily off of 5 or 3.3 volts.

 Analog (6): The area of pins under the ‘Analog In’ label (A0 through A5

on the UNO) are Analog In pins. These pins can read the signal from an
analog sensor (like a temperature sensor) and convert it into a digital

value that we can read.

 Digital (7): Across from the analog pins are the digital pins (0 through 13

on the UNO). These pins can be used for both digital input (like telling if

a button is pushed) and digital output (like powering an LED).

 PWM (8): You may have noticed the tilde (~) next to some of the digital

pins (3, 5, 6, 9, 10, and 11 on the UNO). These pins act as normal digital

pins, but can also be used for something called Pulse-Width Modulation

(PWM). We have a tutorial on PWM, but for now, think of these pins as

being able to simulate analog output (like fading an LED in and out).

 AREF (9): Stands for Analog Reference. Most of the time you can leave

this pin alone. It is sometimes used to set an external reference voltage

(between 0 and 5 Volts) as the upper limit for the analog input pins.

Reset Button

Just like the original Nintendo, the Arduino has a reset button (10). Pushing it

will temporarily connect the reset pin to ground and restart any code that is

loaded on the Arduino. This can be very useful if your code doesn’t repeat, but

you want to test it multiple times. Unlike the original Nintendo however,

blowing on the Arduino doesn’t usually fix any problems.

Power LED Indicator


Just beneath and to the right of the word “UNO” on your circuit board, there’s a

tiny LED next to the word ‘ON’ (11). This LED should light up whenever you

plug your Arduino into a power source. If this light doesn’t turn on, there’s a

good chance something is wrong. Time to re-check your circuit!

TX RX LEDs

TX is short for transmit, RX is short for receive. These markings appear quite a

bit in electronics to indicate the pins responsible for serial communication. In

our case, there are two places on the Arduino UNO where TX and RX appear –

once by digital pins 0 and 1, and a second time next to the TX and RX indicator

LEDs (12). These LEDs will give us some nice visual indications whenever our

Arduino is receiving or transmitting data (like when we’re loading a new

program onto the board).

Main IC

The black thing with all the metal legs is an IC, or Integrated Circuit (13). Think

of it as the brains of our Arduino. The main IC on the Arduino is slightly

different from board type to board type, but is usually from the ATmega line of

IC’s from the ATMEL company. This can be important, as you may need to

know the IC type (along with your board type) before loading up a new program

from the Arduino software. This information can usually be found in writing on
the top side of the IC. If you want to know more about the difference between

various IC’s, reading the datasheets is often a good idea.

Voltage Regulator

The voltage regulator (14) is not actually something you can (or should) interact

with on the Arduino. But it is potentially useful to know that it is there and what

it’s for. The voltage regulator does exactly what it says – it controls the amount

of voltage that is let into the Arduino board. Think of it as a kind of gatekeeper;

it will turn away an extra voltage that might harm the circuit. Of course, it has

its limits, so don’t hook up your Arduino to anything greater than 20 volts.

The Arduino Family

Arduino makes several different boards, each with different capabilities. In

addition, part of being open source hardware means that others can modify and

produce derivatives of Arduino boards that provide even more form factors and

functionality. If you’re not sure which one is right for your project, check this

guide for some helpful hints. Here are a few options that are well-suited to

someone new to the world of Arduino:

Arduino Uno (R3)

The Uno is a great choice for your first Arduino. It’s got everything you need to

get started, and nothing you don’t. It has 14 digital input/output pins (of which 6
can be used as PWM outputs), 6 analog inputs, a USB connection, a power jack,

a reset button and more. It contains everything needed to support the

microcontroller; simply connect it to a computer with a USB cable or power it

with a AC-to-DC adapter or battery to get started.

LilyPad Arduino

This is LilyPad Arduino main board! LilyPad is a wearable e-textile technology

developed by Leah Buechley and cooperatively designed by Leah and

SparkFun. Each LilyPad was creatively designed with large connecting pads

and a flat back to allow them to be sewn into clothing with conductive thread.

The LilyPad also has its own family of input, output, power, and sensor boards

that are also built specifically for e-textiles. They’re even washable!
RedBoard

At SparkFun we use many Arduinos and we’re always looking for the simplest,

most stable one. Each board is a bit different and no one board has everything

we want – so we decided to make our own version that combines all our

favorite features.

The RedBoard can be programmed over a USB Mini-B cable using the Arduino

IDE. It’ll work on Windows 8 without having to change your security settings

(we used signed drivers, unlike the UNO). It’s more stable due to the

USB/FTDI chip we used, plus it’s completely flat on the back, making it easier

to embed in your projects. Just plug in the board, select “Arduino UNO” from
the board menu and you’re ready to upload code. You can power the RedBoard

over USB or through the barrel jack. The on-board power regulator can handle

anything from 7 to 15VDC.

Arduino Mega (R3)

The Arduino Mega is like the UNO’s big brother. It has lots (54!) of digital

input/output pins (14 can be used as PWM outputs), 16 analog inputs, a USB

connection, a power jack, and a reset button. It contains everything needed to

support the microcontroller; simply connect it to a computer with a USB cable

or power it with a AC-to-DC adapter or battery to get started. The large number
of pins make this board very handy for projects that require a bunch of digital

inputs or outputs (like lots of LEDs or buttons).

Arduino Leonardo

The Leonardo is Arduino’s first development board to use one microcontroller

with built-in USB. This means that it can be cheaper and simpler. Also, because

the board is handling USB directly, code libraries are available which allow the

board to emulate a computer keyboard, mouse, and more!


The Extended Family

While your Arduino board sure is pretty, it can’t do a whole lot on its own –

you’ve got to hook it up to something. There are lots of tutorials here on learn

as well as the links back in the ‘What does it do’ section, but rarely do we talk

about the general kinds of things you can easily hook into. In this section we’ll

introduce basic sensors as well as Arduino shields, two of the most handy tools

to use in bringing your projects to life.

Sensors
With some simple code, the Arduino can control and interact with a wide

variety of sensors - things that can measure light, temperature, degree of flex,

pressure, proximity, acceleration, carbon monoxide, radioactivity, humidity,

barometric pressure, you name it, you can sense it!

Just a few of the sensors that are easily compatible with Arduino

Shields
Additionally, there are these things called shields – basically they are pre-built

circuit boards that fit on top of your Arduino and provide additional capabilities

– controlling motors, connecting to the internet, providing cellular or other

wireless communication, controlling an LCD screen, and much more.

Hardware description

All the measurements are made by Texas Instruments INA209, it's a high-side current shunt
and power monitor with an I2C interface. The INA209 monitors both shunt drop and shunt
bus voltage. A programmable calibration value, combined with an internal multiplier, enables
direct readouts in amperes. The INA209 also includes an analog comparator and a
programmable 12 bit digital-to-analog converter (DAC) that combine to provide the fastest
possible responses to current overload conditions. The INA209 senses across shunts on buses
that can vary from 0V to 26V.

INA209 Features

 Senses BUS Voltage from 0V to +26V


 Reports Current, Voltage, Power and stores Peaks
 Triple Watchdog Limit:
o Lower Warning with Delay
o Upper Over-Limit, No Delay
o Fast Analog Critical
 High Accuracy: 1% Max Over Temp

For more details see Texas Instruments INA209 datasheet.

The comunication between INA209 and Arduino occurs through the I2C bus. Arduino
controls all function of INA209 and reads the value measured from the dedicated registers.
You can read the INA209 status or set the configuration parameters.

In this version of firmware I designed only the basic functions for continuos measurements of
instantaneous Voltage, Current and Power but you can control all function of INA209 with
my library as described on page INA209 Arduino Library.
The Voltage, Current and Power values are are shown on a 16x2 LCD display connected to
digital pin of Arduino. LCD display is a standard 16x2 character model YM1602C and is
connected to Arduino digital pins 12, 11, 5, 4, 3, 2. The contrast is regulated by a 10k
trimmer and the backlight is software controlled by Arduino PWM digital output on pin 6.

The figure below shown the block diagram of DC Power MonitorIn this version of firmware I
designed only the basic function for continuos measurements of instantaneous Voltage,
Current and Power but you can control all function of INA209 with my library as described
on page INA209 Arduino Library.

Main circuit diagram


Technical specifications

General features
Averaging results 2 ÷ 128 samples
Voltage Measurement
Digits 5
Full-Scale range 0 ÷ 26 V
Resolution 4mV
Measurement error ± 0.5% max
Measurement error over temperature ± 1% max
Current Measurement
Digits 5
Full-Scale range 0÷6A
Resolution 1mA
Measurement error ± 0.5% max
Measurement error over temperature ± 1% max
Power Measurement
Digits 6
Full-Scale range 0 ÷ 156 W
Resolution 4mW
Measurement error ± 1% max
Measurement error over temperature ± 2% max

Firmware

The most important part of the firmware is the INA209 library I have written and you can see
it on page INA209 Arduino Library. The library is used for control all functions of INA209
through the I2C bus. The measured value are read from INA209 using a simple and intuitive
function call and you don't need to know how I2C works.

/*
  DC Power Monitor by ADPSLAB
  Created 12 Sep. 2012 (Rev. 1.0)
  Copyright (c) 2012 Antonio Dambrosio (
info@adpslab.com).  All rights reserved.
  
  This sketch is for control a Texas Instruments INA209 chip through I2C bu

  and shown on a LCD Display 2x16 character these values:
  Voltage measurement in a range from 0 to +26V with 4mV resolution; 
  Current measurement in a range from 0 to 6A with mA resolution;
  Power measurement with 4mW resolution.
    
  See the schematics on:
  http://www.adpslab.com/en/electronics/arduino/22-dc-power-monitor-with-
ina209-and-arduino  
*/

#include <Wire.h> //I2C library


#include <INA209.h> //INA209 library
#include <LiquidCrystal.h> //LCD library

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the LCD library with


the numbers of the interface pins
#define   BACKLIGHT_PIN  6               // define PIN for PWM Backlight
control
INA209 ina209a(0x40); // creation of an instance of the
INA209 class called ina209a with I2C slave address = 0x40
int intro = 0; // costant value for intro message

void setup() {
  
  analogWrite(BACKLIGHT_PIN, 240);
  lcd.begin(16, 2); // set up the LCD's number of columns and rows
  Serial.begin(9600); // setup serial
  Wire.begin(); // join i2c bus
  
  // ------------- General Configuration ---------
  /* Configuration Register 00h (Read/Write)
     Default settings -> writeCfgReg(14751)
        Bus Voltage Range = 32V
        PGA (Shunt Voltage Only) = +/- 320mV
        BADC Bus ADC Resolution/Averaging = 12bit
        SADC Shunt ADC Resolution/Averaging = 12bit
        Operating Mode = Shunt and Bus, Continuos
  */
  // ina209a.writeCfgReg(14751); // Default settings no averaging
  // ina209a.writeCfgReg(15839); // 8 averaging samples bus and shunt
  ina209a.writeCfgReg(16247); // 64 averaging samples bus and shunt
  
  // -------------- Calibration ------------------
  /* Calibration Register 16h (Read/Write)
    This register sets the current that corresponds to a full-scale drop ac
ross the shunt. 
    Full-scale range and the LSB of the current and power measurement depen
d on the value entered in this register.
    See the Programming the INA209 Power Measurement Engine section of INA2
09 datasheet.         
    In this example:
            Vbus_max = 32V
            Vshunt_max = 0,32V
            Rshunt = 0,05 Ohm
        ->  Max Expected Current = +/- 6A
            Current LSB = 200uA
            Calibration Reg = 4096
            Power LSB = 4mW
            Max Power = 204,8W 
  */
  ina209a.writeCal(4096);
    
  // ---------- WARNING WATCHDOG REGISTERS -------
  /* These registers set warning limits that trigger flags in the Status
Register
     and activate the Warning pin.
  */
  ina209a.writeShuntVolPwrn(30000); // set Shunt Voltage Positive
Warning limit to 30000 (= 300mV)
  ina209a.writeShuntVolNwrn(-500); // set Shunt Voltage Negative
Warning limit to -500 (= -5mV)
  ina209a.writePowerWrn(10000); // set Power Warning limit
  ina209a.writeBusOVwrn(52000); // set Bus Over-Voltage Warning
limit, if you want a limit of 26V you have to set 26000*2 = 52000
  ina209a.writeBusUVwrn(10000); // set Bus Under-Voltage Warning
limit, if you want a limit of 5V you have to set 5000*2 = 10000
  
  // ---------- OVER-LIMIT/CRITICAL WATCHDOG REGISTERS ----------------
  /* These registers set the over-limit and critical DAC limits that
trigger flags to be set in the Status Register
     and activate the Overlimit pin or the Critical pin.
  */
  ina209a.writePowerOL(12000); // set Power Over-Limit
  ina209a.writeBusOVOL(60000); // set Bus Over-Voltage Over-
Limit, if you want a limit of 30V you have to set 30000*2 = 60000 (see the
datasheet for other functions)
  ina209a.writeBusUVOL(6000); // set Bus Under-Voltage Over-
Limit, if you want a limit of 3V you have to set 3000*2 = 6000
  ina209a.writeCrShuntPV(51200); // set Critical DAC+ Register
(Critical Shunt Positive Voltage). No sign bit (sets a positive limit
only). At full-scale range = 255mV; LSB = 1mV; 8-bit.
                                           // if you want a limit of +200mV
you have to set 200*256 = 51200;
                                           // this register control GPIO
PIN, see the datasheet.
  ina209a.writeCrShuntNV(51200); // set Critical DAC– Register
(Critical Shunt Negative Voltage). No sign bit (sets negative limit only).
At full-scale range = –255mV; LSB = 1mV; 8-bit.
                                           // if you want a limit of -200mV
you have to set 200*256 = 51200;
                                           // this register control DAC
Comparator output filter, see the datasheet.
  }
  
  
void loop() {

  if (intro == 0) { // Intro message


      lcd.home ();
      lcd.setCursor(4, 0);
      lcd.print ("ADPSLAB");
      lcd.setCursor(0, 1);
      lcd.print ("DC Power Monitor");
      delay (3000);
      lcd.clear ();
      intro = 1;
  }
  
  lcd.setCursor(0, 0); // set the cursor to (0 at
first line)
  lcd.print (msg2dot3(ina209a.busVol())); // show Voltage measured
  lcd.print (" V");
  lcd.setCursor(8, 0);
  lcd.print (msg2dot3(current_mA(200))); // show Current measured
  lcd.print (" A");
  lcd.setCursor(0, 1);
  lcd.print ("<Power");
  lcd.print (msg3dot3(power_mW(4))); // show Power measured
  lcd.print (" W>");
  lcd.setCursor(7, 1);
 
}

int current_mA (int current_LSB) { // set Current in mA,


current_mA = ina209a.current() * current_LSB (uA) / 1000
    int y = 1000 / current_LSB;
    int x = ina209a.current() / y;
    return x;
}

long power_mW (int power_LSB) { // set Power in mW, power_mW =


ina209a.power() * power_LSB (mW)
    long x = ina209a.power() * power_LSB;
    return x;
}

String msg2dot3 (int xvalue) { // format integer to string 2.3


character
    String strvalue = 0;
    if (xvalue >= 0){
      strvalue = String (xvalue);
      switch (strvalue.length())
      {
       case 1:
        strvalue = String (" .00" + strvalue.substring(0));
        break;
       case 2:
        strvalue = String (" .0" + strvalue.substring(0));
        break;
       case 3:
        strvalue = String (" ." + strvalue.substring(0));
        break;
       case 4:
        strvalue = String (" " + strvalue.substring(0,1) + "." +
strvalue.substring(1));
        break;
       case 5:
        strvalue = String (strvalue.substring(0,2) + "." +
strvalue.substring(2));
        break;
       default:
        strvalue = String ("error");
      }
     } else {
      strvalue = String (abs(xvalue));
      switch (strvalue.length())
      {
       case 1:
        strvalue = String (" -.00" + strvalue.substring(0));
        break;
       case 2:
        strvalue = String (" -.0" + strvalue.substring(0));
        break;
       case 3:
        strvalue = String (" -." + strvalue.substring(0));
        break;
       case 4:
        strvalue = String ("-" + strvalue.substring(0,1) + "." +
strvalue.substring(1));
        break;
       case 5:
        strvalue = String (strvalue.substring(0,2) + "." +
strvalue.substring(2) + "-");
        break;
       default:
        strvalue = String ("error");
      } 
     } 
   return strvalue;
}

String msg3dot3 (long pvalue) { // format long integer to


string 3.3 character
    String strvalue = 0;
    strvalue = String (pvalue);
    switch (strvalue.length())
    {
     case 1:
      strvalue = String (" .00" + strvalue.substring(0));
      break;
     case 2:
      strvalue = String (" .0" + strvalue.substring(0));
      break;
     case 3:
      strvalue = String (" ." + strvalue.substring(0));
      break;
     case 4:
      strvalue = String (" " + strvalue.substring(0,1) + "." +
strvalue.substring(1));
      break;
     case 5:
      strvalue = String (" " +strvalue.substring(0,2) + "." +
strvalue.substring(2));
      break;
     case 6:
      strvalue = String (" " +strvalue.substring(0,3) + "." +
strvalue.substring(3));
      break;
     default:
      strvalue = String ("error");
    }
   return strvalue;
}
There are many display devices used by the hobbyists. LCD displays are one of the most
sophisticated display devices used by them. Once you learn how to interface it, it will be the
easiest and very reliable output device used by you! More, for micro controller based project,
not every time any debugger can be used. So LCD displays can be used to test the outputs.
Obviously, for last possibility, you need to know how to use this stuff pretty well.

Note 1:  We have sub divided this article for easy navigation as shown below:-

1.  Pin Configuration  2. Block Diagram 3. Control and Display Commands  4. LCD
Interfacing  5. LCD Initialization

Note 2: If you are interested in reading about working of LCD – we have an excellent article
for you – Working of Liquid Crystal Displays (LCD)

                Hitachi has set up a mile stone by its LCD controller IC. All the LCD displays use
the same, or any one of the IC s based upon the architecture introduced by Hitachi.

Ok, one minute, all I’m talking about is the character LCD display and not Graphical LCD
Display.

 Most of the LCD Displays available in the market are 16X2 (That means, the LCD displays
are capable of displaying 2 lines each having 16 Characters a), 20X4 LCD Displays (4 lines,
20 characters). It has 14 pins. It uses 8lines for parallel data plus 3 control signals, 2
connections to power, one more for contrast adjustment and two connections for LED back
light. Let us have a look to typical pin configurations:

Pin Configuration table for a 16X2 LCD character display:-


Pin Number Symbol Function
1 Vss Ground Terminal

2 Vcc Positive Supply

3 Vdd Contrast adjustment

4 RS Register Select; 0→Instruction Register, 1→Data Register

5 R/W Read/write Signal; 1→Read, 0→ Write

6 E Enable; Falling edge

7 DB0
8 DB1
Bi-directional data bus, data transfer is performed once, thru DB0 to
9 DB2
10 DB3 DB7, in the case of interface data length is 8-bits; and twice, through
11 DB4 DB4 to DB7 in the case of interface data length is 4-bits. Upper four
12 DB5 bits first then lower four bits.
13 DB6
14 DB7
15 LED-(K) Back light LED cathode terminal

16 LED+(A) Back Light LED anode terminal

Data/Signals/Execution of LCD

Now that was all about the signals and the hardware. Let us come to data, signals and
execution.

LCD accepts two types of signals, one is data, and another is control. These signals are
recognized by the LCD module from status of the RS pin. Now data can be read also from the
LCD display, by pulling the R/W pin high. As soon as the E pin is pulsed, LCD display reads
data at the falling edge of the pulse and executes it, same for the case of transmission.

                LCD display takes a time of 39-43µS to place a character or execute a command.
Except for clearing display and to seek cursor to home position it takes 1.53ms to 1.64ms.
Any attempt to send any data before this interval may lead to failure to read data or execution
of the current data in some devices. Some devices compensate the speed by storing the
incoming data to some temporary registers.

                LCD displays have two RAMs, naming DDRAM and CGRAM. DDRAM registers
in which position which character in the ASCII chart would be displayed. Each byte of
DDRAM represents each unique position on the LCD display. The LCD controller reads the
information from the DDRAM and displays it on the LCD screen. CGRAM allows user to
define their custom characters. For that purpose, address space for first 16 ASCII characters
are reserved for users. After CGRAM has been setup to display characters, user can easily
display their custom characters on the LCD screen.
Images of LCD Display:-

LCD - Front View


LCD - Back View

Block Diagram of LCD Display:-


LCD - Block Diagram

Control and display commands


Instruction Instruction Code Instruction Code Execution
Description time

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


Read Data Read data from
1.53-
From RAM 1 1 D7 D6 D5 D4 D3 D2 D1 D0 internal RAM
1.64ms
Write data into
Write data to
1.53-
RAM 1 0 D7 D6 D5 D4 D3 D2 D1 D0 internal RAM
(DDRAM/CGRAM) 1.64ms

Busy flag (BF: 1→ LCD


Busy flag & Busy) and contents of
Address 0 1 BF AC6 AC5 AC4 AC3 AC2 AC1 AC0 address counter in 39 µs
bits AC6-AC0.

Set DDRAM Set DDRAM address


Address 0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0 in address counter. 39 µs

Set CGRAM Set CGRAM Address


Address 0 0 0 1 AC5 AC4 AC3 AC2 AC1 AC0 in address counter. 39 µs

Set interface data


length (DL: 4bit/8bit),
Numbers of display
Function Set 0 0 0 0 1 DL N F X X line (N: 1-line/2-line) 39 µs
display font type
(F:0→ 5×8 dots, F:1→
5×11 dots)

Set cursor moving


and display shift
Cursor or control bit, and the
Display Shift 0 0 0 0 0 1 S/C R/L X X direction without 39 µs
changing DDRAM
data

Set
Display & Display(D),Cursor(C)
Cursor On/Off 0 0 0 0 0 0 1 D C B and cursor blink(b) 39 µs
on/off control

Entry Mode Set 0 0 0 0 0 0 0 1 I/D SH Assign cursor moving 0µs


direction and enable
shift entire display.

Set DDRAM Address


to “00H” from AC and
Return Home 0 0 0 0 0 0 0 0 1 X return cursor to its 43µs
original position if
shifted.

Write “20H” to
DDRAM and set
Clear Display 0 0 0 0 0 0 0 0 0 1 43µs
DDRAM Address to
“00H” from AC

AC -Address Counter

Outline

Now the instruction can be divided mainly in four kinds

1)      Function set instructions

2)      Address set instructions

3)      Data transfer instructions with internal RAM

4)      Others

Details of the Instructions

1)      Read Data from RAM

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


1 1 D7 D6 D5 D4 D3 D2 D1 D0

Read 8bit binary data from DDRAM/CGRAM

The selection of RAM is set by the previous address set instruction. If the address set
instruction of RAM is not performed before this instruction, the data that is read first is
invalid, because the direction of AC is not determined. If the RAM data is read several times
without RAM address set instruction before read operation, the correct RAM data from the
second, but the first data would be incorrect, as there is no time to transfer RAM data. In case
of DDRAM read operation, cursor shift instruction plays the same role as DDRAM address
set instruction; it also transfers RAM data to the output data registers.
After read operation, the data address counter is automatically increased or decreased by 1
according to the entry mode. After CGRAM read operation, display shift may not be
executed properly.

*In case of RAM write operation, AC is increased or decreased by 1 like that of the read
operation. In this time AC indicates the next address position, but the previous data can only
by the read instruction.

2)      Write data to ram

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


1 0 D7 D6 D5 D4 D3 D2 D1 D0

Write binary 8bit data to DDRAM/CGRAM. The selection of CGRAM or DRAM is set by
the previous address set instruction; DDRAM address set, CGRAM address set. RAM set
instruction can also determine the AC direction to RAM.

After write operation, the address is automatically increased or decreased by 1 according to


the entry mode.

3)      Read Busy Flag and Address

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 1 BF AC6 AC5 AC4 AC3 AC2 AC1 AC0

By making this read out operation, it can be determined if the LCD is performing some
internal operation or not. If Busy Flag (BF) is high, some internal operation is going inside
the LCD at that particular moment. To perform further operation the data source (e.g. micro
controller) must wait for the BF to go low. Here, the address counter value can also be read.

4)      Set DDRAM Address

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0

Set DDRAM address to AC, this instruction makes DDRAM data available from MPU. In 1-
line display mode, DDRAM address rangers from “00H” to “4FH”. In 2-line display mode,
DDRAM address in the first line ranges from “00H” to “27H”, and DDRAM address in the
2nd line is from “40H” to “67H”.

5)      Set CGRAM address

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 1 AC5 AC4 AC3 AC2 AC1 AC0

Set CGRAM address to AC. This instruction makes CGRAM data available from MPU.

6)      Function Set


RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0 0 0 0 1 DL N F X X

DL: Interface data length control bit

DL=’1’ means 8bit mode of data transfer.

DL=’0’ means 4bit mode of data transfer

When 4 bit mode is activated, the data needs to be transferred in two parts, first higher 4bits,
and then lower 4 bits.

N: display line number control bit

N=’1’ will allows to characters to display in 2-lines

N=’0’ will allows to characters to display in the first line only

F: display font control bit

F=’0’ will use 5×8 dots format display mode

F=’1’ will use 5×11 dots format display mode

7)      Cursor or display Shift

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 0 0 1 S/C R/L X X

Without writing or reading the display data, shifting right/left cursor position or display.

This instruction is made to correct or search or display data. During 2-line display mode,
cursor moves to the 2nd line after the 40th digit of the 1st line.

When displayed data is shifted repeatedly, each line shifts individually.

When display shift is performed, the contents of the address counter are not changed.

8)      Display On/Off Control

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 0 0 0 1 D C B

This instruction controls Display, Cursor and cursor blink.

D: Display On/Off control bit

D=’1’ means entire display is turned on


D=’0’ means entire display is turned off. But Display data remains in DDRAM.

C: cursor On/Off control bit

C=’1’ turns on the cursor

C=’0’ turns off the cursor. But I/D register retains the data

B: Cursor blink On/Off control bit

B=’1’ makes cursor blink periodically.

B=’0’ stops the cursor to blink and cursor looks steady if the Cursor is turned on.

9)      Entry Mode Set

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 0 0 0 0 1 I/D SH

This instruction sets the moving direction of cursor and display.

When I/D= ’1’ cursor moves to the right and DDRAM address is increased by 1.

When I/D= ’0’ cursor moves to the left and DDRAM address is decreased by 1.

CGRAM operates in the same way in this setting.

10)   Return Home

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 0 0 0 0 0 1 X

This instruction sets the address counter to ‘00H’, and returns the cursor to the first column of
first line. And if display is shifted previously, this instruction shifts this too. The DDRAM
contents don’t change in this instruction.

11)   Clear display

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0


0 0 0 0 0 0 0 0 0 1

Clear all the display data by writing “20H” (ASCII code of ‘space’ character) to all DDRAM
address, AND set value DDRAM address counter (AC) to “00H”. It returns the cursor to the
first column of first line and sets the entry mode to increment mode (I/D=’1’).
8-bit and 4-bit interfacing of LCD

Now the question is how to display data in the LCD or give command to it. There is two
modes of data transfer are supported by LCD displays. One is 4bit mode, another is 8 bit
mode. To transfer data In 8 bit mode, first put your data in the 8bit bus, then put command in
the command bus and then pulse the enable signal.

                To send data in 4bit mode; first put upper 4bit in the 4 bit data bus connected to
4MSB pins of LCD display, then put control signals in the control bus, then pulse the E pin
once. Next put the lower 4 bit in the data bus and pulse the E pin again. Here is a flowchart
simply describing it.

LCD Display Interfacing – Flowchart:-

LCD Interfacing - Flowchart

LCD Initialisation

We are pretty familiar how to send data. But before displaying characters on the LCD
display, it must be configured first. To configure an LCD display, four command words must
be sent to LCD in either 4 bit mode, or in 8 bit mode. The commands are:

1. Function set

2. Display On/Off control


3. Entry mode set

4. Display Clear

Here is a flow chart of the initialization sequence of LCD display.

LCD Initialization

Displaying Custom Characters

All these character display modules got the feature to create 8 user defined characters (ASCII
Codes 0…7) in addition to the ROM fixed codes.

1.) The command “CG RAM Address Set” defines the ASCII code (Bit 3, 4, 5) and the dot
line (Bit 0, 1, 2) of the new character. Example demonstrates creating ASCII code “00H”.

2.) Doing 8 times the write command “Data Write” defines line by line the new character. 8th
byte stands for the cursor line.

3.) The new defined character can be used as a “normal” ASCII code (0…7); use with “DD
RAM Address Set” and “Data Write”.
Now let us look up the character set that can be displayed using the LCD Displayed

0×00 0×10 0×20 0×30 0×40 0×50 0×60 0×70 0×80 to 0xd0 0xE 0xF
0 0

0×00 CG1 0 @ P ` p CUSTOM


REGIONAL Α
0×01 CG2 ! 1 A Q a q CHARACHTER
S Ä
0×02 CG3 “ 2 B R b r
Β θ
0×03 CG4 # 3 C S c s
Ε
0×04 CG5 $ 4 D T d t
Μ Ω
0×05 CG6 % 5 E U e u
Σ ϋ
0×06 CG7 & 6 F V f v
Ρ Σ
0×07 CG8 7 G W g w
G π
0×08 CG1 ( 8 H X h x

0×09 CG2 ) 9 I Y i y
¯¹ y
0x0A CG3 * : J Z j z
J
0x0B CG4 + ; K [ k {

0x0C CG5 , < L ¥ l |

0x0D CG6 - = M ] m }

0x0E CG7 . > N ^ n →


0x0F CG8 / ? O _ o ←

CG→ CGRAM User Defined Character

Custom Regional characters vary from manufacturer to manufacturer. The Greek letters may
or may not appear. It too depends upon the design.
Recommended alternative parts
 INA219  -  Smaller package in SOT23, and does not include watchdog features.

Description
The INA209 is a high-side current shunt and power monitor with an I2C interface. The
INA209 monitors both shunt drop and shunt bus voltage. A programmable calibration value,
combined with an internal multiplier, enables direct readouts in amperes. An additional
multiplying register calculates power in watts. The INA209 features two separate, onboard
watchdog capabilities: a warning comparator and an over-limit comparator. The warning
comparator is useful for monitoring lower warning limits and incorporates a user-defined
delay. The over-limit comparator assists with monitoring upper limits that could require
immediate system shutdown.

The INA209 also includes an analog comparator and a programmable digital-to-analog


converter (DAC) that combine to provide the fastest possible responses to current overload
conditions.

The INA209 can be used together with hot swap controllers that already use a current sense
resistor. The INA209 full-scale range can be selected to be either within the hot-swap
controller sense limits, or wide enough to include them.
The INA209 senses across shunts on buses that can vary from 0V to 26V. The device uses a
single +3V to +5.5V supply, drawing a maximum of 1.5mA of supply current. It is specified
for operation from -25°C to +85°C.

Features
 SENSES BUS VOLTAGES FROM 0V TO +26V
 REPORTS CURRENT, VOLTAGE, AND POWER; STORES PEAKS
 TRIPLE WATCHDOG LIMITS:
o Lower Warning with Delay
o Upper Over-limit, No Delay
o Fast Analog Critical
 HIGH ACCURACY: 1% MAX OVER TEMP
 APPLICATIONS
o SERVERS
o TELECOM EQUIPMENT
o AUTOMOTIVE
o POWER MANAGEMENT
o BATTERY CHARGERS
o WELDING EQUIPMENT
o POWER SUPPLIES
o TEST EQUIPMEN
Dc power supply

The most common and inexpensive plugpack power supply type you'll see is the chunky transformer
based plug. Whenever you buy some consumer electronics you'll be getting one of these:
These guys are everywhere - all sorts of voltage and current ratings. They're available for
sale at any store just about, but there are some big things to watch out for! One is that the
output voltage is not going to be 9V (for example) out of the box, that voltage rating is just
the minimum output for the current rating (200mA for example). And also, the output is
going to have a lot of ripple on it!

Before we talk precisely about these guys, lets go back in time to when engineers had to build
their power supplies with their bare hands!

The good old days!


Back a couple decades ago, the only way to build a power supply was to start a big chunky
120VAC/12VAC transformer. The transformer was used to bring the high voltage from the wall down
to a less dangerous level. Then diodes and capacitors were used to turn the AC into DC.

Transformers
We aren't going to get into the heavy detail of the electromagnetic theory behind transformers
except to say that they are made of two coils of wire around a chunk of iron. If the number of coils
are the same on both sides then the AC voltage is the same on both sides. If one side has twice the
coils, it has twice the voltage. They can be used 'backwards' or 'forwards'! For more detailed
information, be sure to check out the wikipedia page.
To use it, one half would get wired up to the wall (the 'primary' 'high side')

and the other half would output 12V AC (the 'secondary' 'low side'). The transformer
functioned in two ways: one it took the dangerous high voltage and transformed it to a much
safer low voltage, second itisolated the two sides. That made it even safer because there was
no way for the hot line to show up in your electronics and possibly electrocute you.

We'll use a schematic symbol to indicate a transformer, its two coils inside which are drawn
out, the schematic symbol will have the same number of coils on either side so use common
sense and any schematic indicators to help you out in figuring which is primary and which is
secondary!
Half wave rectification
Now that the voltage is at a non-electrocutey level of around 12VAC it can be converted into DC. The
easiest and cheapest way to convert (also called rectify) AC to DC is to use a single diode. A diode is
a simple electronic 'valve' - it only lets current flow one way. Since AC voltage cycles from positive to
negative and we only want positive, we can connect it up so that the circuit only receives
the positive halfof the AC cycle.

You'll want to use a power diode such as a 1N4001 , they're extremely common and can put up with
a lot of abuse. The side with the silver stripe matches the schematic symbol side that the 'arrow' in
the diode symbol is pointing to. That's the only direction that current can flow. The output is then
chopped in half so that the voltage only goes positive.
This will convert

into
What we have now isnt really AC and isn't really DC, its this lumpy wave. The good news is
that it's only positive voltage'd now, which means its safe to put a capacitor on it.

This is a 2200 microFarad (0.0022 Farad) capacitor, one leg has (-) signs next to it, this is the
negative side. The other side is positive, and there should never be a voltage across is so that
the negative pin is 'higher' than the positive pin or it'll go POOF!
A capacitor smooths the voltage out, taking out the lumps, sort of how spring shocks in car or
mountain bike reduce the bumpiness of the road. Capacitors are great at this, but the big capacitors
that are good at this (electrolytic) can't stand negative voltages - they'll explode!

Because the voltage is very uneven (big ripples), we need a really big electrolytic-type
capacitor. How big? Well, there's a lot of math behind it which you can read about but the
rough formula you'll want to keep in mind is:

Ripple voltage = Current draw / ( (Ripple frequency) * (Capacitor size) )


or written another way

Capacitor size = Current draw / ( (Ripple frequency) * (Ripple Voltage) )

For a half wave rectifier (single diode) the frequency is 60 Hz (or 50 Hz in europe). The
current draw is how much current your project is going to need, maximum. The ripple
voltage is how much rippling there will be in the output which you are willing to live with
and the capacitor size is in Farads.

So lets say we have a current draw of 50 mA and a maximum ripple voltage of 10mV we are
willing to live with. For a half wave rectifier, the capacitor should be at least = 0.05 / (60 *
0.01) = 0.085 Farads = 85,000 uF! This is a massive and expensive capacitor. For that
reason, its rare to see ripple voltages as low as 10mV. Its more common to see maybe 100mV
of ripple and then some other technique to reduce the ripple, such as a linear regulator chip.

You don't have to memorize that formula, but you should keep the following in mind: When
the current goes up and the capacitor stays the same, the ripple goes up. If the current goes
up and you want the ripple the same, the capacitor must also increase.

Full wave rectifiers


One thing that can be done to reduce the ripple/capacitor size by half is to use a full wave rectifier
instead of a half wave. A full wave rectifier uses 4 diodes arranged in a peculiar way so that it both
lets the positive voltage through and manages to 'flip over' the negative voltages into positive.

So now we get:
As you can see, there are twice as many humps - there isnt that "half the time, no voltage" thing
going on. This means we can divide the calculated capacitor size to half of what it was in the
previous.

Basically, a full wave rectifier is way better than a half wave! So why even talk about half-wave type
rectifiers? Well, because they're useful for a few other purposes. In general, you're unlikely to see an
AC/DC converter that uses a half wave as the cost of the diodes makes up for the saving in capacitor
size and cost!
The transformer AC/DC in practice

OK now that we've reviewed transformers, diodes when used as rectifiers and big capacitors, lets
look at a chunky plugpack again. This time, we'll look inside by cutting it in half! This power supply is
rated at9VDC @ 200mA.
We can pull it out completely to see the circuit board parts.

Wow so this looks really familiar, right? From let to right, you can see the wires that come
into the transformer from the wall plug, the transformer output has two power diodes on it
and a big capacitor (2,200uF). You might be a little puzzled at the two diodes - shouldn't
there be four for a full-wave rectifier? It turns out that if you have a special transformer made
with a 'center tap' (a wire that goes to the center) you can get away with using only two
diodes . So it really is a full wave rectifier, just one with a center-tap transformer.

These transformer-based plug-packs are really cheap to make - like on the order of under $1!

Testing the 9V supply


So now we will take a fresh power supply (don't use one you sawed in half, of course) and measure
the output voltage with a multimeter.

Yow! 14V? That's not anything like the 9V on the package, is this a broken wall wart? No! Its totally
normal! Transformer-based wall adapters are not designed to have precision outputs. For one thing,
the transformer, if you remember, is made of coils of wire. The coils for the most part act like
inductors but they still have some small resistance. For example, if the coil is 10 ohms of resistance,
then 200 mA of current will cause V = I * R = (0.2 Amps) * (10 ohms) = 2 Volts to be lost just in the
copper winding! Another thing that causes losses is the metal core of the transformer becomes less
efficient as the amount of current being transformed increases. Altogether, there are many
inefficiencies that will make the output fluctuate. In general, the output can be as high as twice the
'rated' voltage when there is less than 10mA of current being drawn.

Let's look in detail


Lets look on an oscilloscope, that way we can see in detail what is going on.
With no current being drawn on the supply, the voltage output is about 14V
When I connected a 100 ohm resistor (110 mA draw) from the positive pin to the negative pin, it
dropped to 11.2V
Connecting a 60 ohm resistor (~160 mA draw), it goes down to 10.3V
With 35 ohms (230 mA draw) the voltage plummets to 7.7V!

As the resistance gets smaller and smaller, the current draw gets higher and higher and the
voltage droops (that's the technical term for it!) You can also see the ripple increase as the
current goes up.

Now we can at least understand the thinking behind saying "9V 200mA" on the label. As
long as we are drawing less than 200mA the voltage will be higher than 9V.

You might also like