1073|4

2934

帖子

4

TA的资源

五彩晶圆(中级)

楼主
 

【瑞萨RA6E2评估板】DAC输出测试 [复制链接]

RA6E2的DAC和ADC皆是12bit,通常见到的DAC基本上都是10bit,这个对于要求高的项目是一个不错的选择,除了精度以外还有稳定性,那么本次测试就是围绕着DAC输出进行测试。本测试主要参考了:最新的ek_ra6e2开发板的DAC项目,

首先是建立项目dac_FSP_Project

 

项目模板选择FBP_RA6E2,项目类型选择keil。

关键的是DAC的设置,这里有个坑需要注意,前一阶段就因为这个坑无法实现DAC输出

 设置如上,注意画红线部分,这个就是我说的坑,一定要打开这个项目,不然将无法输出。

项目的加入uart模块作为输出,引脚P410和P411

 

  这是全部代码,主要是打开DAC,和设置输出电压。

/***********************************************************************************************************************
 * Copyright [2020-2023] Renesas Electronics Corporation and/or its affiliates.  All Rights Reserved.
 *
 * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products
 * of Renesas Electronics Corp. and its affiliates ("Renesas").  No other uses are authorized.  Renesas products are
 * sold pursuant to Renesas terms and conditions of sale.  Purchasers are solely responsible for the selection and use
 * of Renesas products and Renesas assumes no liability.  No license, express or implied, to any intellectual property
 * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas
 * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION
 * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT
 * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR
 * DOCUMENTATION.  RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH.  TO THE MAXIMUM
 * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION
 * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING,
 * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS,
 * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY
 * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS.
 **********************************************************************************************************************/

#include "hal_data.h"
#include <stdio.h>

/* Macro definition */
#define CARRIAGE_ASCII            (13u)     /* Carriage return */
#define ZERO_ASCII                (48u)     /* ASCII value of zero */
#define NINE_ASCII                (57u)     /* ASCII value for nine */
#define DATA_LENGTH               (4u)      /* Expected Input Data length */
#define UART_ERROR_EVENTS         (UART_EVENT_BREAK_DETECT | UART_EVENT_ERR_OVERFLOW | UART_EVENT_ERR_FRAMING | \
                                    UART_EVENT_ERR_PARITY)    /* UART Error event bits mapped in registers */
#define RESET_VALUE               (0x00)

void R_BSP_WarmStart(bsp_warm_start_event_t event);

extern bsp_leds_t g_bsp_leds;

/* Flag for user callback */
static volatile uint8_t g_uart_event = RESET_VALUE;
static uint8_t g_temp_buffer[DATA_LENGTH] = {RESET_VALUE};
/* Counter to update g_temp_buffer index */
static volatile uint8_t g_counter_var = RESET_VALUE;
/* Flag to check whether data is received or not */
static volatile uint8_t g_data_received_flag = false;



/*******************************************************************************************************************//**
 * [url=home.php?mod=space&uid=159083]@brief[/url] Blinky example application
 *
 * Blinks all leds at a rate of 1 second using the software delay function provided by the BSP.
 *
 **********************************************************************************************************************/
void hal_entry (void)
{

    fsp_err_t  err = FSP_SUCCESS;
	  uint32_t local_timeout = (DATA_LENGTH * UINT16_MAX);
  	unsigned char send_buff[32]="RA Keil DAC\r";
    uint16_t output = 0;

	#if BSP_TZ_SECURE_BUILD

    /* Enter non-secure code */
    R_BSP_NonSecureEnter();
  #endif

    /* Define the units to be used with the software delay function */
    const bsp_delay_units_t bsp_delay_units = BSP_DELAY_UNITS_MILLISECONDS;

    /* Set the blink frequency (must be <= bsp_delay_units */
    const uint32_t freq_in_hz = 2;

    /* Calculate the delay in terms of bsp_delay_units */
    const uint32_t delay = bsp_delay_units / freq_in_hz;

    /* LED type structure */
    bsp_leds_t leds = g_bsp_leds;

    err = R_SCI_UART_Open(&g_uart0_ctrl, &g_uart0_cfg);
    if(FSP_SUCCESS != err) __BKPT();
		
		size_t buff_len = strlen((char *)send_buff);
		
		err = R_SCI_UART_Write(&g_uart0_ctrl, send_buff, buff_len);
		if(FSP_SUCCESS != err) __BKPT();
		
		while ((UART_EVENT_TX_COMPLETE != g_uart_event) && (--local_timeout))
    {
        /* Check if any error event occurred */
        if (UART_ERROR_EVENTS == g_uart_event)
        {
            break;
        }
    }
	
		err = R_DAC_Open (&g_dac0_ctrl, &g_dac0_cfg);	
		
		output =(uint16_t)(1.5/3.3*4096);
		
		err = R_DAC_Write (&g_dac0_ctrl, output);
		err = R_DAC_Start (&g_dac0_ctrl);
		
		
    /* If this board has no LEDs then trap here */
    if (0 == leds.led_count)
    {
        while (1)
        {
            ;                          // There are no LEDs on this board
        }
    }

    /* Holds level to set for pins */
    bsp_io_level_t pin_level = BSP_IO_LEVEL_LOW;

		memset(send_buff,0,32);
    sprintf((char *)send_buff, "a0=%f\r",1.5);
		buff_len = strlen((char *)send_buff);
		err = R_SCI_UART_Write(&g_uart0_ctrl, send_buff, buff_len);
		if(FSP_SUCCESS != err) __BKPT();
		
		while ((UART_EVENT_TX_COMPLETE != g_uart_event) && (--local_timeout))
    {
        /* Check if any error event occurred */
        if (UART_ERROR_EVENTS == g_uart_event)
        {
            break;
        }
    }
    while (1)
    {
        /* Enable access to the PFS registers. If using r_ioport module then register protection is automatically
         * handled. This code uses BSP IO functions to show how it is used.
         */
        R_BSP_PinAccessEnable();

        /* Update all board LEDs */
        for (uint32_t i = 0; i < leds.led_count; i++)
        {
            /* Get pin to toggle */
            uint32_t pin = leds.p_leds[i];

            /* Write to this pin */
            R_BSP_PinWrite((bsp_io_port_pin_t) pin, pin_level);
        }

        /* Protect PFS registers */
        R_BSP_PinAccessDisable();

        /* Toggle level for next write */
        if (BSP_IO_LEVEL_LOW == pin_level)
        {
            pin_level = BSP_IO_LEVEL_HIGH;
        }
        else
        {
            pin_level = BSP_IO_LEVEL_LOW;
        }

        /* Delay */
        R_BSP_SoftwareDelay(delay, bsp_delay_units);
    }
}

