ISR and attachInterrupt statement to toggle power

dan_movie:
I figure every TV remote out there must...

...use pin change interrupts instead of external interrupts.

@larryD ... i read that when putting the processor to sleep you get "better power saving results" by not having any unused pins in a floating state. So the idea was to make all unused pins be "LOW".
see link : Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors

there is a section about : Configuring pins as inputs/outputs it shows the power consumption of the various pins - output / input, low / high.

@coding bradly ... i thought the only way to wake a sleeping arduino was by an external interrupt or watchdog timer. I will do more research on pin change interrupts. If you have any pointers, I would appreciate it. Is it one interrupt that monitors all 3 buttons ?

My point in the small sketch I posted was to show you a more efficient way of setting a range of pins with ‘pinMode’, nothing else.

Take a close look at the sketch in post #8 which uses an array. :wink:

dan_movie:
Is it one interrupt that monitors all 3 buttons ?

One interrupt per port.

dan_movie:
Thanks for the feedback.

I am using an Arduino Pro Micro - so based on the 32U4 chip which has more interrupts.
https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/ProMicro16MHzv1.pdf

Never tried the diodes, can you suggest a diode number / reference ?

Something along the lines of a BAT83S would be easy to prototype with:

https://www.digikey.ca/product-detail/en/vishay-semiconductor-diodes-division/BAT83S-TR/BAT83S-TRGICT-ND/8564711

Larry, sorry I missed the code in your post, much simpler ! thanks.

Thanks for the diode info and the interrupt info.

Hi All,

I just came across this on page 88 on the 32U4 datasheet.
I am not so good with electronics and all the technical info on datasheets but ... does the info below point to why my change interrupt on pin 7 is not working...it needs the clock to be running ??

From page 88....

The External Interrupts can be triggered by a falling or rising edge or a low level. This is set up as indicated in
the specification for the External Interrupt Control Registers – EICRA (INT3:0) and EICRB (INT6). When the
external interrupt is enabled and is configured as level triggered, the interrupt will trigger as long as the pin is
held low. Note that recognition of falling or rising edge interrupts on INT6 requires the presence of an I/O clock,
described in “System Clock and Clock Options” on page 27. Low level interrupts and the edge interrupt on
INT3:0 are detected asynchronously. This implies that these interrupts can be used for waking the part also
from sleep modes other than Idle mode. The I/O clock is halted in all sleep modes except Idle mode.

The datasheet is (very likely) incorrect...

I believe @JChristensen contacted Atmel and they confirmed that external interrupts do NOT require a clock for ATmega processors.

A bit more information...

Ok thanks for this last response.

Could you give this link a quick read and tell me if any of it is still accurate in 2019 ??

https://forum.sparkfun.com/viewtopic.php?t=35847

Something about how the Arduino IDE does not “compile” correctly the Int6 (digital pin 7) of the 32U4.

I am wondering if this is my issue with the interrupt not firing on that pin.

I am in trouble if I need to code it directly with the “AVR commands” cause I don’t understand how they work (too much code, not enough short instructions that mean something).
I can understand : attachInterrupt(digitalPinToInterrupt(BTN_Bell), wakeUpBell, CHANGE);
but not EICRB |= (1<<ISC60)|(1<<ISC61);

thanks for the help.

Support for interrupt numbers 0 through 4…

Digital pin 7 is mapped to interrupt 4…

This will silently fail. There is no interrupt 7...

dan_movie:

...

attachInterrupt(7, wakeUp, LOW);
...

dan_movie:
Something about how the Arduino IDE does not "compile" correctly the Int6 (digital pin 7) of the 32U4.

Digital pin 7 is mapped to interrupt 4 (see the post above). If you use digitalPinToInterrupt you will not have to know that.

@Coding Badly, on page 1 of this thread my revised code (in a subsequent post) does use digitalPinToInterrupt.

I AM CONFUSED and maybe using all the wrong terminology.

In your 1st link, lines 81 to 104…

case 4:
        EICRB = (EICRB & ~((1<<ISC60) | (1<<ISC61))) | (mode << ISC60);
        EIMSK |= (1<<INT6);
        break;

