83|1

2

帖子

1

TA的资源

一粒金砂(中级)

楼主
 

【Follow me第二季第3期】所有任务汇总 [复制链接]

  本帖最后由 liubiy 于 2024-12-10 13:53 编辑

一 、视频介绍

 


 

资料下载

https://download.eeworld.com.cn/detail/liubiy/635227


二、入门任务:搭建环境,下载调试示例程序,Blink,按键;

 

 

 


/* LED引脚置低电平 LED灯亮 */
#define LED1_ON     R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_06, BSP_IO_LEVEL_HIGH)
#define LED2_ON     R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_07, BSP_IO_LEVEL_HIGH)
#define LED3_ON     R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, BSP_IO_LEVEL_HIGH)

/* LED引脚置高电平 LED灯灭 */
#define LED1_OFF    R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_06, BSP_IO_LEVEL_LOW)
#define LED2_OFF    R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_07, BSP_IO_LEVEL_LOW)
#define LED3_OFF    R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, BSP_IO_LEVEL_LOW)

/* 使用寄存器来实现 LED灯翻转 */
#define LED1_TOGGLE R_PORT0->PODR ^= 1<<(BSP_IO_PORT_00_PIN_06 & 0xFF)
#define LED2_TOGGLE R_PORT0->PODR ^= 1<<(BSP_IO_PORT_00_PIN_07 & 0xFF)
#define LED3_TOGGLE R_PORT0->PODR ^= 1<<(BSP_IO_PORT_00_PIN_08 & 0xFF)


/* 两个按键引脚定义 */
#define KEY1_SW2_PIN    BSP_IO_PORT_00_PIN_04
#define KEY2_SW3_PIN    BSP_IO_PORT_00_PIN_05

/* 按键扫描函数(阻塞式)
 * key: KEY1_SW2_PIN 用户按键1
 *      KEY2_SW3_PIN 用户按键2
 */
uint32_t Key_Scan(bsp_io_port_pin_t key)
{
    bsp_io_level_t state;

    // 读取按键引脚电平
    R_IOPORT_PinRead(&g_ioport_ctrl, key, &state);
    if (BSP_IO_LEVEL_HIGH == state)
    {
        return KEY_OFF; //按键没有被按下
    }
    else
    {
        do  //等待按键释放
        {
            R_IOPORT_PinRead(&g_ioport_ctrl, key, &state);
        } while (BSP_IO_LEVEL_LOW == state);
    }

    return KEY_ON; //按键被按下了
}

 

三、基础任务:quad-spi flash和octo-spi flash配置及读写速度测试;DAC配置生成波形及性能测试;

 

 电脑通过USB连接开发板的USB接口,再e2 studio打开终端。再将示波器连接P014口。

 

1,quad-spi flash和octo-spi flash配置及读写速度测试:使用的是例程中的测试代码:

 

下载quickstart_ek_ra6m5_ep的代码,连接USB ,打开终端,选择flash速度对吧

运行结果

运行的部分代码:

sprintf(s_print_buffer, "\r\n\r\nGenerated a text block of %2lu KB in SRAM\r\n", block_size_actual);

        /* ignoring -Wpointer-sign is OK when treating signed char_t array as as unsigned */
        print_to_console((void*)s_print_buffer);

        /* ignoring -Wpointer-sign is OK for a constant string */
        print_to_console((uint8_t *)
                "\r\nWriting the text block to external Quad-SPI and Octo-SPI flash memories...\r\n");

        uint32_t ospi_performance_write_result = 0;
        uint32_t ospi_performance_read_result = 0;
        uint32_t timer_frequency;


        R_GPT_InfoGet(g_memory_performance.p_ctrl, &timer_info);
        timer_frequency = timer_info.clock_frequency;

        ospi_performance_test (block_size_actual, &ospi_performance_write_result, &ospi_performance_read_result);

        /* Multiply uSec calcs by 100, to avoid losses due to small results in integer maths
         * Scaled to fit within uint32_t */
        ospi_write_result = ((100000000 / timer_frequency) * ospi_performance_write_result) / 100;
        qspi_write_result  = ((100000000 / timer_frequency) * qspi_write_test(block_size_actual)) / 100;

        /* ignoring -Wpointer-sign is OK for a constant string */
        print_to_console((uint8_t *)"Writing to flash completed\r\n");

        /* ignoring -Wpointer-sign is OK for a constant string */
        print_to_console((uint8_t *)"\r\nReading the text block from external Quad-SPI and Octo-SPI flash memories...\r\n");

        ospi_read_result  = ((100000000 / timer_frequency) * ospi_performance_read_result) / 100;
        qspi_read_result  = ((100000000 / timer_frequency) * qspi_read_test(block_size_actual)) / 100;

        /* ignoring -Wpointer-sign is OK for a constant string */
        print_to_console((uint8_t *)"Reading from flash completed\r\n");

        R_GPT_Close(g_memory_performance.p_ctrl);

        /* Handle error */
        if (FSP_SUCCESS != fsp_err)
        {
            /* Fatal error */
            SYSTEM_ERROR
        }

  2,DAC配置生成波形及性能测试:

