Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM8L: implement BG task with the RTC and Wakeup-Timer peripherial #375

Closed
TG9541 opened this issue Oct 30, 2020 · 13 comments
Closed

STM8L: implement BG task with the RTC and Wakeup-Timer peripherial #375

TG9541 opened this issue Oct 30, 2020 · 13 comments
Assignees

Comments

@TG9541
Copy link
Owner

TG9541 commented Oct 30, 2020

During an exploration of the STM8L LSE and RTC features I got the following idea:

It may be possible to substitute the TIMx in the STM8 eForth with the "Wakup timer". That would have the advantage that "Active halt" can be used for applications when the console is not needed. Another application would be a BG like feature for the RTC "Alarm A" event. As it uses the same interrupt is the "Wakeup timer" the BG context could be used twice. A possible way for implementing that is refactoring the BG context switch code so that it can be replaced in STM8L applications.

In order to do this the BG task code, including timer initialization, should be factored out of forth.asm so that the option HAS_BACKGROUND can be used for words that need to be "BG-aware".

@TG9541 TG9541 self-assigned this Oct 30, 2020
@TG9541 TG9541 changed the title STM8L: implement the BG with the RTC and Wakeup-Timer peripherial STM8L: implement BG task with the RTC and Wakeup-Timer peripherial Oct 30, 2020
@TG9541
Copy link
Owner Author

TG9541 commented Nov 3, 2020

I have a POC with the Wakup-Timer running the background task.

An STM8L051F3 with a 10ms background task and my experimental low power console draws a supply current below 20µA.

image

The spikes starting just before "+1000" in the DEB1 line show the 'IDLE task going back to HALT, waiting for the next console input or for the next Wakeup-Timer event.

@TG9541
Copy link
Owner Author

TG9541 commented Nov 5, 2020

I put the code and a description of the solution into the Gist STM8L051F3: Experimenting with a low-power console .

There is no reason why this shouldn't work with the STM8S AWU peripheral and the 128kHz LSI. Power consumption is expected to be a bit higher but still in the useful range for battery powered applications.

@TG9541 TG9541 closed this as completed Nov 5, 2020
@happytm
Copy link

happytm commented Jul 14, 2022

Thank you for your excellent work. I would like to create low power solution for a project where IR receiver is used as a wakeup source like circuit described in last page of following link:

https://www.vishay.com/docs/80067/appoverview.pdf

Is it possible?
Thanks.

@VK6TT
Copy link
Collaborator

VK6TT commented Jul 14, 2022 via email

@TG9541
Copy link
Owner Author

TG9541 commented Jul 14, 2022

@happytm as @VK6TT already confirmed that's possible. Low power applications require a fair share of experimenting - independent of the programming language used.

The IR receiver you mention has a specified supply current of 350µA and a standby current of 3.5µA (in the same order as a well tuned STM8L chip). This means that for operation with a small battery (e.g., an LR2032) your application should "know" when to look for a signal. Otherwise the battery life would have to be measured in hours, not months).

@happytm
Copy link

happytm commented Jul 14, 2022

@VK6TT and @TG9541 Thank you for you valuable feedback. I think just like app note I would wake STM8L chip for 2 ms and let it sleep for 200 ms. The IR transmission should start with pre-burst of minimum of 202 ms from another mains powered device within few meters with line of sight. That way battery powered never misses IR command from mains powered device.

Thank again.

@TG9541
Copy link
Owner Author

TG9541 commented Jul 14, 2022

@happytm that sounds like a good plan. The overall power consumption might well be within 20µA which means about 1 year of operation from a humble LR2032.
As a hint: a particularly power conserving mode of operation would be the following:

  1. active halt
  2. WUT interrupt 200ms
  3. set IR receiver active
  4. set WUT 2ms
  5. active halt
  6. a) WUT interrupt 2ms, or b) pin-change-interrupt from IR receiver, decode signal
  7. set IR receiver stand-by
  8. set WUT 198ms
  9. active halt -> 2.

It might even be possible to use the pin change interrupt for decoding the signal

@happytm
Copy link

happytm commented Jul 14, 2022

@TG9541 Thank you for your suggestions. I just found out about your repository couple of days ago so I am still reading all your material available and try to understand everything.

@VK6TT
Copy link
Collaborator

VK6TT commented Jul 15, 2022 via email

@happytm
Copy link

happytm commented Jul 15, 2022

Thank you Richard for the code.

@happytm
Copy link

happytm commented Jul 15, 2022

@TG9541 & @VK6TT I have been playing with low power sensor network using 802.11 wifi communication using ESP32 for quite some time and I have created good working proof of concept at:
https://github.com/happytm/BatteryNode/blob/master/examples/test/802.11_Gateway.ino
https://github.com/happytm/BatteryNode/blob/master/examples/test/802.11_remote_battery.ino
https://github.com/happytm/BatteryNode/blob/master/examples/test/802.11_remote_mains.ino

In theory 802.11_remote_battery.ino code is very efficient for conserving battery power (LIR2450 - 100 mAh). If there is enough sleep time for remote sensor battery can last long time. Remote sensors send their data at predefined interval but sometimes Gateway or remote_mains device need sensor data from remote_battery device urgently then gateway or remote_mains can send IR code and this IR circuit can wakeup the remote_battery device before it's predefined wake up time to send sensor data either by transmitting IR code or in case of ESP32 device by sending 802.11 frame.

This is my planned use case.
Thanks.

@TG9541
Copy link
Owner Author

TG9541 commented Jul 15, 2022

@VK6TT thanks for the code - I've added a link to the Wiki example code page (it might be worth putting that into a GitHub Gist).

  • a word like (pause) that also accepts a pause time value would make "pausing" even easier
  • the Forth Standard words DEFER .. IS (in the library since 2.2.29) makes adding changeable "task code" really easy (e.g., in stm8ef-modbus declare handler and define handler)

@TG9541
Copy link
Owner Author

TG9541 commented Jul 15, 2022

@TG9541 & @VK6TT I have been playing with low power sensor network using 802.11 wifi communication using ESP32 for quite some time and I have created good working proof of concept ...
This is my planned use case. Thanks.

That's interesting - using IR for waking up RF communication. I've once thought about an IR only "very-low-bandwitdh opportunistic" network that operates more like a slow-motion swarm of fireflies than like a military operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants