Sine Wave Generator using DAC with LPC17xx (LPC1769) tutorial.

 By configuring the DAC (digital to analog converter) , we can generate sine wave of required frequency.

The DAC used in LPC 1769 has the following features.

1. 10-bit digital to analog converter
2. Resistor string architecture
3. Buffered output
4. Selectable speed vs. power
5. Maximum update rate of 1 MHz.


D/A PIN DESCRIPTION

Analog Output(AOUT)- 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  ((VREFP - VREFN)/1024) + VREFN. The DAC output is disabled when the device is in deep-sleep, power-down, or deep power-down mode.
Voltage References (VREFP, VREFN)- These pins provide a voltage reference level for the ADC and DAC. VREFP should be tied to VDD (3V3) and VREFN should be tied to VSS if the ADC and DAC are not used.
Analog Power and Ground (VDDA, VSSA)- These should typically be the same voltages as VDD and VSS, but should be isolated to minimize noise and error. Note: VDDA should be tied to VDD(3V3) and VSSA should be tied to VSS if the ADC and DAC are not used.


D/A Converter Register (DACR - 0x4008 C000)

  This read/write register includes the digital value to be converted to analog, and a bit that trades off performance vs. power. Bits 5:0 are reserved for future, higher-resolution D/A converters.
Bit[5:0] - Reserved, user software should not write ones to reserved bits. The value read from a reserved bit is not defined.
BIT[15:6] (value)- After the selected settling time after this field is written with a new VALUE, the voltage on the AOUT pin (with respect to VSSA) is VALUE  ((VREFP - VREFN)/1024) + VREFN.
BIT[16] (bias)- When bit 16 is 0, the settling time of the DAC is 1 microsecond max, and the maximum current is 700 microampere. This allows a maximum update rate of 1 MHz. Bit 16 as 1 The settling time of the DAC is 2.5 microsecond and the maximum current is 350 microampere . This allows a maximum update rate of 400 kHz.
BIT[31:17] – Reserved


DACCNTVAL DAC Counter Value register

This register contains the reload value for the DAC DMA/Interrupt timer.


DAC programming example

/*
==============================================================
Name : main.c
Author : $(author)
Version :
Copyright : $(copyright)
Description : main definition
==============================================================
*/

#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include "cr_section_macros.h"

#include "stdio.h"
#include "LPC17xx.H" // LPC17xx definitions
#include "dac.h"

uint32_t sinetable[]={512,528,544,560,576,592,608,624,639,655, 670,685,700,715,730,744,759,773,786,800,813,826,838,850,862, 874,885,896,906,916,926,935,944,953,961,968,975,982,988,994, 999,1004,1008,1012,1015,1018,1020,1022,1022,1023,1023,1023, 1022,1022,1020,1018,1015,1012,1008,1004,999,994,988,982,975, 968,961,953,945,936,927,917,907,896,886,874,863,851,839,826, 813,800,787,773,759,745,731,716,701,686,671,656,640,624,609, 593,577,561,545,529,513,497,481,465,449,433,417,401,386,370, 355,339,324,310,295,280,266,252,238,225,212,199,186,174,162, 151,139,129,118,108,98,89,80,72,64,56,49,43,36,31,25,21,16, 13,9,6,4,2,1,0,0,0,1,2,4,6,9,12,16,20,25,30,35,42,48,55,63, 71,79,88,97,107,117,127,138,149,160,172,185,197,210,223,236, 250,264,278,293,307,322,337,352,368,383,399,415,430,446,462,478,494};

int main(void)
{
uint8_t i = 0;
uint32_t m =0;
SystemInit(); // initialize clocks
DACInit();
while(1)
{
for(i=0; i < 200; i++)
{
LPC_DAC->DACR = (sinetable[i]<< 6) | DAC_BIAS;
for(m = 1000; m > 1; m--);
}
}
}

void DACInit( void )
{
/* setup the related pin to DAC output */
LPC_PINCON->PINSEL1 &= ~0x00300000 ;
LPC_PINCON->PINSEL1 |= 0x00200000; /* set p0.26 to DAC output */
return;
}


.................................................................................................
Related Programs:
ARM General Purpose Input Output
ARM Timer Programming
ARM ADC Programming
ARM Square wave Generator
ARM Sine wave Generator