完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,我正在尝试在 IDF 5.0 引入的连续模式中使用 ADC,但是我在 adc_continuous_config_t 中指定的采样率与我实际得到的不相关。这是我正在运行的代码:
代码: #include #include "esp_timer.h" #include "freertos/FreeRTOS.h" #include #include #include #define SAMPLE_RATE 40000 adc_continuous_handle_t adcHandle = NULL; std::atomic_uint32_t sampleCount; void printSampleRateTask(void *arg) { uint32_t samplesPerSecond = sampleCount.exchange(0, std::memory_order_acq_rel); printf("Time: %lld, samples per second: %lun", esp_timer_get_time(), samplesPerSecond); } extern "C" void app_main() { adc_continuous_handle_cfg_t handle_cfg = { .max_store_buf_size = 2000, .conv_frame_size = 1000, }; ESP_ERROR_CHECK(adc_continuous_new_handle(&handle_cfg, &adcHandle)); adc_digi_pattern_config_t channel[1] = {}; channel[0].atten = ADC_ATTEN_DB_11; channel[0].channel = 0; channel[0].unit = 0; channel[0].bit_width = SOC_ADC_DIGI_MIN_BITWIDTH; adc_continuous_config_t cfg = { .pattern_num = 1, .adc_pattern = channel, .sample_freq_hz = SAMPLE_RATE, .conv_mode = ADC_CONV_SINGLE_UNIT_1, .format = ADC_DIGI_OUTPUT_FORMAT_TYPE1, }; ESP_ERROR_CHECK(adc_continuous_config(adcHandle, &cfg)); ESP_ERROR_CHECK(adc_continuous_start(adcHandle)); const esp_timer_create_args_t periodic_timer_args = { .callback = &printSampleRateTask, .name = "sampleRate", }; esp_timer_handle_t periodic_timer; ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer)); ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, 1000000)); esp_err_t ret; uint32_t ret_num = 0; uint8_t result[1000] = {0}; while (1) { ret = adc_continuous_read(adcHandle, result, sizeof(result), &ret_num, 1000); if (ret == ESP_OK) { sampleCount += ret_num / SOC_ADC_DIGI_RESULT_BYTES; } else { printf("status: %dn", ret); } } } 这是串行输出的摘录: 代码: Time: 1028996, samples per second: 32500 Time: 2028961, samples per second: 32500 Time: 3028961, samples per second: 33000 Time: 4028961, samples per second: 32500 Time: 5028961, samples per second: 33000 Time: 6028961, samples per second: 32500 Time: 7028961, samples per second: 33000 Time: 8028961, samples per second: 32500 Time: 9028961, samples per second: 32500 Time: 10028961, samples per second: 33000 Time: 11028961, samples per second: 32500 Time: 12028961, samples per second: 33000 Time: 13028961, samples per second: 32500 这就是 IDF 在构建时所说的: 代码: CONFIGURATION: PLATFORM: Espressif 32 (5.3.0+sha.98b1e96) > WEMOS D1 MINI ESP32 HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa) PACKAGES: - framework-espidf @ 3.50000.0 (5.0.0) - tool-cmake @ 3.16.4 - tool-esptoolpy @ 1.40400.0 (4.4.0) - tool-mkfatfs @ 2.0.1 - tool-mklittlefs @ 1.203.210628 (2.3) - tool-mkspiffs @ 2.230.0 (2.30) - tool-ninja @ 1.7.1 - toolchain-esp32ulp @ 1.23500.220830 (2.35.0) - toolchain-xtensa-esp32 @ 11.2.0+2022r1 我试过更改采样率、缓冲区大小以及 max_store_buf_size 和 conv_frame_size,但没有任何组合可以使采样率匹配。我怎样才能让它更精确? |
|
相关推荐
1个回答
|
|
你好!在我使用ESP-IDF 连续读取示例进行的测试中,22050 Hz 的帧率会产生不稳定的值:17920 或 18048 Hz。. . 在我的例子中,生成 22.05 kHz WAV 文件是无用的。. .
|
|
|
|
只有小组成员才能发言,加入小组>>
1143 浏览 1 评论
578浏览 6评论
479浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
463浏览 5评论
464浏览 4评论
440浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 04:20 , Processed in 1.268007 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号