<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>
0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

【英飛凌PSoC 6 RTT開發板試用】語音識別之二:音頻采集

嵌入式USB開發 ? 來源:嵌入式USB開發 ? 作者:嵌入式USB開發 ? 2023-07-11 07:43 ? 次閱讀

一. 音頻采集

原理圖

從原理圖看到有6路模擬輸入,分別對應

P10.0~P10.5, VREF為模擬參考電壓。

image.png

image.png

使用的是MAX4466的MIC,接到ADC0,如下圖所示

image.png

image.png

image.png

配置模擬采集引腳

image.png

代碼

Adc.c

#include "cy_pdl.h"
#include "cyhal.h"
#include "cybsp.h"
#include "cy_retarget_io.h"

#define VPLUS_CHANNEL_0  (P10_0)
/* Conversion factor */
#define MICRO_TO_MILLI_CONV_RATIO        (1000u)

/* Acquistion time in nanosecond */
#define ACQUISITION_TIME_NS              (116680u)

/* ADC Scan delay in millisecond */
#define ADC_SCAN_DELAY_MS                (200u)

/*******************************************************************************
*       Enumerated Types
*******************************************************************************/
/* ADC Channel constants*/
enum ADC_CHANNELS
{
  CHANNEL_0 = 0,
  NUM_CHANNELS
} adc_channel;

/*******************************************************************************
* Global Variables
*******************************************************************************/
/* ADC Object */
cyhal_adc_t adc_obj;

/* ADC Channel 0 Object */
cyhal_adc_channel_t adc_chan_0_obj;

/* Default ADC configuration */
const cyhal_adc_config_t adc_config = {
        .continuous_scanning=false, // Continuous Scanning is disabled
        .average_count=1,           // Average count disabled
        .vref=CYHAL_ADC_REF_VDDA,   // VREF for Single ended channel set to VDDA
        .vneg=CYHAL_ADC_VNEG_VSSA,  // VNEG for Single ended channel set to VSSA
        .resolution = 12u,          // 12-bit resolution
        .ext_vref = NC,             // No connection
        .bypass_pin = NC };       // No connection

/* Asynchronous read complete flag, used in Event Handler */
static bool async_read_complete = true;
#define NUM_SCAN                    (1000)
#define NUM_CHANNELS                (1)
/* Variable to store results from multiple channels during asynchronous read*/
int32_t result_arr[NUM_CHANNELS * NUM_SCAN] = {0};

static void adc_event_handler(void* arg, cyhal_adc_event_t event)
{
    if(0u != (event & CYHAL_ADC_ASYNC_READ_COMPLETE))
    {
        /* Set async read complete flag to true */
        async_read_complete = true;
    }
}

int adc_init(void)
{
    /* Variable to capture return value of functions */
    cy_rslt_t result;

    /* Initialize ADC. The ADC block which can connect to the channel 0 input pin is selected */
    result = cyhal_adc_init(&adc_obj, VPLUS_CHANNEL_0, NULL);
    if(result != CY_RSLT_SUCCESS)
    {
        printf("ADC initialization failed. Error: %ld\\n", (long unsigned int)result);
        CY_ASSERT(0);
    }

    /* ADC channel configuration */
    const cyhal_adc_channel_config_t channel_config = {
            .enable_averaging = false,  // Disable averaging for channel
            .min_acquisition_ns = ACQUISITION_TIME_NS, // Minimum acquisition time set to 1us
            .enabled = true };          // Sample this channel when ADC performs a scan

    /* Initialize a channel 0 and configure it to scan the channel 0 input pin in single ended mode. */
    result  = cyhal_adc_channel_init_diff(&adc_chan_0_obj, &adc_obj, VPLUS_CHANNEL_0,
                                          CYHAL_ADC_VNEG, &channel_config);
    if(result != CY_RSLT_SUCCESS)
    {
        printf("ADC first channel initialization failed. Error: %ld\\n", (long unsigned int)result);
        CY_ASSERT(0);
    }

    /* Register a callback to handle asynchronous read completion */
     cyhal_adc_register_callback(&adc_obj, &adc_event_handler, result_arr);

     /* Subscribe to the async read complete event to process the results */
     cyhal_adc_enable_event(&adc_obj, CYHAL_ADC_ASYNC_READ_COMPLETE, CYHAL_ISR_PRIORITY_DEFAULT, true);

     printf("ADC is configured in multichannel configuration.\\r\\n\\n");
     printf("Channel 0 is configured in single ended mode, connected to the \\r\\n");
     printf("channel 0 input pin. Provide input voltage at the channel 0 input pin \\r\\n");
     return 0;
}

