0

Using other Vref for DAC on itsybitsy M0 Express
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Using other Vref for DAC on itsybitsy M0 Express

by feather_user on Sun May 23, 2021 3:03 pm

I'm playing around with the ItsyBitsy M0, and specifically trying to play around with other Voltage references for the DAC other than the standard 3.3V reference. Do the Arduino analog functions have support for other references or do I need to dig deeper into the SAMD documentation and set bits manually? Anyone have experience with this?

For reference, here's what I'm currently using:
Code: Select all | TOGGLE FULL SIZE
  #define DAC_PIN A0

  // adafruit docs say to not set the A0 pin to output if used as a true DAC
  //pinMode(DAC_PIN, OUTPUT);
  analogWriteResolution(10);
  analogReference(AR_INTERNAL1V0);

  analogWrite(DAC_PIN, output);


I needed to add the call to analogWriteResolution to get the full 10 bit range of the DAC, but the reference call doesn't appear to work right away. The AR_INTERNAL1V0 comes from the wiring analog header file, but that header seems to mostly be referencing the ADC and not the DAC.

I'm succesful in outputting from the DAC across the 3.3V range, but would like to use a different reference if it's not too much effort. Has anyone implemented this on the itsybitsy M0 or other SAMD21 boards using the arduino libraries?

feather_user
 
Posts: 3
Joined: Wed Oct 10, 2018 12:18 pm

Re: Using other Vref for DAC on itsybitsy M0 Express

by feather_user on Sun May 23, 2021 6:03 pm

Started reading the Atmel docs and decided to do one more google and it seems I'm not the first to try to do this. Arduino forum to the rescue:
https://forum.arduino.cc/t/set-ref-for-dac-solved/628586

In case that post doesn't survive the passage of internet time, here's the trick:

analogReference(AR_INTERNAL1V0) only works for the ADC

the DAC voltage reference can be set directly:
Code: Select all | TOGGLE FULL SIZE
DAC->CTRLB.bit.REFSEL = 0;


Page 922 of the docs shows the options for the DAC voltage reference settings.
https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Atmel-42181-SAM-D21_Datasheet.pdf

feather_user
 
Posts: 3
Joined: Wed Oct 10, 2018 12:18 pm

Please be positive and constructive with your questions and comments.