Direct analog


Published on

direct analog with code

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Direct analog

  1. 1. Direct Analog-To-Microcontroller InterfacingThis paper will demonstrate how signals from analog sensors can be directly interfaced to anydigitalembedded system even though they may not be equipped with an on-chip ADC (Analog-to-Digital Converter),comparator or OP amp (Operational Amplifier). With only two resistorsand one capacitor, we willpresent a solution that allows analog voltages to be measured directlyusing only a few digital I/O-pins.The digital target system requirements are minimized andlimited to only two digital I/O-pins (with tristatecapability). No ADC, comparators, timers orcapture modules are necessary. The extremely modesthardware requirements make it a suitablesolution also for CPLDs/FPGAs (Complex Programmable Logicdevices/Field ProgrammableGate Arrays). Since this solution will allow even the simplest embeddedsystem to be interfacedto analog voltage sensors, it has the potential of reducing design costs considerably.The proposeddesign is for DC or low-frequency signals and compared to other similar solution, thisdesignneeds no embedded analog blocks at all.The techniques of interfacing analog sensors directly to digitalembedded systems without the useof embedded ADCs or complexsignal conditioning electronics was developed in the mid-1990s.These techniques may be divided into two categories. One class ofinterfaces focused onpassive sensors (i.e. resistive, capacitive andbridge sensors). Pioneering work was presented byCox,Richey, Baker and Bierl. The other class is focused on sensors with analog voltageoutputsand Peter et al. that these sensors couldbe interfaced without using the embedded SARADC (SuccessiveApproximation Register) of a typical microcontroller. If only thecontroller hasan embedded comparator, a Sigma Delta can be implemented with only a few passivecomponents. Thishas later been confirmed and demonstrated by several, both inmicrocontrollersand in FPGAs (with embedded or externalcomparators). The analog-to-digital conversion is amulti-step process. This is controlled in firmware by polling the comparator’s output. If thecomparator’s output is high the I/O-pin is reset and if it is low the I/O-pin is set.It is slow(limited bandwidth) and most of all, it only works for embedded systems with integratedcomparators, which indicates that it requires a relatively advanced (expensive) micro-controllerand excludes inherently digital systems such as CPLDs and FPGAs. The solution presented inthis work, uses only two I/O-pins but has the advantage of not requiring a comparator; thetechnique can be implemented also in FPGAs.Block Diagram
  2. 2. //in this i am using adc0808 for selecting adc channel & 8 bitdata pin for lcd data selection bit#include <reg51.h>#include "lcd.h"sbit ADD_A = P2^0;sbit ADD_B = P2^1;sbit ADD_C = P2^2;sbit clk= P2^3; //for clocksbit ALE = P2^4; //adress latch enablesbit OE = P2^5; //output enablesbit SC = P2^6; //start convertionsbit EOC = P2^7; //end convertion
  3. 3. sfr input=0x80; //0x80 is the adress of port 0 of 8051,it act as a sensor o/p & microcontroller i/p//function prototypevoid channel_selection(unsigned char channel);unsigned char read_adc(unsigned char channel_area);void sensor_display(unsigned char var);void timer0() interrupt 1 // Function to generate clock of frequency 500KHZ using Timer 0 interrupt.{clk=~clk;}void channel_selection(unsigned char channel){ if(channel==0) { ADD_C=0; ADD_B=0;ADD_A=0; } else if(channel==1) { ADD_C=0; ADD_B=0;ADD_A=1;
  4. 4. }else if(channel==2){ ADD_C=0; ADD_B=1;ADD_A=0;}else if(channel==3){ ADD_C=0; ADD_B=1;ADD_A=1;}else if(channel==4){ ADD_C=1; ADD_B=0;ADD_A=0;}else if(channel==5){ ADD_C=1; ADD_B=0;ADD_A=1;}else if(channel==6){ ADD_C=1; ADD_B=1;ADD_A=0;}else{ ADD_C=1; ADD_B=1;ADD_A=1;}
  5. 5. }unsigned char read_adc(unsigned char channel_area) { unsigned char ch=0; channel_selection(channel_area); EOC=1; //end of convertion high OE=0; //output enable low ALE=0; //adress latch enable low delay(2); ALE = 1; //ALE high delay(2); SC=0; //start convertion pin low delay(2); SC = 1; //start convertion pin high delay(2); ALE = 0; //adress latch enable low delay(2); SC = 0; //start convertion pin low while(EOC==1); //wait for EOC pin is high OE = 1; delay(2); ch=input; OE = 0; return (ch);
  6. 6. }void sensor_display(unsigned char var){ if(var<10) { lcd_data(var+0); lcd_data( ); lcd_data( ); } else if((var>=10)&& (var<100)) { lcd_data((var/10)+0); lcd_data((var%10)+0); lcd_data( ); lcd_data( ); } else if(var>=100) { lcd_data((var/100)+0); lcd_data(((var/10)%10)+0); lcd_data((var%10)+0); }}
  7. 7. void main(){unsigned int y,z;lcd_init();lcd_command(0x0c);input=0xff; //as port 0 bydefult low we have to made as highTMOD=0x22; //timer0 setting for generating clock of 500KHz using interrupt enable mode.TH0=0xFD;IE=0x82;TR0=1;LCDGotoXY(0,0);lcd_string("direct analog");delay(200);while(1){ y=read_adc(7); //huminity sensor z=read_adc(6); //tempareture sensor y=y*1.95; z=z*1.95; delay(25); LCDGotoXY(0,0); lcd_string("humd: "); LCDGotoXY(5,0); sensor_display(y);
  8. 8. delay(25);LCDGotoXY(8,0);lcd_string("Temp: ");LCDGotoXY(13,0);sensor_display(z);delay(25); if( (y>=15) ) { lcd_command(0x0c); //dispaly on cursor off LCDGotoXY(0,1); lcd_string("hum->hig "); delay(40); } else { lcd_command(0x0c); //dispaly on cursor off LCDGotoXY(0,1); lcd_string("hum->nom"); delay(40); } if( z>=40) { lcd_command(0x0c); //dispaly on cursor off LCDGotoXY(9,1); lcd_string(" T hig ");
  9. 9. delay(40); } else { lcd_command(0x0c); //dispaly on cursor off LCDGotoXY(9,1); lcd_string(" T noml "); delay(40); } lcd_command(0x02);}}