Question on DAC handling #98
-
First, thanks a lot for this brilliant library - again, like all of your stuff, now for this exciting chips too! This does nothing; but when writing DAC0.DATAL and DATAH, then the analog output changes as expected. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
hm, are you shifting the data appropriately? if you have a number X that is a 10 bit desired output value, you're setting DAC0.DATA = X <<6? That register is left-adjusted so it can be a normal 16-bit register while letting you write the low byrte onlyto use as an 8-bit DAC., |
Beta Was this translation helpful? Give feedback.
-
This code works for me: void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("reset");
delay(4000);
DACReference(VDD);
DAC0.CTRLA=DAC_ENABLE_bm | DAC_OUTEN_bm;
DAC0.DATA=(uint16_t)0x8000;
analogRead(ADC_DAC0); //dummy read - first analog read I take (of anything, not just this) comes back 0, investigating.
}
void loop() {
// put your main code here, to run repeatedly:
static uint16_t dacval = 0x110;
DAC0.DATA = (dacval << 6);
delay(1000);
Serial.printHex(dacval);
Serial.print(" ");
Serial.printHex(DAC0.DATA);
Serial.print(" ");
Serial.println(analogRead(ADC_DAC0));
dacval+= 0x20;
dacval &=0x03FF;
} |
Beta Was this translation helpful? Give feedback.
hm, are you shifting the data appropriately? if you have a number X that is a 10 bit desired output value, you're setting DAC0.DATA = X <<6? That register is left-adjusted so it can be a normal 16-bit register while letting you write the low byrte onlyto use as an 8-bit DAC.,