atmel - 为 SAMD21 DAC 使用外部 Vref
问题描述
我使用 SAMD21 Xplained 板。我运行 Atmel Studio 提供的 DAC 示例:DAC_QUICKSTART1
在示例()附带的头文件中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
};
这里创建了dac_reference
调用引用的实例。我认为这是完成的地方,但我仍然不确定如何。
任何帮助表示赞赏。
解决方案
DAC 的配置可以在 a 中定义,struct dac_config
然后将其用作 的参数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中找到。
推荐阅读
- mysql - 引用自身时如何将表连接到自身
- java - IBM Domino Java - 优化对特定 Internet 地址的 $(Rooms) 视图的搜索
- c - 尝试将所有制表符更改为一定数量的空格,K&R 练习 1-20
- mysql - 如何使用 JPA 查询获取最后的数据
- linux - 如何使用 GStreamer 和 VAAPi 解决 RAW 流播放问题
- ruby-on-rails - 在 Google Cloud Run 中使用 Sidekiq 的 Rails 作业不起作用
- amazon-web-services - RHat企业服务器7.7 EC2镜像突然关闭80端口
- javascript - reactjs如何恢复到之前的状态?
- javascript - 如何在Javascript中将问号包围的文本提取到数组中
- python - 如何使用 Azure API 检测情绪?