Using External Vref for SAMD21 DAC

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I used SAMD21 Xplained board. I run a DAC example provided by Atmel Studio: DAC_QUICKSTART1

 

In header file that comes with the example (dac_feature.h), I have following enum:

enum dac_reference {
	/** 1V from the internal band-gap reference*/
	DAC_REFERENCE_INT1V = DAC_CTRLB_REFSEL(0),
	/** Analog V<SUB>CC</SUB> as reference */
	DAC_REFERENCE_AVCC  = DAC_CTRLB_REFSEL(1),
	/** External reference on AREF */
	DAC_REFERENCE_AREF  = DAC_CTRLB_REFSEL(2),
};

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.

My question is: How do I actually set these settings?

In the same file - dac_feature.h, there is a following struct:

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
};

Here there is created instance of dac_reference - reference. I assumed that here is where it is done, but I am still not sure how.

Any help appreciated.
 

This topic has a solution.
Last Edited: Thu. Nov 29, 2018 - 11:02 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The config is setup here 

void configure_dac(void)
{
//! [setup_config]
    struct dac_config config_dac;
//! [setup_config]
//! [setup_config_defaults]
    dac_get_config_defaults(&config_dac);
//! [setup_config_defaults]

//! [setup_set_config]
    dac_init(&dac_instance, DAC, &config_dac);
//! [setup_set_config]
}

So make your changes in config_dac after the dac_get_config_defaults call.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BTW

 ...so that DAC output can vary from 0V to 5V or so.

is not possible, check "Digital to Analog Converter (DAC) Characteristics" under "Electrical Characteristics".

/Lars

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot!

This solved it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot!

This solved it.