DAC in LPC2148

DAC in LPC2148

Features of DAC


  • LPC2148 has one 10-bit DAC
  • Settling time software selectable 
  • DAC output can drive max of 700 micro-Ampere or 350 micro-Ampere
  • DAC peripheral has only one register, DACR
    • It contains 10-bit value for conversion in bit[15:6] position 
    • Bit[16] selects settling time, ‘1’ selects  1 micro-seconds settling time and 700 micro-Ampere Current
                                                   '0’ selects  2.5 micro-seconds settling time and 700 micro-Ampere Current 
DAC Pin Description 
PinTypeDescription
AOUTOutputAnalog Output. After the selected settling time after the DACR is written with a new value, the voltage on this pin (with respect to VSSA) is VALUE/1024 * VREF.
VREFReferenceVoltage Reference. This pin provides a voltage reference level for the D/A converter.
VDDA, VSSAPowerAnalog Power and Ground. These should be nominally the same voltages as V3 and VSSD, but should be isolated to minimize noise and error.

Digital to Analog Control Register (DACR)


31-171615-65-0
ReservedBIAS10-bit Digital ValueReserved
DAC Register (DACR - address OxE006 C000) Bit Description 
BitSymbolValueDescriptionReset value
5:0- Reserved, user software should not write ones to reserved NA bits. The value read from a reserved bit is not defined.NA
15:6VALUE After the selected settling time after this field is written with a 0 new VALUE, the voltage on the AOUT pin (with respect to VssA) is VALUE/1024 * VREF.0
16BIAS0The settling time of the DAC is 1 µs max, and the maximum current is 700 µA.0
1The settling time of the DAC is 2.5 µs and the maximum current is 350 µA. 
31:17- Reserved, user software should not write ones to reserved NA bits. The value read from a reserved bit is not defined.NA

Example:
Configure DAC register for generating with 3.3V VREF & Select 350 microAMPERE settling time.

  1. 0V,
  2. 1.65V,
  3. 3.3V 

Formula:

AOUT= VREF * (10 bit Digital Value/Resolution)

Solution:

  1. DACR = 0x00010000;     //AOUT = 0V
  2. DACR  =  0x00018000;     //AOUT = 1.65V
  3. DACR = 0x0001FFC0;      //AOUT = 3.3 V

Draw DAC interfacing diagram with LPC2148. Also write program for triangular waveform generation

Interfacing Diagram


dac interfacing

Configuring internal DAC of LPC2148 for Generation of Triangular waveform

Embedded C Program for Sine Waveform Generation


/**************************************************************************/
/* Project Name:- Sine waveform generation using internal DAC of LPC2148     */
/* Device:- LPC2148                          */
/* Compiler:- KeilUvision4                   */
/* Language:- Embedded  C*/
/* Visit www.wikinote.org for more Details   */
/********************************************************************************************/
#include <lpc214x.h>
#include <stdint.h>


void delay_ms(uint16_t j)
{
   uint16_t x,i;
for(i=0;i<j;i++)
 {
   for(x=0; x<6000; x++);    /* loop to generate 1 milisecond delay with Cclk = 60MHz */
 }
}

int main (void)
{
 uint16_t value;
uint8_t i;
 i = 0;
 PINSEL1 = 0x00080000; /* P0.25 as DAC output */
uint16_t sin_wave[42] = { 512,591,665,742,808,873,926,968,998,1017,1023,1017,998,968,926,873,808,742,665,591,512,
             436,359,282,216,211,151,97,55,25,6,0,6,25,55,97,151,211,216,282,359,436 };
while(1)
 {  
   while(i !=42)
    {
     value = sin_wave[i];
     DACR = ( (1<<16) | (value<<6) );///Bias bit=1, Digital Value left shifted by 6 bits
    delay_ms(1);
     i++;
    }
    i = 0;
  }
}  

Embedded C code for Triangular Waveform Generation


/**************************************************************************/
/* Project Name:- Triangular wave generation using internal DAC of LPC2148     */
/* Device:- LPC2148                          */
/* Compiler:- KeilUvision4                   */
/* Language:- Embedded  C*/
/* Visit www.wikinote.org for more Details   */
/********************************************************************************************/
#include <lpc214x.h>
#include <stdint.h>
void delay_ms(uint16_t j)
{
   uint16_t x,i;
for(i=0;i<j;i++)
 {
   for(x=0; x<6000; x++);    /* loop to generate 1 milisecond delay with Cclk = 60MHz */
 }
}

int main (void)
{
 uint16_t value;
uint8_t i;
 i = 0;
 PINSEL1 = 0x00080000; /* P0.25 as DAC output */
while(1)
 {  
    value = 0;
   while ( value != 1023 )
    {
     DACR = ( (1<<16) | (value<<6) );
     value++;
    }
   while ( value != 0 )
    {
     DACR = ( (1<<16) | (value<<6) );
     value--;
    }
  }
 
}

Embedded C Program for Square Waveform Generation


/**************************************************************************/
/* Project Name:- Square waveform generation using internal DAC of LPC2148     */
/* Device:- LPC2148                          */
/* Compiler:- KeiluVision4                   */
/* Language:- Embedded  C                    */
/* Visit www.wikinote.org for more Details   */
/********************************************************************************************/
#include <lpc214x.h>
#include <stdint.h>


void delay_ms(uint16_t j)
{
   uint16_t x,i;
for(i=0;i<j;i++)
 {
   for(x=0; x<6000; x++);    /* loop to generate 1 milisecond delay with Cclk = 60MHz */
 }
}

int main (void)
{
 uint16_t value;
uint8_t i;
 i = 0;
 PINSEL1 = 0x00080000; /* P0.25 as DAC output */
while(1)
 {  
    value = 1023;
    DACR = ( (1<<16) | (value<<6) );
    delay_ms(100);
    value = 0;
    DACR = ( (1<<16) | (value<<6) );
    delay_ms(100);
 }
}

References


  • WikiNote Foundation
  • Prof. Sujit Wagh

Last modified: Tuesday, 21 April 2020, 4:22 PM