Good morning,
Lately we have been experimenting with projects with ATmega328P microcontrollers to SAMD21, in this case with the MKR1500 board.
My need is to send the board in deep sleep to save consumption and in the meantime to count the impulses of a reed sensor connected to a digital pin via an interrupt.
Here problems arise, with this board (at least in my case) when it goes to sleep, interrupts are not counted as arriving in FALLING / RISING mode, instead with HIGH or LOW mode, the board wakes up at the first impulse ...
Instead I would like the board to continue to sleep for a certain time, and in the meantime to count the impulses.
My piece of code is as follows:
pinMode(countPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(countPin), count_int, FALLING); /*attiva interrupt su pin*/
Serial1.println("Go to sleep...");
LowPower.deepSleep(10000);
detachInterrupt(1); /*disattiva interrupt su pin*/
print_count();
pylon:
You know what you describe here? You want the board to sleep (consume no power) but does the job anyway? That doesn't work.
We don't want to see pieces of code but complete code! In most cases the error is within that part of the code that you're hiding from us.
Is there a way to count the pulses while the board is sleeping? or is there anyway the possibility of counting keeping the consumption as low as possible?
Is there a way to count the pulses while the board is sleeping?
To my knowledge: no.
BTW: are we talking about the MKR1500 or an ATmega328p based board? As far as I know the wake up with a level interrupt only is only true for the ATmega328p, the SAM can wake up with any interrupt configured by the interrupt controller.
is there anyway the possibility of counting keeping the consumption as low as possible?
The SAM has the option to enter idle state immediately when it exits the interrupt handler.
in practice counting the pulses via interrupt while the board was in an idle state, but without waking up.
Because in my tests the MKR1500 board when in sleep as soon as it receives an impulse it wakes up instead of counting and staying in sleep
How should that work? If the CPU doesn't wake up it cannot count anything.
With the ATmega328p, the board probably wakes up as you say, but does not continue the code but remains dormant until the time set for the LowPower.idle function passes (...);
Sure it wakes up but you can tell it to go to sleep again immediately after you exit the interrupt handler. Post the code you tried on the MKR1500!
With the ATmega328p, the board probably wakes up as you say, but does not continue the code but remains dormant until the time set for the LowPower.idle function passes (...);
Bullshit. The time period is simply used to set the watchdog timer to wake up after that time if no other wake event occurred.
How is it possible to do what you say?
Did you read the SAMD21 datasheet, especially the part about the power manager? If you want to do special task as you're asking for, using high level libraries as the LowPower library doesn't work anymore.
But beyond the problem of waking up from sleep, the problem remains that the board does not hear the interrupt with the falling clause ...