can this be done with sleep modes and interrupts?

I am using an ATMEGA328p in a stand alone application.

there are two processes that my sketch implements:

  1. Fill a buffer with data at specified timing intervals (using TIMER1 interrupts for example)
  2. when the buffer is full, process the data

In an effort to reduce current draw, I was wondering if during process 1 (where I am gathering data with minimal processing) could be done during a sleep mode. If so, since I know when the buffer is filled, could I use that as a trigger to get out of sleep? I’m on the learning curve for sleep modes so your help is appreciated.

Thanks

Here is an idea of the “minimal processing”

  if (buffer_index < BUFFER_SIZE) {
  }
  else
    buffer_index = 0;

  data[buffer_index]= ADCH;

I think that should work well. Do you have an idea how long the "specific timing intervals" would be? The reason I ask is because if it is the right time, you might be able to mess with the prescaler and configure the adc into free running mode.

Processing an interrupt wakes up the processor. You can put it right back to sleep, though, if the buffer isn't full.

TanHadron: I think that should work well. Do you have an idea how long the "specific timing intervals" would be? The reason I ask is because if it is the right time, you might be able to mess with the prescaler and configure the adc into free running mode.

Processing an interrupt wakes up the processor. You can put it right back to sleep, though, if the buffer isn't full.

It is 100-200ms and I could use the ADC or the comparator to sample this signal

Can you explain what "processing an interrupt" means? I assume it means keep the cpu on watching for the interrupt.

Processing an interrupt means the interrupt service routine gets called, and it does whatever it is supposed to do when the interrupt happens. In your case, that would be sampling the data and putting the result in the circular buffer.

You sleep the processor from run time code. Not from interrupt code. If the processor is asleep when the interrupt hits, it wakes up and calls the interrupt service routine, and when the interrupt service routine returns, control passes back to the run time code that executed the sleep. Execution continues from the code right after the sleep instruction.

The run time code will then need to check to see if the buffer is full, and if not, go back to sleep.

Actually, your timing is slow enough that you could do it all in run-time code and use the watchdog timer to wake you up every 100 ms or so and take a reading. You would save more power if you actually turned off the ADC while you're asleep. Look at this from Nick Gammon: http://www.gammon.com.au/power Scroll down to where it talks about Waking from sleep with a timer.

The other way where your interrupt just saves the sample may be less complex when the other process is running, but it would draw maybe 6 mA power to keep the ADC running.