下载自己写的代码(01_Uart_Led_Key),连接P014发出的波形。

 

DAC的配置:

 

生成波形的代码:

if(Key_Scan(KEY1_SW2_PIN)==KEY_ON){
    frequency = frequency + 20;
    if(frequency >= 200){frequency = 50;};
}

if(Key_Scan(KEY2_SW3_PIN)==KEY_ON){
    mode++;
    if(mode == 4){mode = 0;}
}


Time = Time + 0.1f;if(Time > 200){Time = 0;}
if(mode == 1){

    DAC_Value = (uint16_t)(( sin(2 * M_PI * frequency * Time) + 1 ) / 2 * 4095);

}else if(mode == 2){

    DAC_Value = (uint16_t)( ( 2 / M_PI * asin(sin(2 * M_PI / frequency * Time)) + 1 ) * 4095 );
}else if(mode == 2){

    Time1 = Time1 + 0.01f;
    if(Time1 > 200){Time1 = 0;}
    DAC_Value = (uint16_t)(  (1-exp(-Time1/frequency)) * 4095 );
}else{

    DAC_Value = (uint16_t)(2047);
}
R_DAC_Write(&g_dac0_ctrl, DAC_Value);

 

四、进阶任务:示例程序中新增命令打印信息;

实现一个:显示DAC频率和模式的参数:

 

修改的是例程中的测试代码:

添加一下显示界面的函数{"Task Information" , Task_display_menu}

/* Table of menu functions */
static st_menu_fn_tbl_t s_menu_items[] =
{
    {"Task Information"                        , Task_display_menu},
    {"Kit Information"                         , kis_display_menu},
    {"Web Server"                              , eth_emb_display_menu},
    {"Network Name Lookup"                     , eth_www_display_menu},
    {"Quad-SPI and Octo-SPI Speed Comparison"  , ext_display_menu},
    {"Cryptography and USB High speed (MSC)"   , enc_display_menu},
    {"Next Steps", ns_display_menu },
    {"", NULL }
};

在menu_kis.c中添加

extern uint8_t frequency;
extern uint8_t mode;
#define TASK_NAME     "\r\n%d. Signal Generator Task\r\n"

#define SUB_TASK        "\r\n\x1b[2m\x1b[37m a) Kit name:                            "                               \
                        "\r\n\x1b[2m\x1b[37m b) Kit ordering part number:            "                               \
                        "\r\n\x1b[2m\x1b[37m c) RA Device part number:              "                                \
                        "\r\n\x1b[2m\x1b[37m d) RA MCU 128-bit Unique ID (hex):     "                                  \
                        "                                                               "          \
                        "\r\n\x1b[2m\x1b[37m e) RA MCU Die temperature (F/C):                "  \
                        "\r\n\x1b[2m\x1b[37m f) Blue LED blinking frequency (Hz):            "               \
                        "\r\n\x1b[2m\x1b[37m g) Blue LED blinking intensity (%%%%):          "             \
                        "\r\n\x1b[2m\x1b[37m h) Waveform mode (mode1:sine wave):      \x1b[32m%d\x1b[37m "             \
                        "\r\n\x1b[2m\x1b[37m l) Waveform frequency (Hz):              \x1b[32m%d\x1b[37m "             \



test_fn Task_display_menu(void)
{
    int8_t c = -1;


    sprintf (s_print_buffer, "%s%s", gp_clear_screen, gp_cursor_home);
    print_to_console((void*)s_print_buffer);

    sprintf (s_print_buffer, TASK_NAME, g_selected_menu);
    print_to_console((void*)s_print_buffer);

    sprintf (s_print_buffer, SUB_TASK, mode, frequency);
    print_to_console((void*)s_print_buffer);

    sprintf (s_print_buffer, MENU_RETURN_INFO);
    print_to_console((void*)s_print_buffer);


    vTaskDelay (s_ticks_to_wait);
    xEventGroupSetBits (g_update_console_event, STATUS_DISPLAY_MENU_KIS);

    while (CONNECTION_ABORT_CRTL != c)
    {
        c = input_from_console ();
        if ((MENU_EXIT_CRTL == c) || (CONNECTION_ABORT_CRTL == c))
        {
            break;
        }
    }

    xEventGroupClearBits (g_update_console_event, STATUS_DISPLAY_MENU_KIS);
    return (0);
}

