我使用SAMD21拼图板。我运行了Atmel Studio: DAC_QUICKSTART1提供的DAC示例
在示例(dac_feature.h)附带的头文件中,我有以下枚举:
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),
};最初,参考电压是内部1V电压。我想使用外部引用,这样DAC输出可以从0V到5V左右不等。
我的问题是:我如何实际设置这些设置?
在同一个文件- dac_feature.h中,有以下结构:
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
};这里有一个名为reference的dac_reference创建实例。我认为这就是它的工作方向,但我仍然不确定如何做到这一点。
任何帮助都很感激。
发布于 2018-12-07 18:23:14
可以在struct dac_config中定义DAC的配置,然后将其用作dac_init()的参数。enum dac_reference定义了可以设置dac_config.reference的可能值。
// DAC abstraction struct
struct dac_module dac_instance;
// DAC parameter struct
struct dac_config config_dac;
// initialize to defaults
dac_get_config_defaults(&config_dac);
// set DAC reference to AREF
config_dac.reference = DAC_REFERENCE_AREF;
// use parameters set above to initialize DAC hardware
dac_init(&dac_instance, DAC, &config_dac);上面的线条--以及更多的细节--可以在第9.1章的应用注意事项AT03244中找到。
https://stackoverflow.com/questions/53542591
复制相似问题