【问题标题】:Using External Vref for SAMD21 DAC为 SAMD21 DAC 使用外部 Vref
【发布时间】:2018-11-29 15:39:13
【问题描述】:

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

任何帮助表示赞赏。

【问题讨论】:

    标签: atmel atmelstudio asf samd21


    【解决方案1】:

    可以在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 章的application note AT03244 中找到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多