Pages: [1]   Go Down
Author Topic: sleep mode and pin states  (Read 609 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

My sketch uses SLEEP_MODE_PWR_DOWN to save battery and I have a PIR sensor attached to +5v, ground and a digital pin set to input. Every 8 seconds, the chip wakes up and checks the digital pin. If digital pin reads high, the chip registers the time on the epprom and stays awake for two minutes. Then it goes back to sleep.  It works fine, until the chip goes to sleep. It immediately wakes up and the digital pin reads high, so it enters a loop and registers an event every time it goes to sleep, even if nothing is activating the PIR.

My question: When the SLEEP_MODE_PWR_DOWN enables, what happens to the digital pin set to input? Does it go high?

I appreciate all the help you can give.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 223
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing happens to an input pin when the chip goes into power down mode. What are you using to wake up the chip every 8s, the watchdog or something else? Why not use a pin change interrupt to wake up the mcu on a low to high transition of the PIR output? Post your code.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing happens to an input pin when the chip goes into power down mode.
Then it's probably the PIR itself reacting to a fluctuation in voltage and resetting when the MCU goes into sleep mode. It could only be the Pin going high or the PIR resetting. The PIR enters a calibration mode for 20 seconds and during that it goes high. Gonna try a capacitor to smooth the voltage.

What are you using to wake up the chip every 8s, the watchdog or something else? Why not use a pin change interrupt to wake up the mcu on a low to high transition of the PIR output? Post your code.
I'm using the watchdog. Can't use any of the interrupts available cause I’m already using them for other events... Every single pin on the Atmega 328 is already used (some with more than one task). Gonna start fiddling with other models for the next project cause the 328 is limiting.


Thanks!
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 223
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using the watchdog. Can't use any of the interrupts available cause I’m already using them for other events... Every single pin on the Atmega 328 is already used (some with more than one task). Gonna start fiddling with other models for the next project cause the 328 is limiting.

1. You can still enable the pin-change interrupt on the input pin you are already using.

2. In many designs, it is possible to use some of the pins to interface to more than one device. It sounds like you are already doing this, but maybe you can take it further. I frequently re-use 5 of the pins for driving a character LCD display as multiplex pins for connecting push buttons or rotary encoders.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


1. You can still enable the pin-change interrupt on the input pin you are already using.


How? Can I add a 3rd interrupt and assing it to Digital13? (no LED on the D13;)
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 223
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://playground.arduino.cc/Main/PinChangeInt
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


It doesn't resolve my problem, but WOW! That is very nice to know, thanks!

Oh well, back to the multimeter... smiley-cry
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 223
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If the mcu is immediately waking up when you put it into sleep mode, it is fairly clear that something is wrong with your code. But you haven't posted it.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for the late answer, but I only figured out yesterday what was the problem.
It was the freaking wind! I had my project on my terrace, which is a pretty windy place. I thought the MCU was resetting because of power fluctuations, but it was the wind wobbling the setup and causing the PIR sensor to be constantly active.
When you hear hoof beats, think of horses, not zebras...
Also, always test your projects indoors first!
Logged

Pages: [1]   Go Up
Jump to: