在线时间543 小时
UID1650185
注册时间2017-4-19
NXP金币724
TA的每日心情 | 怒 2021-1-28 20:09 |
---|
签到天数: 317 天 连续签到: 1 天 [LV.8]以坛为家I
金牌会员
 
- 积分
- 9415
- 最后登录
- 2022-5-12
|
本帖最后由 小马哥-1650185 于 2018-1-11 19:01 编辑
随便瞎玩的。。。
本测试基于官方sdk的 dmic_dam例程,增加了oled驱动,和fft算法。。。。
下来显示个图片玩玩吧
然后进入频谱章节。。。。。。
大概就是这样子喽,声音通过数字麦克采集,54114 开启dma 采集128个点,然后进入fft运算,得到声音信号中的不同频率成分,送oled显示
串口打印信息如下:
其实挺简单的,没什么,就是在调试oeld 驱动时候花了一些时间
oled io配置
- typedef struct {
- uint8_t port;
- uint8_t pin;
- uint32_t modefunc;
- bool init_state;
- } SPI_BB_IO_T;
- gpio_pin_config_t oled_config = {
- kGPIO_DigitalOutput, 0,
- };
- static const SPI_BB_IO_T bb_io[] = {
- { 1, 1, (IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGITAL_EN), true }, // SPI SSEL
- { 0, 19, (IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGITAL_EN), false }, // SPI SCK
- { 0, 20, (IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGITAL_EN), false }, // SPI MOSI
- { 1, 15, (IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGITAL_EN), true }, // OLED DATA/CMD
- { 1, 14, (IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGITAL_EN), true }, // OLED nRESET
- { 1, 12, (IOCON_FUNC0 | IOCON_MODE_PULLUP | IOCON_DIGITAL_EN), false }, // OLED VPP control
- };
- static const uint32_t bb_io_ct = sizeof(bb_io) / sizeof(SPI_BB_IO_T);
- static void init_pinmux(void)
- {
- uint32_t i;
- for (i=0; i<bb_io_ct; i++) {
- IOCON_PinMuxSet(IOCON, bb_io[i].port, bb_io[i].pin, bb_io[i].modefunc);
- }
- }
- static void init_gpio(void)
- {
- uint32_t i;
- for (i=0; i<bb_io_ct; i++) {
- GPIO_PinInit(GPIO, bb_io[i].port, bb_io[i].pin, &oled_config);
- // GPIO->DIR[bb_io[i].port] |= 1UL << bb_io[i].pin;
- GPIO_PinWrite(GPIO, bb_io[i].port, bb_io[i].pin, bb_io[i].init_state);
- }
- }
复制代码
oled 相关寄存器
- static uint8_t init_seq[] = {
- 0xae, // Display OFF
- 0xd5, // Set D-clock
- 0x50, // 100Hz
- 0x20, // Set row address
- 0x81, // Set contrast control
- 0xc0,
- 0xa0, // Segment remap
- 0xa4, // Set Entire Display ON
- 0xa6, // Normal display
- 0xad, // Set external VPP
- 0x80,
- 0xc0, // Set Common scan direction
- 0xd9, // Set phase length
- 0x25,
- 0xdb, // Set Vcomh voltage
- 0x28, // 0.687*VPP
- // 0xaf // Display ON
- };
复制代码
自己写的一些方法。。。
- void OLED_Draw_Point(int32_t x1,int32_t y1, uint16_t color);
- uint16_t OLED_Get_Point_Vaule( int x1, int y1);
- void OLED_Clear (uint16_t color);
- void OLED_Clear_Fbp( unsigned short color);
- void OLED_Draw_Line(int x1,int y1,int x2,int y2, uint16_t color);
- void OLED_Draw_Line_1(int x1, int y1, int x2, int y2, uint16_t color);
- void OLED_Draw_box(int x1, int y1,int x2,int y2, unsigned short color);
- void OLED_Draw_Rectangle(int x1, int y1, int x2, int y2, uint16_t color);
- void OLED_Darw_Circle(int xc, int yc,int r, uint16_t color, int fill);
- void OLED_Darw_Circle_1( int cx, int cy, int radius, uint16_t color, int fill);
- void OLED_fill_Box(int x1,int y1,int x2,int y2, uint16_t color);
- void OLED_Darw_BAR(int x0,int y0,int w,float data,int data_max,int h_max, uint16_t color);
- void OLED_Move_BAR(int x,int y,int w,int num,int len,float* data,int data_max,int h_max, uint16_t color);
- void OLED_Move_BAR_dynamic(int x,int y,int w,int num,int len,float* data,float* data_old,int data_max,int h_max, uint16_t color);
- void OLED_Draw_wave(int x,int y,int data_max, short h_max, uint16_t * p, unsigned short color);
- void OLED_Show_Char(int x,int y,uint16_t font,uint16_t color,uint16_t backcolor,uint8_t num);
- void OLED_Show_String( int x,int y,uint16_t font,uint16_t color,uint16_t backcolor, char *p);
- void OLED_Show_HZ_Char(int x,int y,uint16_t font,uint16_t color,uint16_t backcolor,uint16_t num);
- void OLED_Show_HZ_String( int x,int y,uint16_t font,uint16_t color,uint16_t backcolor,unsigned char *p);
- void OLED_Printf( int x,int y,uint16_t font,uint16_t color,uint16_t backcolor, char *p);
- void OLED_Draw_Image(int x, int y, uint16_t color,uint16_t backcolor, const unsigned char* pic_array);
复制代码
主循环代码
- while (1)
- {
- if(dmic_hwvad_ok == true)
- {
- // OLED_Clear(0);
- dmic_hwvad_ok= false;
- DMIC_TransferReceiveDMA(DMIC0, &g_dmicDmaHandle, &receiveXfer, APP_DMIC_CHANNEL);
-
- if(g_Transfer_Done == true)
- {
- g_Transfer_Done = false;
- PRINTF("Transfer completed\r\n");
- PRINTF("----DMIC----From----DMA------To------CPU:\r\n");
- for (i = 0; i < BUFFER_LENGTH; i++)
- {
- PRINTF("%5d , ", g_rxBuffer[i]);
- if(((i!=0)&&((i+1)%8 == 0)) ||(i ==BUFFER_LENGTH-1 )) PRINTF("\r\n");
- }
- PRINTF("\r\n--------------------M.G.F----------------------\r\n");
- }
-
- // OLED_Draw_wave(0,63,65536,63,g_rxBuffer_old,BLACK);
- // OLED_Draw_wave(0,0,65536,63,g_rxBuffer,WHITE);
- // memcpy(g_rxBuffer_old,g_rxBuffer,sizeof(g_rxBuffer));
- //把数据送入结构体comp对象的实部,虚部等于零.
- for(uint8_t j=0;j<FFT_N;j++)
- {
- //实部初始化为需要fft变换的数据
- DMIC_Buffer[j].real= g_rxBuffer[j]>>4;
- //虚部初始化为0
- DMIC_Buffer[j].imag= 0;
- }
-
- FFT(DMIC_Buffer);//fft变换
- fft_result(DMIC_Buffer);//求分次谐波模值存入复数的实部
- THD_signle(DMIC_Buffer,DMIC_Voltage);//分次谐波值
- PRINTF("----FFT----FFT----FFT------\r\n");
- for (i = 0; i < 128; i++)
- {
- PRINTF("%05d, ", (unsigned int)DMIC_Buffer[i].real);
- if(((i!=0)&&((i+1)%8 == 0)) ||(i ==128-1 )) PRINTF("\r\n");
- }
- PRINTF("----FFT----FFT----FFT------\r\n");
-
- OLED_Move_BAR(2,100,2,62,125,DMIC_Voltage+2,100,80, WHITE);
-
- OLED_Update_Display();
- }
-
- }
复制代码
最后附上hex文件吧,有官方板子的可以下进去玩玩
lpc54114_oled_ frequency spectrum.rar
(30.42 KB, 下载次数: 3)
|
|