1、概述
感謝官方舉辦【Vision Board 創(chuàng)客營】活動,使得我有機(jī)會試用Vision Board開發(fā)板,體驗(yàn)嵌入式AI的快樂。在此,再次感謝官方以及導(dǎo)師們的熱情幫助。在本次活動中,本人選擇的是DAC功能的測試。
2、環(huán)境配置
配置
? 系統(tǒng):Win11
? 開發(fā)板:RA8-M85-vision-board
? 開發(fā)IDE:RTThread Studio 版本: 2.2.6
環(huán)境配置
3、新建工程以及編寫測試?yán)?/h3>
- 使能DAC驅(qū)動框架,可參考下圖:
- 打開RA Smart Configurator (記得選擇sc_v2023-10_fsp_v5.1.0 文件夾),進(jìn)行DAC硬件功能配置,具體可參考下圖:
- 測試程序
- 在工程src目錄中,右鍵新建 test_dac.c 文件,文件內(nèi)容如下:
/** 功能說明:通過DAC生成一個(gè)正弦波,其中每一個(gè)dac的輸出值,是通過py程序自動生成,可在附錄中自取 */ /* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2024-04-20 MagicKingC the first version */ #include < rtthread.h > #include < rtdevice.h > #define DAC_DEV_NAME "dac0" #define DAC_DEV_CHANNEL 0 static rt_uint32_t sin_wave_vaule[]={ 2048,2073,2098,2123,2149,2174,2199,2224,2249,2274, 2299,2324,2349,2374,2399,2423,2448,2473,2497,2522, 2546,2571,2595,2619,2643,2667,2691,2715,2739,2763, 2786,2810,2833,2856,2879,2902,2925,2947,2970,2992, 3015,3037,3059,3081,3102,3124,3145,3166,3187,3208, 3229,3249,3269,3290,3309,3329,3349,3368,3387,3406, 3425,3443,3462,3480,3498,3515,3533,3550,3567,3584, 3600,3617,3633,3648,3664,3679,3694,3709,3724,3738, 3752,3766,3780,3793,3806,3819,3831,3843,3855,3867, 3878,3890,3900,3911,3921,3931,3941,3950,3960,3968, 3977,3985,3993,4001,4008,4015,4022,4029,4035,4041, 4046,4052,4057,4061,4066,4070,4074,4077,4080,4083, 4086,4088,4090,4092,4093,4094,4095,4095,4095,4095, 4094,4093,4092,4091,4089,4087,4084,4082,4079,4075, 4072,4068,4064,4059,4054,4049,4044,4038,4032,4026, 4019,4012,4005,3997,3989,3981,3973,3964,3955,3946, 3936,3926,3916,3906,3895,3884,3873,3861,3849,3837, 3825,3812,3799,3786,3773,3759,3745,3731,3717,3702, 3687,3672,3656,3641,3625,3608,3592,3575,3559,3541, 3524,3507,3489,3471,3453,3434,3416,3397,3378,3358, 3339,3319,3300,3280,3259,3239,3218,3198,3177,3156, 3134,3113,3091,3070,3048,3026,3004,2981,2959,2936, 2913,2891,2868,2844,2821,2798,2774,2751,2727,2703, 2679,2655,2631,2607,2583,2559,2534,2510,2485,2460, 2436,2411,2386,2361,2336,2312,2287,2262,2237,2211, 2186,2161,2136,2111,2086,2061,2035,2010,1985,1960, 1935,1910,1885,1859,1834,1809,1784,1760,1735,1710, 1685,1660,1636,1611,1586,1562,1537,1513,1489,1465, 1441,1417,1393,1369,1345,1322,1298,1275,1252,1228, 1205,1183,1160,1137,1115,1092,1070,1048,1026,1005, 983,962,940,919,898,878,857,837,816,796, 777,757,738,718,699,680,662,643,625,607, 589,572,555,537,521,504,488,471,455,440, 424,409,394,379,365,351,337,323,310,297, 284,271,259,247,235,223,212,201,190,180, 170,160,150,141,132,123,115,107,99,91, 84,77,70,64,58,52,47,42,37,32, 28,24,21,17,14,12,9,7,5,4, 3,2,1,1,1,1,2,3,4,6, 8,10,13,16,19,22,26,30,35,39, 44,50,55,61,67,74,81,88,95,103, 111,119,128,136,146,155,165,175,185,196, 206,218,229,241,253,265,277,290,303,316, 330,344,358,372,387,402,417,432,448,463, 479,496,512,529,546,563,581,598,616,634, 653,671,690,709,728,747,767,787,806,827, 847,867,888,909,930,951,972,994,1015,1037, 1059,1081,1104,1126,1149,1171,1194,1217,1240,1263, 1286,1310,1333,1357,1381,1405,1429,1453,1477,1501, 1525,1550,1574,1599,1623,1648,1673,1697,1722,1747, 1772,1797,1822,1847,1872,1897,1922,1947,1973,1998, 2023,2048 }; /** * 通過dac生成sin波形 * @param agrc * @param agrv * @return */ static int sin_dac_sample(int agrc, char **agrv){ rt_dac_device_t dac_dev; //打開硬件外設(shè) dac_dev = (rt_dac_device_t)rt_device_find(DAC_DEV_NAME); if (dac_dev == RT_NULL) { rt_kprintf("can't find %s devicern",DAC_DEV_NAME); return -RT_ERROR; } rt_dac_enable(dac_dev, DAC_DEV_CHANNEL); rt_kprintf("begin echo sin wavern"); for (int i = 0; i < 300; ++i) { for (int j = 0; j < sizeof(sin_wave_vaule)/sizeof(rt_uint32_t); ++j) { rt_dac_write(dac_dev, DAC_DEV_CHANNEL, sin_wave_vaule[j]); rt_thread_mdelay(1); } } rt_kprintf("end echo sin wavern"); return 0; } MSH_CMD_EXPORT(sin_dac_sample,dac out sin wave sample)
- 進(jìn)行程序編譯,然后燒錄到開發(fā)板
- 在工程src目錄中,右鍵新建 test_dac.c 文件,文件內(nèi)容如下:
4、測試
- 打開串口工具輸入 ,在finsh 命令行中輸入 sin_dac_sample ,然后回車,現(xiàn)象可看下圖:
到此測試完畢
5、總結(jié)
到此 DAC 測試已經(jīng)完畢,感覺在本次測試下來的很順利,開發(fā)速度非常塊,需要簡單的幾個(gè)配置,就可以將DAC使用起來。
附錄
sin.py
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0,1,512)
y = (np.sin(2*np.pi*t) * 2047) + 2048
count = 0
for num in np.round(y):
print("%d" % num, end=',')
count = count +1
if count % 10 == 0:
print()
plt.scatter(t,y)
plt.show()
審核編輯 黃宇
-
dac
+關(guān)注
關(guān)注
43文章
2294瀏覽量
191055 -
開發(fā)板
+關(guān)注
關(guān)注
25文章
5050瀏覽量
97469 -
RTThread
+關(guān)注
關(guān)注
8文章
132瀏覽量
40875
發(fā)布評論請先 登錄
相關(guān)推薦
評論