int adc_samp(void)
{
    /* Variable to capture return value of functions */
    cy_rslt_t result;

    /* Variable to store ADC conversion result from channel 0 */
    int32_t adc_result_0 = 0;


        /* Clear async read complete flag */
        async_read_complete = false;

        /* Initiate an asynchronous read operation. The event handler will be called
         * when it is complete. */
        memset(result_arr,0,sizeof(result_arr));
        cyhal_gpio_write_internal(CYBSP_USER_LED,true);
        result = cyhal_adc_read_async_uv(&adc_obj, NUM_SCAN, result_arr);
        if(result != CY_RSLT_SUCCESS)
        {
            printf("ADC async read failed. Error: %ld\\n", (long unsigned int)result);
            CY_ASSERT(0);
        }
        while(async_read_complete == false);
        cyhal_gpio_write_internal(CYBSP_USER_LED,false);
        /*
         * Read data from result list, input voltage in the result list is in
         * microvolts. Convert it millivolts and print input voltage
         *
         */
        for(int i=0; i< NUM_SCAN; i++)
        {
            adc_result_0 = result_arr[i] / MICRO_TO_MILLI_CONV_RATIO;
            printf("/*%4ld*/\\r\\n", (long int)adc_result_0);
        }

    return 0;
}

Adc.h

#ifndef ADC_H
#define ADC_H

int adc_init(void);
int adc_samp(void);

#endif

Main.c調用

adc_init();

adc_samp();

時鐘

時鐘源是100Mhz,12分頻=8.33M,滿足1.8MHz~18MHz之間的要求

默認是按照8M配置

image.png

image.png

采樣時間

采樣前后翻轉LED用示波器測量時間

int adc_samp(void)
{
    /* Variable to capture return value of functions */
    cy_rslt_t result;

    /* Variable to store ADC conversion result from channel 0 */
    int32_t adc_result_0 = 0;


        /* Clear async read complete flag */
        async_read_complete = false;

        /* Initiate an asynchronous read operation. The event handler will be called
         * when it is complete. */
        memset(result_arr,0,sizeof(result_arr));
        cyhal_gpio_write_internal(CYBSP_USER_LED,true);
        result = cyhal_adc_read_async_uv(&adc_obj, NUM_SCAN, result_arr);
        if(result != CY_RSLT_SUCCESS)
        {
            printf("ADC async read failed. Error: %ld\\n", (long unsigned int)result);
            CY_ASSERT(0);
        }
        while(async_read_complete == false);
        cyhal_gpio_write_internal(CYBSP_USER_LED,false);
        /*
         * Read data from result list, input voltage in the result list is in
         * microvolts. Convert it millivolts and print input voltage
         *
         */
        for(int i=0; i< NUM_SCAN; i++)
        {
            adc_result_0 = result_arr[i] / MICRO_TO_MILLI_CONV_RATIO;
            printf("/*%4ld*/\\r\\n", (long int)adc_result_0);
        }

    return 0;
}

采樣1000次,分別設置采樣時間為2uS和1uS對比。

#define ACQUISITION_TIME_NS (2000u)

10.28mS

image.png

#define ACQUISITION_TIME_NS (1000u)

9.32mS

image.png

10.28-9.32=0.96mS 1000次約1mS,1次剛好是1uS。

而1000次除去采樣時間其他時間為8.32mS,即一次8.32uS。

因為前面設置了時鐘為8.33MHz, 從前面時序一節可以看到,除去采樣時間,其他轉換時間等需要14個CLK,所以需要14/8.33uS=1.7uS. 剩余的8.32-1.7為數據搬運,軟件處理等時間。

采樣值正確性

1.545V和示波器采集為1.54V差不多是正確的,這里沒有高精度萬用表就不對測試精度了,只測試了正確性。

image.png

image.png

音頻采集

一次采集1000次然后串口打印,使用SerialStudio可視化顯示

int adc_samp(void)
{
    /* Variable to capture return value of functions */
    cy_rslt_t result;

    /* Variable to store ADC conversion result from channel 0 */
    int32_t adc_result_0 = 0;


        /* Clear async read complete flag */
        async_read_complete = false;

        /* Initiate an asynchronous read operation. The event handler will be called
         * when it is complete. */
        memset(result_arr,0,sizeof(result_arr));
        cyhal_gpio_write_internal(CYBSP_USER_LED,true);
        result = cyhal_adc_read_async_uv(&adc_obj, NUM_SCAN, result_arr);
        if(result != CY_RSLT_SUCCESS)
        {
            printf("ADC async read failed. Error: %ld\\n", (long unsigned int)result);
            CY_ASSERT(0);
        }
        while(async_read_complete == false);
        cyhal_gpio_write_internal(CYBSP_USER_LED,false);
        /*
         * Read data from result list, input voltage in the result list is in
         * microvolts. Convert it millivolts and print input voltage
         *
         */
        for(int i=0; i< NUM_SCAN; i++)
        {
            adc_result_0 = result_arr[i] / MICRO_TO_MILLI_CONV_RATIO;
            printf("/*%4ld*/\\r\\n", (long int)adc_result_0);
        }

    return 0;
}

串口打印到PC,可視化顯示如下

image.png

審核編輯:湯梓紅

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 英飛凌
    +關注

    關注

    65

    文章

    1977

    瀏覽量

    137115
  • PSoC
    +關注

    關注

    12

    文章

    168

    瀏覽量

    91306
  • 音頻
    +關注

    關注

    28

    文章

    2632

    瀏覽量

    80226
  • 語音識別
    +關注

    關注

    38

    文章

    1651

    瀏覽量

    111931
  • 開發板
    +關注

    關注

    25

    文章

    4560

    瀏覽量

    94883
  • RTT
    RTT
    +關注

    關注

    0

    文章

    64

    瀏覽量

    16918
