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.