AVR128DA64 Analog output setup

Unable to set up the DAC for AVR128DA64 chip, tried to configure but could not get any output it's always 4.2Volts on PD6, I have put 56K as load resistor tied to ground, need an example code to properly setup DAC0 analog output which is going to be used as contrast setting for 4 X20 LCD. Idea is to use DAC0 analog output voltage as digital control of contrast of LCD

Using Spence Konde’s Arduino core? Or bare c?
What does your current code look like?

using dxcore from Spence konde's, but there is no clear example how to proceed I tried different methods but does not work. using following code not sure if its correct but its not working.

unsigned int dacValue = 0;

void setup() {
  
Serial.begin(115200); // open the serial port
DACReference(VDD); 
DAC0.CTRLA |= (DAC_OUTEN_bm | DAC_ENABLE_bm);
dacValue = 512;
// write value to DAC
DAC0.DATA   = (dacValue << 6); // this should produce some voltages according to dacvalue on PD6 pin.

}

void loop() {


}

DxCore should have Arduino-style support for the DAC

   analogWrite(PIN_PD6, value);  // output 8bit analog value

As for your own code. Did you do:

The input for the DAC pin must be disabled in the Port peripheral (ISC = INPUT_DISABLE in PORTx.PINCTRLn).

Thanks "westfw", I knew from the datasheet that DAC output pin needs to disable input but was not sure how to do it, after a bit of research found the method now the DAC is working fine posting the code I tested below.


unsigned int dacValue = 0;

#define PIN_ISC_DISABLE      0x00C0 // DISABLED

void setup() {
  
Serial.begin(115200); // open the serial port

PORTD.PIN6CTRL = PIN_ISC_DISABLE;

DACReference(INTERNAL2V5); 
DAC0.CTRLA |= (DAC_OUTEN_bm | DAC_ENABLE_bm);
dacValue = 512;// 0 - 1023 10bit data will produce 0 - 2.5V on DAC0 out put pin 

DAC0.DATA   = (dacValue << 6); // this should produce some voltages according to dacvalue on PD6 pin.

}

void loop() {

Serial.println(DAC0.DATA);
delay(3000);
}