Pulse Counting and sleeping
Pulse Counting and sleeping
Hi, I'm new to the ESP32 and have been playing with the IDF for the last couple of weeks. I'm trying to get the ESP32 to run for a long time on a couple of cells to take regular measurements (ADC and/or count pulses), log them and then send the data daily.
I have had some trouble understanding the pulse counters and their relationship to the sleep modes. I think the pulse counters sit within the RTC block so I'm assuming that if I deep_sleep with the RTC features enabled then the ULP and PCA's should continue operating?
My use case is a flow meter so I want to count pulses for a very long time!
Many thanks for such a great module!!
-Stuart
I have had some trouble understanding the pulse counters and their relationship to the sleep modes. I think the pulse counters sit within the RTC block so I'm assuming that if I deep_sleep with the RTC features enabled then the ULP and PCA's should continue operating?
My use case is a flow meter so I want to count pulses for a very long time!
Many thanks for such a great module!!
-Stuart
-
- Posts: 9711
- Joined: Thu Nov 26, 2015 4:08 am
Re: Pulse Counting and sleeping
No, sorry, the pulse counter is in the digital domain. You may be able to use the ULP to keep track of pulses, however.
Re: Pulse Counting and sleeping
Many thanks, ESP_Sprite.
OK, that's a little disappointing. The pulse counters look pretty awesome - shame it looks like they're too power hungry to be used in a battery powered sensor.
You say the ULP can be used - would that be polling the GPIO / ADC or some kind of GPIO interrupt? I didn't think the ULP could run on interrupt.
Thanks for any help, I'm pretty sure I'm not the only person who would want to do this.
-Stuart
OK, that's a little disappointing. The pulse counters look pretty awesome - shame it looks like they're too power hungry to be used in a battery powered sensor.
You say the ULP can be used - would that be polling the GPIO / ADC or some kind of GPIO interrupt? I didn't think the ULP could run on interrupt.
Thanks for any help, I'm pretty sure I'm not the only person who would want to do this.
-Stuart
Re: Pulse Counting and sleeping
ULP doesn't have GPIO interrupts.
One way of implementing what you need is to use GPIO-triggered wakeup from deep sleep (that's one of the supported wakeup modes).
Depending on the pulse length/frequency this option may be viable or not...
In deep sleep wake stub (small piece of code which runs immediately after deep sleep, prior to loading application from flash into RAM) you can increment the pulse counter variable, and go to sleep again. This way you can get low power consumption (~6uA) between pulses and moderate power consumption while running the wake stub (around 15mA), for a very short time.
One way of implementing what you need is to use GPIO-triggered wakeup from deep sleep (that's one of the supported wakeup modes).
Depending on the pulse length/frequency this option may be viable or not...
In deep sleep wake stub (small piece of code which runs immediately after deep sleep, prior to loading application from flash into RAM) you can increment the pulse counter variable, and go to sleep again. This way you can get low power consumption (~6uA) between pulses and moderate power consumption while running the wake stub (around 15mA), for a very short time.
Re: Pulse Counting and sleeping
I have created an example which illustrates deep sleep'ing and counting low pulses on GPIO0:
https://gist.github.com/igrr/54f7fbe051 ... d7fbecfeab
Comments are welcome. If there is positive feedback we will add this example to the ESP-IDF.
Each time you press "Boot" button (which brings GPIO0 low), ESP32 will wake up, increment a counter, and go back to sleep. Once the counter reaches certain number, application will start up.
Application can then connect to WiFi and send data somewhere, for example (not shown in this sample).
https://gist.github.com/igrr/54f7fbe051 ... d7fbecfeab
Comments are welcome. If there is positive feedback we will add this example to the ESP-IDF.
Each time you press "Boot" button (which brings GPIO0 low), ESP32 will wake up, increment a counter, and go back to sleep. Once the counter reaches certain number, application will start up.
Application can then connect to WiFi and send data somewhere, for example (not shown in this sample).
Re: Pulse Counting and sleeping
Another option might be using the pulse as the rtc clock input at the peril of getting stuck sleeping if the pulses stop.
Interested to know power consumption vs pulse rate and max possible pulse rate. Also can you post ulp template next?ESP_igrr wrote:I have created an example which illustrates deep sleep'ing and counting low pulses on GPIO0
Re: Pulse Counting and sleeping
Wow! Super support, I wasn't expecting code!
I'll give the deep-sleep pulse counting a whirl. The pulse frequency changes depending on location and consumption; pulse length can be constant (electronic meter) or changing (mechanical meter). So I'll have to build a current profile with a variety of conditions to see if it's viable.
But thank you very much for your assistance.
-Stuart
I'll give the deep-sleep pulse counting a whirl. The pulse frequency changes depending on location and consumption; pulse length can be constant (electronic meter) or changing (mechanical meter). So I'll have to build a current profile with a variety of conditions to see if it's viable.
But thank you very much for your assistance.
-Stuart
- ESP_krzychb
- Posts: 400
- Joined: Sat Oct 01, 2016 9:05 am
- Contact:
Re: Pulse Counting and sleeping
Very informative, neat example.I have created an example which illustrates deep sleep'ing and counting low pulses on GPIO0:
Thank you!
Re: Pulse Counting and sleeping
Current is 5uA in sleep phase and 13mA in active phase (which is possible to reduce by lowering the APB/CPU frequencies from 40 down to 2MHz at the entry of the wake stub... but i need to merge some register header files into the IDF first).Interested to know power consumption vs pulse rate and max possible pulse rate. Also can you post ulp template next?
Also it is possible to fake an edge trigger by changing the wakeup mode in the wake stub. First set trigger on low level, upon wakeup change that to high level, and go to sleep immediately. This will probably reduce active phase time significantly. Also for the real-world use case you will probably remove all the printf's and disable UART output using a bootstrapping pin.
Re ulp template: some fixes to ULP instruction macros to be merged soon, along with an example.
Re: Pulse Counting and sleeping
Yes that is interesting. How long does it take to execute wake stub and sleep (with no UART)?ESP_igrr wrote:Current is 5uA in sleep phase and 13mA in active phase (which is possible to reduce by lowering the APB/CPU frequencies from 40 down to 2MHz at the entry of the wake stub... but i need to merge some register header files into the IDF first).Interested to know power consumption vs pulse rate and max possible pulse rate. Also can you post ulp template next?
Also it is possible to fake an edge trigger by changing the wakeup mode in the wake stub. First set trigger on low level, upon wakeup change that to high level, and go to sleep immediately. This will probably reduce active phase time significantly. Also for the real-world use case you will probably remove all the printf's and disable UART output using a bootstrapping pin.
Re ulp template: some fixes to ULP instruction macros to be merged soon, along with an example.
Macros still? I thought binutils for ulp is ready?
Who is online
Users browsing this forum: No registered users and 67 guests