1

for a battery powered project I would like to put an Attiny85 into deep sleep mode immediately after program start and let it wake up only when a sensor value (in this case a photo resistor) changes. Unfortunately I could only find examples for interrupts by a button and not for photo resistors in the internet. Does anyone have an idea how I could implement it, or if it is impossible?

Michael Brown
  • 137
  • 2
  • 13
  • I’m voting to close this question because it's really an electronics question, not a software question. – TomServo Jul 25 '20 at 15:30
  • It is of course possible, but you need circuitry to activate, for example, INT0. Circuitry design and part selection is off-topic here. – TomServo Jul 25 '20 at 15:31
  • @TomServo, not really, since it is a programming and not a hardware question. Or am I wrong??? I have absolutely bo idea how to programm my problem or if it's even possible – Michael Brown Jul 25 '20 at 16:14
  • Not really. The low-power modes are simple. Each datasheet show the register settings in detail. You must create a circuit that asserts Vcc onto INT0, as you say, when a sensor values changes (presumably with some hysteresis). This is circuit design, first and foremost. You need to specify this further (particularly hysteresis) and look for opamp/comparator/schmitt trigger circuit designs to trigger INT0. But not here on Stackoverflow. Program INT0 to wake it when you apply Vcc to the INT0 pin with a breadboard wire. Then add other circuit when this works. Easy. – TomServo Jul 25 '20 at 17:08
  • Nevertheless, thank you very much for your answer and apologize that I have "contaminated" the forum. I will then try to implement it according to your suggestion. Thanks! P.S.: By the way, my question was more like this: "How do I put the Attiny into deep sleep mode and wake it up again if a sensor value changes?" I just wanted to know if it is possible to get an interrupt with a photo resistor, but it seems to be only possible if you set INT0 to high. – Michael Brown Jul 25 '20 at 18:04
  • Perhaps the answer below will suffice. You never specified what order of magnitude you were talking about. Microamps are easier than nanoamps. My low-power designs operate at the latter. – TomServo Jul 25 '20 at 22:52

1 Answers1

3

Turn out that this is probably a software question.

Probably to lowest power and simplest way to implement this would be to...

  1. Connect the analog sensor value to any one of the analog input pins on the ATTINY.
  2. Make sure you disable the digital buffer on that pin.
  3. Set up the ADC to point to the pin and set other relevant values like precaller.
  4. Set up a watchdog timer to fire a periodic interrupt.
  5. Go into deep sleep and wait for the watchdog timer to fire.

Each time the watchdog fires...

  1. Enable the the ADC.
  2. Take a sample.
  3. Jump to main code if the value has changed more than your threshold.
  4. Disable ADC.
  5. Go back to deep sleep.

How power efficient this will be really depends on how often the timer interrupt fires - the less often the better. If your application can live with only checking the sensor, say, once per second then I bet power usage will be single digits of microamps or less.

If you really need very low latency when that sensor values changes, then you could instead use the build in analog comparitor... enter image description here .. to generate an interrupt when the input voltage goes above or below a threshold value, but this will likely use much more power since just the analog comparitor itself uses ~30ua while on, and you will also need to generate the voltage that you are comparing to either with the internal 1.1 voltage reference or an external resistor bridge or buffer capacitor.

bigjosh
  • 1,273
  • 13
  • 19
  • This is not a bad solution. It might be useful to OP and others; I upvoted it. Just to be clear though, it seems this circuit hasn't been tested for power. When someone says low-power and deep sleep, I think in the nanoamp range, not the microamp range. The low-power designs I've built operate in nA range. – TomServo Jul 25 '20 at 22:50
  • I think that one measurement in one second should be enough, so I can achieve low power consumption without interrupt. Thanks – Michael Brown Jul 26 '20 at 07:31
  • @TomServo Even using an ultra-low power dedicated analog comparator like MAX40003 it would still take a couple of uA. How would you do it to get down to nA range? – bigjosh Jul 26 '20 at 23:17