You are currently using guest access (Log in)
Advanced Processors - TE
Home
 Courses
 Savitribai Phule Pune University
 Electronics and Telecommunication Engineering
 Third Year
 Advanced Processors - TE
 Unit 4 : Real World Interfacing with ARM7 Based Microcontroller -2
 DAC in LPC2148
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 
Pin	Type	Description
AOUT	Output	Analog 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.
VREF	Reference	Voltage Reference. This pin provides a voltage reference level for the D/A converter.
VDDA, VSSA	Power	Analog 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-17	16	15-6	5-0
Reserved	BIAS	10-bit Digital Value	Reserved
DAC Register (DACR - address OxE006 C000) Bit Description 
Bit	Symbol	Value	Description	Reset 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:6	VALUE	 	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
16	BIAS	0	The settling time of the DAC is 1 µs max, and the maximum current is 700 µA.	0
1	The 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.

0V,
1.65V,
3.3V 
Formula:

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

Solution:

DACR = 0x00010000;     //AOUT = 0V
DACR  =  0x00018000;     //AOUT = 1.65V
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);
 }
} 

C Language online compiler

Write, Run & Share C Language code online using OneCompiler's C online compiler for free. It's one of the robust, feature-rich online compilers for C language, running the latest C version which is C18. Getting started with the OneCompiler's C editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'C' and start coding!

Read inputs from stdin

OneCompiler's C online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample C program which takes name as input and print your name with hello.

#include <stdio.h>
int main()
{
    char name[50];
    printf("Enter name:");
    scanf("%s", name);
    printf("Hello %s \n" , name );
    return 0;
    
}

About C

C language is one of the most popular general-purpose programming language developed by Dennis Ritchie at Bell laboratories for UNIX operating system. The initial release of C Language was in the year 1972. Most of the desktop operating systems are written in C Language.

Key features:

  • Structured Programming
  • Popular system programming language
  • UNIX, MySQL and Oracle are completely written in C.
  • Supports variety of platforms
  • Efficient and also handle low-level activities.
  • As fast as assembly language and hence used as system development language.

Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition if-else is used.

if(conditional-expression) {
   // code
} else {
   // code
}

You can also use if-else for nested Ifs and if-else-if ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to if-else-if ladder.

switch(conditional-expression) {    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
...    
    
default:     
 // code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  // code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition) {  
 // code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {
  // code 
} while (condition); 

Arrays

Array is a collection of similar data which is stored in continuous memory addresses. Array values can be fetched using index. Index starts from 0 to size-1.

Syntax

One dimentional Array:

data-type array-name[size];

Two dimensional array:

data-type array-name[size][size];

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

Two types of functions are present in C

  1. Library Functions:

Library functions are the in-built functions which are declared in header files like printf(),scanf(),puts(),gets() etc.,

  1. User defined functions:

User defined functions are the ones which are written by the programmer based on the requirement.

How to declare a Function

return_type function_name(parameters);

How to call a Function

function_name (parameters)

How to define a Function

return_type function_name(parameters) {  
  //code
}