如何使用esp32 ulp中断脉冲计数器和周期性唤醒深度睡眠模式
how to use esp32 ulp interrupt pulse counter and periodic wake up deepsleep mode
我正在尝试使用 dds353 kWh 仪表测量用电量。该仪表具有脉冲输出。我对使用 esp32 很感兴趣,因为我可以定期通过互联网将数据发送到 nodered dashboard.I 我也对在低功耗模式下使用 esp32 并定期唤醒以通过 mqtt 发送数据非常感兴趣。我已经使用 espressif idf 尝试了 github 中的示例,但我不介意 arduino 等效项。我想做硬件中断,当其中一个 rtc gpio 引脚变高时,计数器会增加,而单独的定时器中断 运行 偶尔会唤醒主要的 xtensia 核心,它从 rtc 获取数据并将其发送过来。我查看了脉冲计数器示例,并且以我有限的知识无法判断中断是在 ulp 处于睡眠模式时触发还是仅在它打开时触发。如果有人能告诉我如何基本上使用 ulp 来计算脉冲,即使它处于睡眠模式并定期唤醒主内核,我也会很高兴。我对 IDF 或 arduino 示例没意见
如果你想在深度睡眠时计算脉搏,你可以使用 ULP。当电路板唤醒并进入正常功耗模式时,ULP 上的代码继续执行。所以当它被唤醒时,它仍然会 运行 ULP 处理器上的计数器,除非你停止 ULP 周期性唤醒定时器,ULP 将保持唤醒并 运行ning 而主要 CPU已激活。
正如您已经提供的那样 checked with this example , it should be pretty close to what you need. The only difference seems to be that the example is set to wake up after a given number of pulses, rather than a fixed amount of time. However it should be easy to change that, by enabling deep sleep wake up from timer.
For the Arduino you could check
一些额外的信息:
ULP 没有 GPIO 中断。因此,您可以使用深度睡眠唤醒存根(在深度睡眠之后 运行s 立即将应用程序从闪存加载到 RAM 之前的一小段代码),您可以增加脉冲计数器变量,然后再次进入睡眠状态。通过这种方式,您可以在很短的时间内 运行 在唤醒存根(大约 13mA)时获得脉冲之间的低功耗 (~5uA) 和中等功耗。
因此,您可以根据自己的具体情况进行试验。
您可以使用 ESP32 中的脉冲计数器 (PCNT) 功能来计算背景中的脉冲数,通过使用相同的理解您可以进行一些周期性的唤醒并读取计数。它也可以配置当计数达到特定阈值并且有很多选项时的事件,
有关获取信息和可用接口以及API 脉冲计数器 (PCNT) 的信息,请遵循以下 link、https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/pcnt.html
Initially I faced lot of issue to make Pulse Counter(PCNT) work in Adrino IDE for ESP-32, After multiple attempt I make it working, And same sample code is uploaded in GitHub for reference. I have not use all the API's in the official documentation but but used few of them and are working..
我制作了一个水流量计的示例程序,我们也用它来获取脉冲,需要计数来测量水流量,理解类似于千瓦时表。
GitHub 示例代码路径:- https://github.com/Embedded-Linux-Developement/Arduino_Sample_Programs/tree/main/ESP_32/Water_Flow_Pulse_counter_WithOut_Interrupt_Using_PCNT
我没有把代码放在这里,因为它在 GitHub 中,不是直接针对所问的问题,而是一个明喻,可以使用它。它是我在 HW 中测试的有效代码。
希望对你有帮助,
此致,杰瑞·詹姆斯
我正在尝试使用 dds353 kWh 仪表测量用电量。该仪表具有脉冲输出。我对使用 esp32 很感兴趣,因为我可以定期通过互联网将数据发送到 nodered dashboard.I 我也对在低功耗模式下使用 esp32 并定期唤醒以通过 mqtt 发送数据非常感兴趣。我已经使用 espressif idf 尝试了 github 中的示例,但我不介意 arduino 等效项。我想做硬件中断,当其中一个 rtc gpio 引脚变高时,计数器会增加,而单独的定时器中断 运行 偶尔会唤醒主要的 xtensia 核心,它从 rtc 获取数据并将其发送过来。我查看了脉冲计数器示例,并且以我有限的知识无法判断中断是在 ulp 处于睡眠模式时触发还是仅在它打开时触发。如果有人能告诉我如何基本上使用 ulp 来计算脉冲,即使它处于睡眠模式并定期唤醒主内核,我也会很高兴。我对 IDF 或 arduino 示例没意见
如果你想在深度睡眠时计算脉搏,你可以使用 ULP。当电路板唤醒并进入正常功耗模式时,ULP 上的代码继续执行。所以当它被唤醒时,它仍然会 运行 ULP 处理器上的计数器,除非你停止 ULP 周期性唤醒定时器,ULP 将保持唤醒并 运行ning 而主要 CPU已激活。
正如您已经提供的那样 checked with this example , it should be pretty close to what you need. The only difference seems to be that the example is set to wake up after a given number of pulses, rather than a fixed amount of time. However it should be easy to change that, by enabling deep sleep wake up from timer.
For the Arduino you could check
一些额外的信息:
ULP 没有 GPIO 中断。因此,您可以使用深度睡眠唤醒存根(在深度睡眠之后 运行s 立即将应用程序从闪存加载到 RAM 之前的一小段代码),您可以增加脉冲计数器变量,然后再次进入睡眠状态。通过这种方式,您可以在很短的时间内 运行 在唤醒存根(大约 13mA)时获得脉冲之间的低功耗 (~5uA) 和中等功耗。
因此,您可以根据自己的具体情况进行试验。
您可以使用 ESP32 中的脉冲计数器 (PCNT) 功能来计算背景中的脉冲数,通过使用相同的理解您可以进行一些周期性的唤醒并读取计数。它也可以配置当计数达到特定阈值并且有很多选项时的事件,
有关获取信息和可用接口以及API 脉冲计数器 (PCNT) 的信息,请遵循以下 link、https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/pcnt.html
Initially I faced lot of issue to make Pulse Counter(PCNT) work in Adrino IDE for ESP-32, After multiple attempt I make it working, And same sample code is uploaded in GitHub for reference. I have not use all the API's in the official documentation but but used few of them and are working..
我制作了一个水流量计的示例程序,我们也用它来获取脉冲,需要计数来测量水流量,理解类似于千瓦时表。
GitHub 示例代码路径:- https://github.com/Embedded-Linux-Developement/Arduino_Sample_Programs/tree/main/ESP_32/Water_Flow_Pulse_counter_WithOut_Interrupt_Using_PCNT
我没有把代码放在这里,因为它在 GitHub 中,不是直接针对所问的问题,而是一个明喻,可以使用它。它是我在 HW 中测试的有效代码。
希望对你有帮助, 此致,杰瑞·詹姆斯