RA4E1包含一路12bit精度的DAC,这个要比通常的MCU要高4倍,通常的MCU中集成的DAC为10bit的精度,本次测试对DAC进行测试,测量工具使用的是万用。
首先是使用FSP建立项目,
加入sci_uart和Dac驱动,设置uart使用通道9,设置回调函数user_uart_callback()
设置dac引脚
DAC0的设置为P014,但是这个引脚没有引出到arduino接口。引出的是PMOD1的第7脚
设置通道channel 0,驱动名称为g_dac0,引脚已经设置好了P014,生成项目,用keil打开
/*******************************************************************************************************************//**
* main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function
* is called by main() when no RTOS is used.
**********************************************************************************************************************/
void hal_entry(void)
{
/* TODO: add your own code here */
fsp_err_t err = FSP_SUCCESS;
uint16_t input = 0;
err = R_SCI_UART_Open(&g_uart9_ctrl, &g_uart9_cfg);
unsigned char buff[]="RA E2STUDIO DAC";
size_t buff_len = strlen(buff);
err = R_SCI_UART_Write(&g_uart9_ctrl, buff, buff_len);
if(FSP_SUCCESS != err) __BKPT();
while(uart_send_complete_flag == false){}
uart_send_complete_flag = false;
err = R_DAC_Open (&g_dac0_ctrl, &g_dac0_cfg);
input =(uint16_t)(1.5/3.3*4096);
/* Write value to DAC module */
err = R_DAC_Write (&g_dac0_ctrl, input);
err = R_DAC_Start (&g_dac0_ctrl);
for(;;){
err = R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_07, BSP_IO_LEVEL_HIGH);
err = R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_08, BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay (200, BSP_DELAY_UNITS_MILLISECONDS);
err = R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_07, BSP_IO_LEVEL_LOW);
err = R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_08, BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay (200, BSP_DELAY_UNITS_MILLISECONDS);
}
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
}
主要的程序都在hal_entry()函数中,主要步骤。
打开dac设备,err = R_DAC_Open (&g_dac0_ctrl, &g_dac0_cfg);
设置输出的电压,err = R_DAC_Write (&g_dac0_ctrl, input);
开始输出,err = R_DAC_Start (&g_dac0_ctrl);
编译调试程序... 测试的输出电压与设置的差不多,长时间静置,基本上变化不大。输出精度较高,这里可能有小伙伴有疑问,你都是15.086了这么还较高呢,这里解释一下:
1、因为使用万用表直接测量,没有做阻抗匹配,万用表的阻抗大概在50M欧姆的样子,这个会影响测量
2、电压为3.3V基准,计算也可能带来误差。