beyond_笑谈 发表于 2024-11-24 21:41

【Follow me第二季第3期】DAC配置生成波形及测试

<p>Stack中增加DAC的功能配置</p>

<p > &nbsp;</p>

<p >增加DAC0引脚P014并配置为enable,引脚冲突</p>

<p > &nbsp;</p>

<p >&nbsp;</p>

<p >确认是ADC0的第12通道AN012已经占用P014</p>

<p > &nbsp;</p>

<p >&nbsp;</p>

<p >ADC0的AN012引脚配置为None,DAC0的引脚配置则不冲突</p>

<p > &nbsp;</p>

<p > &nbsp;</p>

<p >&nbsp;</p>

<p >在common_init中增加DAC函数调用</p>

<p > &nbsp;</p>

<p >增加正旋波形产生函数程序</p>

<p > &nbsp;</p>

<p >&nbsp;</p>

<p >#include &quot;math.h&quot;&nbsp;&nbsp;</p>

<p >#define M_PI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.14159265358979323846</p>

<p >void gpt_blue_callback(timer_callback_args_t * p_args)</p>

<p >{</p>

<p >&nbsp;&nbsp;&nbsp; FSP_PARAMETER_NOT_USED(p_args);</p>

<p >&nbsp;&nbsp;&nbsp; uint16_t dacvalue = 0;&nbsp;</p>

<p >&nbsp;&nbsp;&nbsp; static double w = 0.0;</p>

<p >&nbsp;&nbsp;&nbsp; w += M_PI / 30;</p>

<p >&nbsp;&nbsp;&nbsp; if (w &gt;= M_PI * 2)</p>

<p >&nbsp;&nbsp;&nbsp; {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; w = 0.0;</p>

<p >&nbsp;&nbsp;&nbsp; }</p>

<p >&nbsp;&nbsp;&nbsp; dacvalue = (sin(w) + 1) / 2 * 4096;</p>

<p >R_DAC_Write(&amp;g_dac0_ctrl, dacvalue);&nbsp;&nbsp;</p>

<p >&nbsp;</p>

<p >利用笔式示波器测量P014引脚的输出波形,如下</p>

<p > &nbsp;</p>

<p >测试环境如下</p>

<p > &nbsp;</p>
页: [1]
查看完整版本: 【Follow me第二季第3期】DAC配置生成波形及测试