收藏 人收藏

    評論

    相關推薦

    英飛凌PSoC 6】新建RTT工程

    介紹英飛凌PSoC 6 RTT開發板環境創建
    的頭像 發表于 04-24 15:29 ?1533次閱讀
    【<b class='flag-5'>英飛凌</b><b class='flag-5'>PSoC</b> 6】新建<b class='flag-5'>RTT</b>工程

    英飛凌PSoC 6 RTT開發板試用語音識別之一:移植CMSIS-DSP庫-FFT測試

    后面會基于本開發板實現語音識別,需要使用到FFT等關鍵算法,所以先移植CMSIS-DSP庫,并進行FFT的測試。
    的頭像 發表于 07-11 00:10 ?2409次閱讀
    【<b class='flag-5'>英飛凌</b><b class='flag-5'>PSoC</b> 6 <b class='flag-5'>RTT</b><b class='flag-5'>開發板</b><b class='flag-5'>試用</b>】<b class='flag-5'>語音</b><b class='flag-5'>識別</b>之一:移植CMSIS-DSP庫-FFT測試

    英飛凌PSoC? 62開發板 -LCD ILI9341 8080 DEMO

    英飛凌開發板
    rx_ted
    發布于 :2024年03月07日 21:08:39

    【 平頭哥CB5654語音開發板試用連載】智能門禁語音識別

    項目名稱:智能門禁語音識別試用計劃:1、計劃開發一個智能門禁系統,申請理由本人一致工作再電子行業,最近再做一些語音識別和智能家居整合項目,基
    發表于 03-13 16:20

    【大聯大品佳 Nuvoton ISD9160語音識別試用申請】基于大聯大品佳 Nuvoton ISD9160 語音識別開發板的微型冰箱數據采集

    項目名稱:基于大聯大品佳 Nuvoton ISD9160 語音識別開發板的微型冰箱數據采集試用計劃:申請理由本人在本科、碩士及工作階段有8年單片機
    發表于 08-10 17:40

    【1024平頭哥開發套件開發體驗】 語音識別開發板的比較

    隨著語音識別技術的發展,帶有語音識別處理功能的開發板也逐漸豐富起來,目前供用戶進行測評的開發板
    發表于 12-13 00:13

    [CB5654智能語音開發板測評] 語音識別開發板的比較

    隨著語音識別技術的發展,帶有語音識別處理功能的開發板也逐漸豐富起來,目前供用戶進行測評的開發板
    發表于 03-09 08:11

    【新品發布】英飛凌PSoC 6 RTT物聯網開發板內容詳解

    4月12日,英飛凌聯合 RT-Thread 發布PSoC? 62 with CAPSENSE? evaluation kit開發板 (以下簡稱PSoC
    發表于 04-13 13:46

    【資料下載】英飛凌PSoC 6 RTT物聯網開發板

    Infineon Psoc6-evaluationkit-062S2 說明開發板免費試用活動:https://bbs.elecfans.com/jishu_2349212_1_1.html簡介本文
    發表于 04-13 13:38

    【新品試用英飛凌PSoC 6 RTT開發板試用活動

    概述、軟件調試、硬件接入、視頻演示,不少于500字+2張圖片。 2)報告形式:標題格式 【評測活動標題+自擬標題】示例: 【英飛凌PSoC 6 RTT
    發表于 04-13 15:26

    英飛凌PSoC 6 RTT開發板試用

    單周期乘法和MPU,可以充分發揮 PSoC6 雙核芯片性能。 該開發板核心 板載資源 如下: MCU:CY8C624ABZI-S2D44,Cortex-M4主頻 150MHz,Cortex-M0主頻
    發表于 05-30 20:47

    英飛凌PSoC 6 RTT開發板試用】以搭積木方式實現簡單的互聯型家庭網關

    本文基于RT-Studio,采用搭積木的方式實現一個簡單的互聯型家庭網關,采集各類傳感器數據并傳輸至云端。硬件除了Psoc6-evaluationkit-062S2開發板之外,還有一塊RW007
    發表于 05-31 22:19

    英飛凌PSoC 6 RTT開發板試用】+開箱測試

    英飛凌PSoC 6 RTT開發板試用】+開箱測試 硬件資源介紹
    發表于 06-05 01:06

    英飛凌聯合 RT-Thread 發布 PSoC? 62 with CAPSENSE ? evaluation kit開發板

    近日,RT-Thread 社區團隊打造了新品開發板英飛凌聯合 RT-Thread 發布 ?PSoC 62 with CAPSENSE evaluation kit開發板?(以下簡稱
    的頭像 發表于 04-13 01:35 ?1445次閱讀

    玩轉PSoC 6 RTT積木式開發套件,實現毫米波雷達等實用功能

    本期英飛凌手工課,將由來自英飛凌的工程師Jenson給大家帶來PSoC62withCAPSENSEevaluationkit(下稱PSoC6RTT
    的頭像 發表于 03-20 08:35 ?375次閱讀
    玩轉<b class='flag-5'>PSoC</b> 6 <b class='flag-5'>RTT</b>積木式<b class='flag-5'>開發</b>套件,實現毫米波雷達等實用功能
    亚洲欧美日韩精品久久_久久精品AⅤ无码中文_日本中文字幕有码在线播放_亚洲视频高清不卡在线观看
    <acronym id="s8ci2"><small id="s8ci2"></small></acronym>
    <rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
    <acronym id="s8ci2"></acronym>
    <acronym id="s8ci2"><center id="s8ci2"></center></acronym>