0

我使用 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调用引用的实例。我认为这是完成的地方,但我仍然不确定如何。

任何帮助表示赞赏。

4

1 回答 1

0

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中找到。

于 2018-12-07T18:23:14.007 回答