You are not logged in

Log in into our community

Log in so you acess some hidden content

* Fields are required.

Register into our community!

Sign up now for some good content

* Fields are required.

Lost something?

Enter your username or email to reset your password.

* Fields are required.

Digital to Analog Convertor

Posted on : Wed , 02 2014 by : virusi

Theory on digital to analog convertor :

Digital to analog convertor or abbreviated DAC are the opposite of the Digital to Analog convertor. The same as ADC, one of the most important features is the resolution, this is how accurate DAC will output the voltage from the DAC register. Most used DAC’s are be 8 bit , 10 bit and 12bit. Let’s take look at a 8 bit DAC which can output maximum 5V. What is the minimum voltage change that can support DAC? We have to divide the maximum output voltage (5V) to 256(
) and this will be the minimum voltage change. In our case it will be 19.53 mV. So if you want the output voltage to be more accurate than you should buy a microcontroller with a DAC that has a higher resolution. What will be the minimum voltage change of a 10 bit DAC?

Another important feature of the DAC is the maximum update rate. This is how fast your value from the DAC register can be transformed in voltage that is outputted on the DAC PIN. For LPC1768 the maximum update rate is 1 MHz.

What is maximum voltage that can be outputted by and DAC? Because DAC and ADC have the same Vref+ and Vref- the maximum output voltage of the DAC is the (Vref+) – (Vref-) because in our scheme Vref+ is connected to 3.3V and Vref- is connected to ground , our maximum output voltage is 3.3V.

LPC1768 Practical Example :

In this example will use our ADC and DAC. Will connected to our DAC a buzzer and depending on the output voltage the buzzer volume will differ. At our ADC will connect a potentiometer and depending the input voltage will modify the output voltage. Here will have a small problem because the ADC value is on 12 bit’s but our DAC is on 10 bit’s. Will have to reduce our ADC value into a 10 bit value, so everything works as expected.

Fig.1 DAC Application

Let’s take a look at the program step by step.


1. Configure clock

/* initialize clocks */

2. Configure ADC

/* Init ADC */ 
void AdcInit(void)
 /* select ADC function for  */	
 /* P1.31 is selected as GPIO */
 /* P1.31 is selected as AD0.5 */
 /* configure ADC */
 /* Enable power to ADC block */
                          /* select AD0.5 pin */	
                          /* ADC clock is 25MHz/1 */
                          /* enable ADC */
                         /* Start conversion now. */
 /* enable ADC interrupt */
 /* enable interrupt generation for AD0.5  */ 

3. Configure DAC

 /* DAC init */
 void DacInit(void)


1. When a ADC interrupt occurs , read ADC register for the necessary channel and assign it to a global variable

void ADC_IRQHandler(void)
  uint32_t adGdr = 0UL;
  uint32_t channel = 0UL;
  /* disable ADC interrupt */
  channel = LPC_ADC->ADSTAT>>5;
  /* check if conversion on the 5 channel
  is done */
  if(channel & 0x01)
    adGdr = (LPC_ADC->ADDR5>>4);
    ADCval  = (adGdr&ADC_MAX_VALUE);
  /* enable ADC interrupt */
  /* start a new conversion */

2. Transform our ADC value and into a 10 bit value and DAC register.

  /* trasform 12 bit value to 10 bit value */
  DACval = ADCval>>2;
  /* write requested voltage at output */
  LPC_DAC->DACR = DACval<<6;


If you are interested in the full example then download DAC example.

Last updated on Wed , 08 2014

This page is waiting for your comment.

Share and Leave a comment.

You must be logged in to post a comment.

Back to Top