Go Down

Topic: Can Timer 1 event capture pin ICP1 wake Arduino/ATmega328 [Solved] (Read 3974 times) previous topic - next topic

mk3

Hello,

As the subject says.  I have read the datasheet many times as well as a lot of forum posts and code.  I have not been able to find a good answer to this question.

I plan to use an infrared receiver chip to create a bitstream for an arduino Uno to read.  The event capture of Timer/Counter 1 seems to be a good way to do this because the time stamps will be really accurate.

I have found that pin change interrupts and of course INT0 and INT1 can be use to wake the chip from sleep.  I cannot find explicit information so far for the case in which ATmega328 pin 14 (Arduino digital pin 8, DIO8) which is also ICP1 is used for waking.

If this will not work I can do a work-around in which I also connect my signal to the INT0 pin but I hope I can keep it free for potential other uses.  INT1 is already occupied because I am using OC2B to create an output waveform to blast IR to other components.

My device will be an infrared repeater and decoder and it will be used to wake up my home theater PC and possibly some other home theater components or devices.

thanks in advance!

johnwasser

Looks like the Input Capture Interrupt is NOT a Wake-up Source.

Perhaps you can connect your IR signal also to INT0 or INT1 and wake the CPU with that.   Disable that interrupt while the input capture interrupt to measure the pulse pattern.  When the signal has been received, re-enable the INT0 (or INT1) interrupt and go back to sleep.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

nickgammon

All three timers generate interrupts which can wake the processor from sleep (depending on the sleep level). In particular Timer 2 can wake it from a deeper sleep (SLEEP_MODE_PWR_SAVE).

http://gammon.com.au/interrupts

and:

http://www.gammon.com.au/forum/?id=11497
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

johnwasser


All three timers generate interrupts which can wake the processor from sleep (depending on the sleep level). In particular Timer 2 can wake it from a deeper sleep (SLEEP_MODE_PWR_SAVE).

http://gammon.com.au/interrupts

and:

http://www.gammon.com.au/forum/?id=11497


According to the ATmega data sheet, of the timers, ONLY Timer2 can wake the processor from SLEEP_MODE_PWR_SAVE and only when Timer2 is running off an asynchronous clock (probably since the I/O clock is off during Power Save).  The Timer2 asynchronous clock pins (TOSC1 and TOSC2) share the same pins as the external crystal clock (XTAL1 and XTAL2, a.k.a. PB6 and PB7).  TOSC1 and TOSC2 can only be used when the ATmega is running off the internal 8MHz RC clock.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

nickgammon

Looks like I was wrong. Only SLEEP_MODE_IDLE would allow you to wake from a timer interrupt, or as John said, a Timer 2 interrupt if from an external clock.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

mk3

Thanks everyone for the quick and thorough replies.  Looks like I have as about as much information know as can be had without trying it.  I do like the option of using INT0 just to wake as member johnwasser suggested and of course the only downside is the use of a pin that might otherwise be used for additional functions.

One other thing that confused me is whether an event capture would be considered a "timer interrupt";  the overflow and compare match is what I think of as a timer event.

Would another option be to configure the pin as a port change interrupt before going to sleep?  After waking I could reconfigure the pin to act as the event capture.  I would lose some timing accuracy at the beginning but I am not sure that will matter much.

I am using the Arduino IDA and standard Arduino boards although obviously I am deviating from standard commands.  I am pretty much a beginner but learning is so easy with all the resources out here.


I don't get much spare time to work on the project but when I do I will test the options.

thanks again!

johnwasser


Would another option be to configure the pin as a port change interrupt before going to sleep?  After waking I could reconfigure the pin to act as the event capture.  I would lose some timing accuracy at the beginning but I am not sure that will matter much.


Yes, that would probably be at least as effective as my idea of using INT0, particularly since INT0 has to be set to trigger on HIGH or LOW and not RISING or FALLING if it is to work while in a Sleep mode deeper than Idle.  The pin-change interrupts even work in "POWER DOWN" sleep (the deepest sleep).
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

nickgammon


The event capture of Timer/Counter 1 seems to be a good way to do this because the time stamps will be really accurate.


One caveat here is that it takes time for the processor to wake from sleep (like I do). So "really accurate" might be pushing it. Some of the wake-up times (depending on fuse settings) can be as long as 16 clock cycles plus 65 mS. So that is hardly instantaneous.

But perhaps the timer can remember the event while the processor is struggling back to wakefulness. I haven't experimented with that.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

mk3

I marked this as solved even though I will not directly test this.  I decided that for my RC6 decoding the timing is not as critical as I had first thought.  I will use INT0 to wake from sleep.  I may not need ICP1 at all. 

The general answer to the question is that ICP1 will not directly wake the processor but there are some decent workarounds.

Thank you gentlemen for your excellent answers.

Go Up