/*******************************************************************************************************************//**
 * This function is called at various points during the startup process.  This implementation uses the event that is
 * called right before main() to set up the pins.
 *
 * @param[in]  event    Where at in the start up process the code is currently at
 **********************************************************************************************************************/
void R_BSP_WarmStart (bsp_warm_start_event_t event)
{
    if (BSP_WARM_START_RESET == event)
    {
#if BSP_FEATURE_FLASH_LP_VERSION != 0

        /* Enable reading from data flash. */
        R_FACI_LP->DFLCTL = 1U;

        /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
         * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
#endif
    }

    if (BSP_WARM_START_POST_C == event)
    {
        /* C runtime environment and system clocks are setup. */

        /* Configure pins. */
        R_IOPORT_Open(&g_ioport_ctrl, g_ioport.p_cfg);
    }
}

/*****************************************************************************************************************
 *  @brief      UART user callback
 *  @param[in]  p_args
 *  @retval     None
 ****************************************************************************************************************/
void user_uart_callback(uart_callback_args_t *p_args)
{
    /* Logged the event in global variable */
    g_uart_event = (uint8_t)p_args->event;

    /* Reset g_temp_buffer index if it exceeds than buffer size */
    if(DATA_LENGTH == g_counter_var)
    {
        g_counter_var = RESET_VALUE;
    }

    if(UART_EVENT_RX_CHAR == p_args->event)
    {
        switch (p_args->data)
        {
            /* If Enter is pressed by user, set flag to process the data */
            case CARRIAGE_ASCII:
            {
                g_counter_var = RESET_VALUE;
                g_data_received_flag  = true;
                break;
            }
            /* Read all data provided by user until enter button is pressed */
            default:
            {
                g_temp_buffer[g_counter_var++] = (uint8_t ) p_args->data;
                break;
            }
        }
    }
}

DAC输出设置为1.5V电压。万用表输出为1.5104V,这个电压输出比较稳定,没有出现较大的波动。

 

 

 

最新回复

3uS的话,那频率还是蛮高的。可以当音频的DAC了?   详情 回复 发表于 2023-11-14 11:30
点赞 关注

回复
举报

7175

帖子

2

TA的资源

版主

沙发
 

这个DAC输出频率可以达到多少?

点评

转换时间为3uS,但是这个于程序设置也有关系。   [attachimg]752863[/attachimg]    详情 回复 发表于 2023-11-13 18:56
 
 

回复

2934

帖子

4

TA的资源

五彩晶圆(中级)

板凳
 
wangerxian 发表于 2023-11-13 17:54 这个DAC输出频率可以达到多少?

转换时间为3uS,但是这个于程序设置也有关系。

 

 

点评

3uS的话,那频率还是蛮高的。可以当音频的DAC了?  详情 回复 发表于 2023-11-14 11:30
 
 
 

回复

2934

帖子

4

TA的资源

五彩晶圆(中级)

4
 

瑞萨的RA6E2支持DTC方式,这可以大大增加DAC的转换效率。

 
 
 

回复

7175

帖子

2

TA的资源

版主

5
 
bigbat 发表于 2023-11-13 18:56 转换时间为3uS,但是这个于程序设置也有关系。    

3uS的话,那频率还是蛮高的。可以当音频的DAC了?

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/8 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表