Timer with Atmega 328

Hello,

I'm new to the board and new to MCU programming as well. If I'm not in the right place let me know.

What I'm building is essentially a wake-up circuit. The circuit will recieve a signal via antenna and hit the turn on voltage of a CMOS transistor. The transistor will send a signal to an Atmega 328 (this is the MCU the group before me used) which in turn will start a timer for 5 minutes and send an output signal to the rest of my circuit essentially turning it "on" After the 5 minutes are up the circuit should reject all incoming signals for a short amount of time (i.e. 5 seconds), in other words I don't want it to turn back on immediately. The entire circuit is powered by a 3.6V battery.

Any tips or advice is welcome. If anyone can point me in the right direction or even if I'm using the right piece of hardware for this, I would appreciate it greatly.

So your circuit is doing the timing, or receiving the signals and turning a transistor ON?

How I would go about the problem is:

  • Power up and initialise the AVR
  • Shutdown all unecessary HW blocks, like the ACD module, …
  • Declare 2 interrupt service routines (see below):
    ? One for external interrupts
    ? One for the watchdog
  • Configure the AVR sleep mode to wake up on external IO trigger (external interrupt)
  • Enable external interrupt
  • Configure sleep mode
  • Go to sleep
  • Your main program's loop should maintain a very small state machine with the power up sequence so that you know what what state you are in so that your main loop can act accordingly.
    (When changing the state variable, remember to put it in a critical section (disable interrupts,
    change state variable, enable interrupts)
    Depending on the state:
    ? Configure AVR sleep mode to wake up on watchdog or external IO trigger depending on state:
    (if you woke up from sleep via External interrupt)
    § Configure the AVR sleep mode to wake up on watchdoge reset
    § Configure the watchdog expire every 8 seconds, 4, or what ever you want your code
    § Do the entire powerup sequence you need
    § Configure sleep mode
    § Enable to watchdog interrupt

(if you woke up from sleep via Watchdog reset)
§ Configure AVR sleep mode to wake up on external IO
§ If time to attend new external interrupts (configure and enable them)
§ If not time to attend new external interrupts (configure WD wake up and enble)
? Go to sleep

External interrupt ISR

  • Change state of the main state machine to waking up (remember critical section)
  • Inhibit the external trigger interrupt

Watchdog ISR

  • // Depending in the ammount of time you want the system to ignore the external interrupt count
  • Change state variable (in a critical section)
  • Inhibit the watchdog interrupt

The above needs to be polished up a bit, this is just a rough idea.

The good thing about the solution is that the power consumption is very, very small for your reset circuit.

I think this is a over kill for the AVR as most of the time it will be sleeping waiting for something to happen.