Entropy library prevents sleep?

Hi,

I'm using this entropy library.

It seems to prevent my attiny85 from going into SLEEP_MODE_PWR_DOWN.

While using the entropy library I can get down to 4mA, if I take out the library, I can get down to .40 mA, which is about what I expect. My project is a Chess960 position generator, so it's important that I can get a random number. Otherwise the random chess position will be the same every time!

Is anyone familiar with this library, or know why it might prevent my attiny85 from powering down?

I'm including

#include <avr/power.h>
#include <avr/sleep.h>

and my sleep code looks like this:

for (byte i = 0; i <= 5; i++){
    pinMode(i, INPUT);
    digitalWrite(i, LOW);
}
ADCSRA = 0;
power_all_disable();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu();

Any help greatly appreciated.

Jimmy

While using the entropy library I can get down to 4mA, if I take out the library, I can get down to .40 mA, which is about what I expect.

This does not make sense. While using the library, you get lower power consumption. But, you are complaining.

I guess some people are just never happy.

I thought 4mA is larger thatn .40 mA? No?

Anyway I see that this:

cli();

before

sleep_enable();

gets me back to about .40 mA.

If I don't understand the relative values when referring to current, please enlighten me.

Thanks Paul.

Jimmy

I thought 4mA is larger thatn .40 mA? No?

No, 4 is not larger than 40.

On the other hand, 4 is more than 0.40.

Fractional values less than one ALWAYS have a leading 0.

OK. Point taken. Thanks.

...it's important that I can get a random number.

Of what quality?

It needs to be pretty good. There are 960 starting positions and I'd like it to seem random. Since I power down the MCU, and then pull RESET low to get the next position, if I just use a psuedo-random number, it gives the same position every time. I have done something else In the past (that i saw here) where I store a seed in EEPROM and increment that each time the program runs.

That works ok, and looks random-ish.

Jimmy

mixographer:
It needs to be pretty good.

Maybe I can get a response using a different question... Is money involved?

I have done something else In the past (that i saw here) where I store a seed in EEPROM and increment that each time the program runs.

Like this...

http://forum.arduino.cc/index.php?topic=66206.0
http://forum.arduino.cc/index.php?topic=66206.msg537783#msg537783

Oh. No, there is no money involved, I'm just entertaining myself. It's just starting positions for chess. I'll try your method from those posts.

Thanks for the info!

Jimmy

I know that the Java "SecureRandom" class works by starting up a number of threads and timing them. Could this entropy library be doing the same thing? Starting up some processor threads (or an equivalent - yeah I know the AVR is single threaded but I'm looking for clues).

Perhaps the entropy library has a specific "stop doing whatever it is you do for the time being" that you might need to call.

mixographer:
If I just use a psuedo-random number, it gives the same position every time.

One way to go is to have a "press any key to start the game!" and to time how long the any key takes to be pressed (just use the get microsecond function).

Or you could investigate a hardware solution. Find a source of noise. Sample it and take the samples as pairs of bits. If the two bits of a pair are the same, discard them. Otherwise take (say) the first bit. This process turns noise into a fair coin toss.

Actually - this is something that the electronics guys might be interested in tackling.

PaulMurrayCbr:
I know that the Java "SecureRandom" class works by starting up a number of threads and timing them.

You most certainly have gotten that detail wrong. That "method" is reminiscent of the nasty Netscape SSL bug.

Could this entropy library be doing the same thing?

Timer jitter...

Hmm. Well, it's all down to the implementation of

https://docs.oracle.com/javase/8/docs/api/java/security/SecureRandomSpi.html

in whatever java platform you happen to be using.