Content originally posted in LPCWare by yohvd on Sun Dec 15 03:34:36 MST 2013
Hi,
I'm beginner with LPC1769 and I have to use the digital analog converter but It seems I didn't understand all registers because it doesn't work.
The code (show below) is a dac test. I increment a value (i) which is put in DACR. When i attend a max value, I decrement.
The clock used as peripheral clock is the IRC clock at 4 MHZ. To set my settling time at 10 KHz, I set CNTVAL at 400.
The code:
Quote:
#include <cr_section_macros.h>
#include <NXP/crp.h>
__CRP const unsigned int CRP_WORD = CRP_NO_CRP;
#include "lpc17xx.h"
#include "type.h"
#include "dac.h"
///////////////////////////////////////////////////
void initclock(void);
void DACInit(void);
///////////////////////////Main///////////////////////////////////
int main(void)
{
initclock();
DACInit();
uint32_t value = 51;
uint32_t i = 0;
while(1)
{
for(i=0 ;i<=value; i++ )
LPC_DAC->CR |= (10*i << 6);
for(i=value; i>=0;i--)
LPC_DAC->CR |= (i*10 << 6);
}
}
///////////////////////////initialisation///////////////////////////////////
void DACInit( void )
{
/* setup the related pin to DAC output */
LPC_PINCON->PINSEL1 = (1<<21);/* set p0.26 to DAC output */
LPC_DAC->CR = 0;
LPC_DAC->CTRL = (0<<1)|(1<<2);
LPC_DAC->CNTVAL = 0x0190; /*counter set at 400*/
}
void initclock( void ) /*init peripheral clock at 4MHZ */
{
LPC_SC->CLKSRCSEL = 0x00;
LPC_SC->PLL0CON = 0x01;
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
LPC_SC->PLL0CFG = 0x3B;
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
while (!(LPC_SC->PLL0STAT & (1<<26)));
LPC_SC->PLL0CON = 0x03;
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
while (!(LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));
LPC_SC->CCLKCFG = 0x00000078;
LPC_SC->PCLKSEL0 |= (1<<22);
LPC_SC->CLKOUTCFG |= 2;
LPC_SC->CLKOUTCFG |= (1<<8);
LPC_PINCON->PINSEL3 |= (1<<22);/*used to see CLKOUT on P1.27. It works */
}
/*********************************************************************************
** End Of File
*********************************************************************************/
Thanks for help.
Yohvd