再添加头文件,就可以显示了

 

 

五、扩展任务:设计一个类似信号发生器功能的例程。

 

项目简介:

实现信号发生器功能,通过命令或按键,设置DAC输出波形,可通过flash存储历史波形等信息。

全部物料清单(含物料名称、实物图片):

   

用到了示波器,USB线,USB串口,开发板。

 

软件流程图:

 

关键代码:

/*
按键和FALSH存储代码
*/

if(Key_Scan(KEY1_SW2_PIN)==KEY_ON){
    frequency = frequency + 20;
    if(frequency >= 200){frequency = 50;};
    Write_Data[0] = frequency;

    err = erase_and_blankcheck(ospi_ref_addr);
    if(FSP_SUCCESS != err)
    {
        sprintf(test_str, "ERR erase_and_blankcheck: %d\n",err);
        R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str));
        R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS);
    }
    // Write Data
    err = R_OSPI_Write(&g_ospi_ctrl, Write_Data, ospi_ref_addr, (uint32_t)(OSPI_DATA_SIZE));
    wait_operation();
    if(FSP_SUCCESS != err)
    {
        sprintf(test_str, "** R_OSPI_Write API failed in SPI Operation **\r\n");
        R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str));
        R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS);
    }
    sprintf(test_str, "** frequency_success:%d **\r\n",frequency);
    R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str));
    R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS);

}

if(Key_Scan(KEY2_SW3_PIN)==KEY_ON){
    mode++;
    if(mode == 4){mode = 0;}
    Write_Data[1] = mode;

    err = erase_and_blankcheck(ospi_ref_addr);
    if(FSP_SUCCESS != err)
    {
        sprintf(test_str, "ERR erase_and_blankcheck: %d\n",err);
        R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str));
        R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS);
    }

    // Write Data
    err = R_OSPI_Write(&g_ospi_ctrl, Write_Data, ospi_ref_addr, (uint32_t)(OSPI_DATA_SIZE));
    wait_operation();
    if(FSP_SUCCESS != err)
    {
        sprintf(test_str, "** R_OSPI_Write API failed in SPI Operation **\r\n");
        R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str));
        R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS);
    }
    sprintf(test_str, "** mode_success:%d **\r\n",mode);
    R_SCI_UART_Write(&g_uart4_ctrl, (uint8_t const * const)test_str, strlen(test_str));
    R_BSP_SoftwareDelay(10u, BSP_DELAY_UNITS_MILLISECONDS);

}

生成波形的代码:

Time = Time + 1;if(Time > 20000){Time = 0;}

if(mode == 1){          //sin()

    DAC_Value = (uint16_t)(( sin(2 * M_PI / frequency * Time) + 1 ) / 2 * 4095);

}else if(mode == 2){    //3angle

    DAC_Value = (uint16_t)( ( 2 / M_PI * asin(sin(2 * M_PI / frequency * Time)) + 1 ) * 4095 );
}else if(mode == 2){

    Time1 = Time1 + 1;
    if(Time1 > 20000){Time1 = 0;}
    DAC_Value = (uint16_t)(  (1-exp(-Time1/frequency)) * 4095 );
}else{

    DAC_Value = (uint16_t)(2047);
}
R_DAC_Write(&g_dac0_ctrl, DAC_Value);

 

六、心得体会

在制作DAC信号发生器的过程中,我深入了解了数字模拟转换器(DAC)的工作原理和在信号生成中的应用。通过设计和实现这个项目,我不仅提升了对嵌入式系统的理解,也对硬件和软件之间的协作有了更深刻的体会。在实际操作中,我学习了如何通过编程控制DAC输出不同频率和幅度的信号,掌握了与硬件通信、调试和优化程序的技巧。

项目中,我遇到了不少挑战,特别是在信号精度和稳定性方面。通过不断调整硬件设置和优化代码,我逐步解决了这些问题,成功实现了预定的功能。这不仅提高了我的动手能力,还让我对嵌入式系统中信号处理的细节有了更多的了解。总的来说,制作DAC信号发生器的过程让我收获颇丰,也让我更加坚定了未来继续深入嵌入式开发的决心。

 

 

最新回复

  详情 回复 发表于 前天 14:58
点赞 关注
 
 

回复
举报

735

帖子

4

TA的资源

纯净的硅(初级)

沙发
个人签名徐建
20091127
 
 
 

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

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

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

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

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

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

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

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