Nah, some MCUs have low power modes.
ESP32 has 5 of them, from disabling fancy features, throttling the clock, even delegating to an ultra low power coprocessor, or just going to sleep until a pin wakes it up again. It can go from 240mA to 150uA and still process things, or sleep for only 5uA.
This should be the new isEven()/isOdd(). Calculate the speed of the CPU and use that to determine how long it might take to achieve a 'sleep' of a required time.
I took an embedded hardware class where specifically we were required to manually calculate our sleeps or use interrupts and timers rather than using a library function to do it for us.
This was in 1985, on a ABC80, a Swedish computer with a 3 MHz CPU. So, in theory it would be much faster, but I assume there were many performance losses (slow basic interpretor and thing like that) so that for loop got close enough to a second for us to use.
32 Comments
EisFrei@lemmy.world · 90 pts · 2y
Ah yes. The speedup-loop.
https://thedailywtf.com/articles/The-Speedup-Loop
tryptaminev@feddit.de · 21 pts · 2y
This is brilliant.
bangupjobasusual@sh.itjust.works · 81 pts · 2y
I think some compilers will just drop that in the optimization step.
ryannathans@aussie.zone · 27 pts · 2y
Real pain in the ass when you're in embedded and your carefully placed NOPs get stripped
vrighter@discuss.tchncs.de · 5 pts · 2y
asm("nop");
wreckedcarzz@lemmy.world · 16 pts · 2y
Homer: "oh yeah speed
holessleep"jaybone@lemmy.world · 3 pts · 2y
Sleep holes
Darkassassin07@lemmy.ca · 67 pts · 2y
Tell the CPU to wait for you?
Na, keep the CPU busy with useless crap till you need it.
jaybone@lemmy.world · 28 pts · 2y
Fuck those other processes. I want to hear that fan.
leclownfou@sh.itjust.works · 5 pts · 2y
I paid good money for my fan, I want to know it's working!
kogasa@programming.dev · 23 pts · 2y
Have you considered a career in middle management
aksdb@lemmy.world · 26 pts · 2y
On microcontrollers that might be a valid approach.
kevincox@lemmy.ml · 11 pts · 2y
I've written these cycle-perfect sleep loops before.
It gets really complicated if you want to account for time spent in interrupt handlers.
aksdb@lemmy.world · 2 pts · 2y
Thankfully I didn't need high precision realtime. I just needed to wait a few seconds for serial comm.
Darkassassin07@lemmy.ca · 1 pts · 2y
But then I gotta buy a space heater too...
YIj54yALOJxEsY20eU@lemm.ee · 4 pts · 2y
Microcontrollers run 100% of the time even while sleeping.
towerful@programming.dev · 4 pts · 2y
Nah, some MCUs have low power modes.
ESP32 has 5 of them, from disabling fancy features, throttling the clock, even delegating to an ultra low power coprocessor, or just going to sleep until a pin wakes it up again. It can go from 240mA to 150uA and still process things, or sleep for only 5uA.
YIj54yALOJxEsY20eU@lemm.ee · 3 pts · 2y
Nah, Sleeping != Low power mode. The now obsolete ATmega328 has a low power mode.
Matty_r@programming.dev · 12 pts · 2y
This should be the new isEven()/isOdd(). Calculate the speed of the CPU and use that to determine how long it might take to achieve a 'sleep' of a required time.
henfredemars@infosec.pub · 11 pts · 2y
I took an embedded hardware class where specifically we were required to manually calculate our sleeps or use interrupts and timers rather than using a library function to do it for us.
drmoose@lemmy.world · 10 pts · 2y
Javascript enters chat:
Which is somehow even worse.
sbv@sh.itjust.works · 4 pts · 2y
As someone who likes to use the CPU, I don't think it's worse.
KairuByte@lemmy.dbzer0.com · 2 pts · 2y
I mean, it’s certainly better than pre-2015.
vcmj@programming.dev · 9 pts · 2y
Its a thing. https://en.m.wikipedia.org/wiki/Busy_waiting
ExtraMedicated@lemmy.world · 5 pts · 2y
I actually remember the teacher having us do this in high school. I tried it again a few years later and it didn't really work anymore.
snaggen@programming.dev · 13 pts · 2y
On my first programming lesson, we were taught that 1 second sleep was
for i = 1 to 1000😀, computers was not that fast back then...aBundleOfFerrets@sh.itjust.works · 3 pts · 2y
I mean maybe in an early interpreted language like BASIC… even the Intel 8086 could count to 1000 in a fraction of a second
snaggen@programming.dev · 5 pts · 2y
This was in 1985, on a ABC80, a Swedish computer with a 3 MHz CPU. So, in theory it would be much faster, but I assume there were many performance losses (slow basic interpretor and thing like that) so that for loop got close enough to a second for us to use.
https://en.m.wikipedia.org/wiki/ABC_80
Socsa@sh.itjust.works · 4 pts · 2y
You gotta measure the latency of the first loop.
lauha@lemmy.one · 3 pts · 2y
I can relate. We have breaks ate work too.
Bronco1676@lemmy.ml · 2 pts · 2y
I just measured it, and this takes 0.17 seconds. And it's really reliable, I added another zero to that number and it was 1.7 seconds
No_Ones_Slick_Like_Gaston@lemmy.world · 0 pts · 2y
Sudo sleep