title: Using External Vref for SAMD21 DAC
body: <p>I use SAMD21 Xplained board. I run a DAC example provided by Atmel Studio: DAC_QUICKSTART1</p>
  
  <p>In header file that comes with the example (<code>dac_feature.h</code>), I have following enum:</p>
  
  <pre class="lang-c prettyprint-override"><code>enum dac_reference {
      /** 1V from the internal band-gap reference*/
      DAC_REFERENCE_INT1V = DAC_CTRLB_REFSEL(0),
      /** Analog V&lt;SUB&gt;CC&lt;/SUB&gt; as reference */
      DAC_REFERENCE_AVCC  = DAC_CTRLB_REFSEL(1),
      /** External reference on AREF */
      DAC_REFERENCE_AREF  = DAC_CTRLB_REFSEL(2),
  };
  </code></pre>
  
  <p>Originally, reference voltage is internal 1V voltage. I want to use external reference, so that DAC output can vary from 0V to 5V or so.</p>
  
  <p>My question is: How do I actually set these settings?</p>
  
  <p>In the same file - <code>dac_feature.h</code>, there is a following struct:</p>
  
  <pre class="lang-c prettyprint-override"><code>struct dac_config {
      /** Reference voltage */
      enum dac_reference reference;
      /** Select DAC output */
      enum dac_output output;
      /** Left adjusted data */
      bool left_adjust;
      /** GCLK generator used to clock the peripheral */
      enum gclk_generator clock_source;
  #ifdef FEATURE_DAC_DATABUF_WRITE_PROTECTION
      /** Bypass DATABUF write protection */
      bool databuf_protection_bypass;
  #endif
      /** Voltage pump disable */
      bool voltage_pump_disable;
      /**
       * The DAC behaves as in normal mode when the chip enters STANDBY sleep
       * mode
       */
      bool run_in_standby;
  #if (SAMC21)
      /** Dither mode enable data */
      bool dither_mode;
  #endif
  };
  </code></pre>
  
  <p>Here there is created instance of <code>dac_reference</code> called reference. I assume that this is where it is done, but I am still not sure how.</p>
  
  <p>Any help appreciated.</p>