RA4E1 contains a 12-bit precision DAC, which is 4 times higher than that of ordinary MCUs. The DAC integrated in ordinary MCUs has a precision of 10 bits. This test tests the DAC, and the measurement tool used is a universal.
The first step is to use FSP to build a project.
Add sci_uart and Dac drivers, set uart to use channel 9, and set callback function user_uart_callback()
Setting DAC pins
DAC0 is set to P014, but this pin is not brought out to the Arduino interface. It is brought out to PMOD1's 7th pin.
After the setup is completed, set the DAC driver
Set channel 0, driver name to g_dac0, pin has been set to P014, generate the project, open it with 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
}
The main procedures are in the hal_entry() function, the main steps.
Open dac device, err = R_DAC_Open (&g_dac0_ctrl, &g_dac0_cfg);
Set the output voltage, err = R_DAC_Write (&g_dac0_ctrl, input);
Start output, err = R_DAC_Start (&g_dac0_ctrl);
Compile and debug the program...
The output voltage of the test is almost the same as the setting. After long-term static, there is basically no change. The output accuracy is relatively high. Some friends may have questions here. You are already 15.086, but it is still high. Here is an explanation:
1. Because the multimeter is used for direct measurement without impedance matching, the impedance of the multimeter is about 50M ohms, which will affect the measurement.
2. The voltage is 3.3V reference, and calculations may also cause errors.
|