Help initializing DAC on the LPC4337

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help initializing DAC on the LPC4337

674 Views
matthewmaslak
Contributor I

I'm trying to initialize the DAC on the LPC4337, I've read the DAC section of the manual and used the debugger to gain access of the DAC registers. I was able to "Enable" or set bit 3 of the CTRL register, set the CNTVAL register at 0x0000 and I put my 10 bit value in the CR register (15:6 bit) and my board does output the right analog voltage. However when I try to implement this in the code, it's not working. I don't see the CTRL bit 3 changing so I believe my initialization of the DAC isn't correct. I cannot find any documentation on this and all the examples I see either are gibberish or older/other IDEs. I'm using both LPCxpresso and MCUxpresso.  

/* p4_4 ADC0_0, GPIO 2_4*/
Chip_SCU_PinMuxSet(0x4,4,SCU_MODE_FUNC0);
Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, 2, 4); // set GPIO port direction register
Chip_SCU_PinMuxSet(0x4,4,SCU_MODE_INACT); // disable pull up and pull down resistor
LPC_SCU->SFSP[0x4][4] &= ~(1<<6);//disable receiveing by setting the EZI bit to zero.

Chip_SCU_DAC_Analog_Config(); //select DAC function
Chip_DAC_Init(LPC_DAC); //initialize DAC
Chip_DAC_SetDMATimeOut(LPC_DAC, 0x0000);
Chip_DAC_ConfigDAConverterControl(LPC_DAC, (DAC_DMA_ENA));

 I have also tried to do LPC_DAC -> to write the registers but that didn't work either. Any and all help will be appreciated.

Labels (1)
0 Kudos
1 Reply

583 Views
bernhardfink
NXP Employee
NXP Employee

Hi Matthew,

can't check the code which you are using, as I'm no longer active on this MCU platform, but there was a kind of magic setting for the DAC, see the snapshot of a thread from the past.

Hi,
I have some problem with DAC.
After configuring using driver lpc43xx_dac and selecting analog function in ENAIO2 the E3 pin
(analog pin ADC0_0/ADC1_0/DAC in LPC4350FET256) remains stable and have 3.0V voltage level.
How do I configure DAC (from lpc43xx_dac driver):


/* Set default clock divider for DAC */
CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_APB3);
//Set maximum current output
DAC_SetBias(LPC_DAC,DAC_MAX_CURRENT_700uA);
//Select pin function - DAC
p->ENAIO2 |= (1<<(0));// At that stage pin E3 goes to 3.0V

After configuring I am trying to set some voltages on the DAC output, but the voltage remains the same (3.0V).
tmp = DACx->CR & DAC_BIAS_EN;
tmp |= DAC_VALUE(dac_value);
// Update value
DACx->CR = tmp;

Looks like I have missed something.

I will kindly appreciate any help.
Thanks in advance.

=========================================================================================

Is it correct, that you use FUNC8?

scu_pinmux(0x4 ,4 , MD_PLN, FUNC8); // DAC is function 8

I find only FUNC0 to FUNC7, no FUNC8 and according to user manual UM10503 page 292 (Rev 1.4 from Sep 2012) the bit field MODE goes only from bit 0 to 2 and function 0 to 7?
Perhaps this is different in LPC18xx compared to LPC43xx?

Best regards,
M.

=========================================================================================
Hi M.,

I'm sure that's a typo. It's the ninth entry in a list where your choice is one out of eight. Correct is FUNC0, as that is the GPIO function, which you should make an input. As a matter of fact, the selection in the MODE field is only secondary.
The choice for DAC in the ENAIO2 multiplex register gives DAC precedence over the digital function selected via MODE.

However, that fight is a sideshow...
The original question wasn't for P4_4, to which those settings apply! Antony rather uses the ADC0_0/ADC1_0/DAC signal (pin E3 of the LBGA256 package). For that pure analog pin the settings of the P4_4 config register and the ENAIO2 multiplexer are completely irrelevant. Pin ADC0_0/ADC1_0/DAC will always show the DAC output as soon as the DAC is enabled.

The missing point is probably the DMA_ENA bit in the DAC CTRL register. Despite its name this bit must be set to get a DAC output, whether you use DMA or not.

Regards,
R.

Edit: I should have mentioned that the existing library requires you to call DAC_ConfigDAConverterControl() in addition to DAC_Init() for the DAC to operate.
    
=========================================================================================

Thanks for the information, but for a newbie like me, it takes hours to understand...
Let's make it easier:

SystemInit();
CGU_Init();

scu_pinmux(0x4 ,4 , MD_PLN, 0); // set pin configuration register
GPIO_SetDir(0x4, 4, 0); // set GPIO port direction register
LPC_SCU->ENAIO2 |= 1; // set analog function select register

DAC_Init(LPC_DAC);
LPC_DAC->CTRL |= DAC_DMA_ENA;

int32_t iLop;

while(1)
{
for (iLop = 0; iLop < 1023; iLop++)    DAC_UpdateValue(LPC_DAC, iLop);
for (iLop = 1023; iLop > 0; iLop--)    DAC_UpdateValue(LPC_DAC, iLop);
}

Hope it helps,

Bernhard.

0 Kudos