Thursday, 9 June 2016

ADC (Anlog to digital Coverter) with LPC2148 (ARM)

ADC (Anlog to digital Coverter)with LPC2148 (ARM) :

Program: ADC using Temperature Sensor :

#include<lpc214x.h>
#include<stdio.h>
#define PLLE 0
#define PLLC 1
#define PLOCK 10
#define rs 16
#define rw 17
#define en 18
#define lcdport IO0SET
#define lcdportclr IO0CLR
void daten(void);
void cmnd(void);
void pllinit(void);
void delay(int);
void lcdcmd(char);
void lcddata(char);
void lcdinit(void );
void lcdstring( char *);
void adcinit(void);
unsigned long int temp;
char res[4];
int main()
{

    PINSEL0=0x000;
    PINSEL2=0;
        IO1DIR=0xffff0000;
    pllinit();
    lcdinit();
    adcinit();
    lcdstring("ADC VAL 4 TMP IS:");
    while(1)
    {
        AD0CR|=(1<<24);
        while((AD0GDR & (unsigned long   )(1<<31))==0);
        temp=(AD0GDR>>6)&0x3ff;
        lcdcmd(0xc0);
        sprintf(res,"%d",temp/3);
        lcdstring(res);
        delay(10);
    }
}








void adcinit()
{
    PINSEL1=(1<<24);    //select AD0.1 Functionality
    AD0CR=0x00200302;
}
void lcdinit()
{
    IO0DIR|=(0xff<<16);
    lcdcmd(0x02);
    lcdcmd(0x28);
    lcdcmd(0x01);
    lcdcmd(0x0e);
    lcdcmd(0x80);
}
void lcdcmd(char ch)
{
    IO0SET = ((ch&0xf0)<<15);
    cmnd();
    IO0CLR = ((ch&0xf0)<<15);
    lcdport = (((ch<<4)&0xf0)<<15);
    cmnd();
    lcdportclr = (((ch<<4)&0xf0)<<15);
}

void lcddata(char ch)
{
    lcdport = ((ch&0xf0)<<15);
    daten();
    lcdportclr = ((ch&0xf0)<<15);
   
    lcdport = (((ch<<4)&0xf0)<<15);
    daten();
    lcdportclr = (((ch<<4)&0xf0)<<15);
}
void cmnd()
{
    lcdportclr = (1<<rs);
    lcdportclr = (1<<rw);
    lcdport = (1<<en);
    delay(1);
    lcdportclr = (1<<en);
    delay(2);
}
void daten()
{
    lcdport = (1<<rs);
    lcdportclr = (1<<rw);
    lcdport = (1<<en);
    delay(1);
    lcdportclr = (1<<en);
    delay(5);
}
void lcdstring(char *x)
{
    while(*x != '\0' )
    {
        lcddata(*x);
        x++;
    }
}

void delay(int ms)
{
    T1CTCR=0x00;
    T1TC=0;
    T1PC=0;
    T1PR=59999;
    T1TCR=0x02;
    T1TCR=0x01;
    while( T1TC != ms);
    T1TCR=0;
}
void pllinit()
{
 PLL0CFG=0x24;
 PLL0CON=PLL0CON|(1<<PLLE);
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 //PLL0CON=PLL0CON|(1<<PLLC);
 while( (PLL0STAT & (1<<PLOCK))==0);
 PLL0CON=PLL0CON|3;
 PLL0FEED=0xAA;
 PLL0FEED=0x55;   
 VPBDIV=0x01;
}

Simulation:




1 comment:

  1. Thanks for above article!!
    I want to interface multiple sensors with lpc2148.Is there any reference How do I select and read multiple ADC in LPC2148.

    ReplyDelete

if you have any doubt please let me know