Pulse Counting and sleeping

stuartc
Posts: 5
Joined: Tue Feb 28, 2017 11:07 am

Pulse Counting and sleeping

Postby stuartc » Tue Feb 28, 2017 11:16 am

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

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: Pulse Counting and sleeping

Postby ESP_Sprite » Wed Mar 01, 2017 4:24 am

No, sorry, the pulse counter is in the digital domain. You may be able to use the ULP to keep track of pulses, however.

stuartc
Posts: 5
Joined: Tue Feb 28, 2017 11:07 am

Re: Pulse Counting and sleeping

Postby stuartc » Wed Mar 01, 2017 11:46 pm

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

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Pulse Counting and sleeping

Postby ESP_igrr » Fri Mar 03, 2017 3:16 am

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.

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Pulse Counting and sleeping

Postby ESP_igrr » Fri Mar 03, 2017 8:30 am

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).

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Pulse Counting and sleeping

Postby WiFive » Fri Mar 03, 2017 4:07 pm

Another option might be using the pulse as the rtc clock input at the peril of getting stuck sleeping if the pulses stop.
ESP_igrr wrote:I have created an example which illustrates deep sleep'ing and counting low pulses on GPIO0
Interested to know power consumption vs pulse rate and max possible pulse rate. Also can you post ulp template next?

stuartc
Posts: 5
Joined: Tue Feb 28, 2017 11:07 am

Re: Pulse Counting and sleeping

Postby stuartc » Fri Mar 03, 2017 5:06 pm

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

User avatar
ESP_krzychb
Posts: 400
Joined: Sat Oct 01, 2016 9:05 am
Contact:

Re: Pulse Counting and sleeping

Postby ESP_krzychb » Fri Mar 03, 2017 7:44 pm

I have created an example which illustrates deep sleep'ing and counting low pulses on GPIO0:
Very informative, neat example.
Thank you!

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Pulse Counting and sleeping

Postby ESP_igrr » Sat Mar 04, 2017 2:02 am

Interested to know power consumption vs pulse rate and max possible pulse rate. Also can you post ulp template next?
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).

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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Pulse Counting and sleeping

Postby WiFive » Sat Mar 04, 2017 3:06 am

ESP_igrr wrote:
Interested to know power consumption vs pulse rate and max possible pulse rate. Also can you post ulp template next?
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).

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.
Yes that is interesting. How long does it take to execute wake stub and sleep (with no UART)?

Macros still? I thought binutils for ulp is ready?

Who is online

Users browsing this forum: No registered users and 235 guests