Watchdog Timer with Attiny 85

i tried adding PCINT0 as a Pin Change Interrupt to wake up the chip but it made the board go crazy when there is no light.

i have looked in to the attiny 85 data sheet and it looks like you can't use PCINT0 to wake up to a specific voltage. plus photocell (CdS photoresistor) change the voltage depending on the light so i don't think i can use watchdog timer with my circuit to do what i want it to do. =(

Erni:
Take a look at Jack Christensens demo sleep code

Sleep mode demo code - Libraries - Arduino Forum

He's already got all the code he needs, posted at the start of the thread.

I really don't know where the problem is.

Quote from: Erni on Today at 04:38:03 am
Take a look at Jack Christensens demo sleep code

Sleep mode demo code - Libraries - Arduino Forum

He's already got all the code he needs, posted at the start of the thread.

I really don't know where the problem is.

the problem is that using a photocell as an interrupt is not a good idea because the voltage is not stable at all (even a little change in light will trigger the interrupt) plus i want the interrupt to happen on all 3 analog pins

what i want is that when the voltage on the photocell connected interrput pins reaches a specific voltage (and only that specific voltage) it wakes up.... lower than that specific voltage it stays in sleep mode

the code in Christensens demo sleep wakes up the chip by using a switch which is ok since the voltage is stable

iA2K:
the problem is that using a photocell as an interrupt is not a good idea

No disagreement there... but why do you need that?

All you need is code like this:

void loop()
{
  sleep4secs();
  if (checkPhotocells()) {
    beep();
  }
}

Where's the problem?

the problem is that using a photocell as an interrupt is not a good idea

No disagreement there... but why do you need that?

All you need is code like this:

Code:
void loop()
{
sleep4secs();
if (checkPhotocells()) {
beep();
}
}

Where's the problem?

i want my circuit to work like this:

check for light

if (there is light (at a specific value))
then beep
delay for 4 secs (or sleep for 4 secs)
then system goes to sleep but can wake up again if there is light;

if there is no light then stay sleeping till light is detected (at specific value)

the problem with the code you wrote is that after sleeping for 4 secs it checks for light and if there is no light then it will go back to sleep for another 4 secs... so during those 4 secs if there is light the system won't do anything.

only after it beeps the system should shut down for 4 secs....other than that it should wake up if there is light

iA2K:
only after it beeps the system should shut down for 4 secs....other than that it should wake up if there is light

I mentioned the solution to that in the second post.

Why would a 4 second delay matter?

Maybe you could tell us what sort of light it is, how fast it changes, etc.

(or anything at all about what it is you're actually trying to achieve...)

iA2K:
what i want is that when the voltage on the photocell connected interrput pins reaches a specific voltage (and only that specific voltage) it wakes up.... lower than that specific voltage it stays in sleep mode

You will need to use an analog comparator to condition the photocell output to trigger at a certain reference voltage level.

what i want is that when the voltage on the photocell connected interrput pins reaches a specific voltage (and only that specific voltage) it wakes up.... lower than that specific voltage it stays in sleep mode

You will need to use an analog comparator to condition the photocell output to trigger at a certain reference voltage level.

it look alike a analogue comparator is the way to go....thank you

I mentioned the solution to that in the second post.

like i told you before using a photocell as an interrupt turns out to be a bad idea.

Why would a 4 second delay matter?

Maybe you could tell us what sort of light it is, how fast it changes, etc.

(or anything at all about what it is you're actually trying to achieve...)

those 4 secs are really essential to my system... (I'm trying to build a light installation made of many individual lights, after a light lights up it shouldn't do anything for 4 secs)

iA2K:
those 4 secs are really essential to my system...

So your very first post should have described that system - just to avoid wasting everybody's time.

iA2K:
(I'm trying to build a light installation made of many individual lights, after a light lights up it shouldn't do anything for 4 secs)

Nope. I still have no idea exactly what the lights are supposed to do.

@iA2K...

Take a look at this t85 project. It wakes and immediately goes back to sleep if the thermistor has not changed value... The value persists thru the sleep. Same idea with photocel, I should think.

http://www.hackster.io/rayburne/hot-yet

The trick w/ battery power is to sleep much longer than you are awake unless there is work to do. It is not absolutely necessary to use an interrupt to awake if you go back to sleep quickly.

Ray