You are currently viewing DAC interface with Cortex M4

DAC interface with Cortex M4

Spread the love

This blog post explains how to interface DAC with LPC4088 based cortex m4 development board

Procedure to interface DAC with Cortex M4

  1. Configure Pin P0.26 for DAC using IOCON_P0_26
  2. Enable DAC
  3. Set the Maximum current output as default (700uA)
  4. Write the sample DAC values in DAC data register.

C source code to interface DAC with Cortex M4

#include "LPC407x_8x_177x_8x.h"

void init_dac(void);
void Write_DAC(unsigned int dacval);
void delay_ms(long ms) ;

int main(void)
{
		init_dac();

		while(1)
		{
				Write_DAC(0x3FF);
				delay_ms(1);
				Write_DAC(0);
				delay_ms(1);
		}
}

void init_dac(void)
{
	
	//1.Configure Pin P0.26 for DAC using IOCON_P0_26
	//2.Enable DAC (bit 16)
	  LPC_IOCON->P0_26 =  (2<<0) | (1<<16);        	/* Pin P0.26 used as DACDOUT */

	//3.Set the Maximum current output as default (700uA)
	  LPC_DAC->CR = 0;								
													
}

//4.Write the sample DAC values in DAC data register
void Write_DAC(unsigned int dacval)
{
	  LPC_DAC->CR = (dacval<<6);
}

void delay_ms(long ms) 					// delay 1 ms per count @ CCLK 120 MHz
{
		long i,j;
		for (i = 0; i < ms; i++ )
		for (j = 0; j < 26659; j++ );
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.