in case # 4, so interrupt 4 seems to be using the config info for INT6 based on the 32U4 datasheet.
(bottom of page 89, section 11.1.2 - control register B - EICRB which seems to refer to external interrupt 6.

The 2nd link is pointing to line 160…

#define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))

is this showing that pin 7 equal interrupt 4 ?

If I look at line 177 in that same link, does it not show D7 is INT6 ??

I also don’t see a INT4 in the list of pins between lines 168 to 202 ?

Again, is my terminology all wrong ??

Lastly, since I did use digitalpintoInterrupt in my code, I still don’t get why the arduino does not wake up only for that specific interrupt when it does for the other 2 that have very similar code.
I know that my button works and does change the logic level because when my xbee radio is awake because of pressing the other buttons, if I press the Bell button while the radio is still awake the bell ring signal code is sent and when I release the button the bell quiet code is sent, so that has to be a change in logic level from pressed to released.

@Blackfin

In your #8 post on this thread, do I understand correctly that using the diodes, I would move the reading on the input pins to the main loop and just use the interrupt to wake the system.
Wake on falling for example, detach the interrupt and just re-attach when I put the system back to sleep once the "awake delay" has expired and no button is pressed.

If I have all my pushbutton inputs on INPUT_PULLUP, do I use the same for this interrupt pin ?
I don't know what the diode does to this circuit, when a button is pushed will pin 3 of your example be high or low ?

thanks

dan_movie:
@Blackfin

In your #8 post on this thread, do I understand correctly that using the diodes, I would move the reading on the input pins to the main loop and just use the interrupt to wake the system.
Wake on falling for example, detach the interrupt and just re-attach when I put the system back to sleep once the “awake delay” has expired and no button is pressed.

With the diodes you should be able to read pins 7, 8 and 9 normally and use in 3 as your wake from sleep input which will respond to a press of any of the buttons.

If I have all my pushbutton inputs on INPUT_PULLUP, do I use the same for this interrupt pin ?
I don’t know what the diode does to this circuit, when a button is pushed will pin 3 of your example be high or low ?

Yes, INPUT_PULLUP on pin 3 as well as 7, 8 and 9.

The diodes are there to allow any of the switches to pull pin 3 the GND without affecting the other pin inputs. If no switches are closed, pins 7-9 and 3 are all high. If, say, the switch on pin 8 is pressed, pin 8 goes to ground. The diode between pin 8 and pin 3 is forward biased so pin 3 is pulled <0.7V above ground. The other two diodes are reverse biased (their cathodes are at a higher potential than their anodes) and so their pins, 7 and 9, remain high (unaffected.)

Thanks for the explanation.

I ordered the part you mentioned BAT83S as well as this one
https://www.digikey.ca/product-detail/en/SD0805S040S0R1/478-7801-1-ND/3749492?utm_medium=email&utm_source=oce&utm_campaign=2481_OCE19RT&utm_content=productdetail_CA&utm_cid=670046&so=58501384&mkt_tok=eyJpIjoiT0RWbU5qSTBNbU16TVRKaSIsInQiOiJydkU4ZjBtb0hmcGdOOVB6QTY1bWY1amY0bGhobWdTOHg2TUdUa1QxNGNcL21rWmI4Ylk2R0NwSFROSVc0eTVncDkyV1Z5ck1CTDVNdlwvdzlaZndsVW9TV2EyN1BqbG92XC9NSDBOWjFocjNVbjMxQlRKb3NxOEE3WXdwSm9UVGtuYyJ9
from digi-key. trying to minimize size of the final remote control.

One last question, if I switch to a 3.3v Arduino would these diode values still be OK ?

Yep, they should be fine.

@Blackfin - thanks, the diodes arrived today and worked like a charm !!

dan_movie:
I still don't get why the arduino does not wake up only for that specific interrupt when it does for the other 2 that have very similar code.

Is that still a problem?

Thanks for asking...

I gave up on the Micro and used Blackfin's idea of the diodes to trigger the interrupt on the single pin.

So in the end I will either use a pro mini or nano - both use the 328 chip and by combining all buttons to a single interrupt pin, I end up not dealing with the non-firing interrupt on pin 7 of the arduino pro micro that uses the 32U4 chip.

So the short answer - no longer a problem. The long answer - the interrupt on pin 7 of the pro micro never fired.
Yet the same code fired when I changed the pin to another one on the Pro Micro or the Nano.