Go Down

Topic: samd51 - counting sheeps while sleeping (Read 414 times) previous topic - next topic

falkenauge

Nov 12, 2020, 03:36 pm Last Edit: Nov 12, 2020, 03:38 pm by falkenauge
Hello everyone, hope you're all doing great!

Forgive me for the lame joke on the title, trying to get some attention to the post...

Setup:

The Rain Gauge output is connected to a pull-up resistor, so it generate LOW pulses when there is rain, something close to this ¯¯¯¯|_|¯¯¯¯.
  • The board is powered by a small battery that can last quite some time with the correct setup.


Goal and Explanation:
As you may have figure out, I would like to be able to read this pulses every time they occur, so first I had to use the Arduino Interruption with a simple debounce to not count the same pulse multiple times.

Code: [Select]
attachInterrupt(digitalPinToInterrupt(interruptPin), countBucket, RISING);
[...]
void countBucket() {
  noInterrupts();
  pulseTime = millis();
  if ((pulseTime - lastPulseTime) > acceptedInterval ) {
    state = !state;
    count++;
    lastPulseTime = pulseTime;
  }
  interrupts();
}

The code above (plus the omitted part) works just fine, I can count the sensor without any problem.
Because the board is always working, the battery isn't able to last much time and so I decided to use the Adafruit Sleepy Dog to make it sleep most of the time and with this the battery last a really long time.

Issue:
However, if everything worked i wouldn't be here (rsrsrs) and while sleeping I can't count the pulses right. When the board get the first pulse, it wakes up and then, on the second one if the board is still wake the pulse will be counted once, otherwise it will just wake it up again. Does anyone know if it is possible to count this while sleeping or to wake it up and make this first pulse be counted?
"You can never know everything, and part of what you know is always wrong. Perhaps even the most important part. A portion of wisdom lies in knowing that. A portion of courage lies in going on anyways."
--The Eye of the World

PerryBebbington

How long do the pulses last?
I'm thinking maybe if the pulses last, for example, 100ms then you can have the board sleep for 95ms, wake, check then go back to sleep without missing a pulse. Further to that, if you know there will never be, for example, more than 1 pulse every 15 seconds then after you detect a pulse you can sleep for 14 seconds knowing that there won't be a pulse in that time.

markd833

It sounds like you are almost there! You can get the SAMD51 to wake on an external interrupt.

When you talk about the second pulse, are you referring to a completely separate event from the rain gauge or an additional pulse related to the first pulse (debouncing?).

Whether your SAMD51 is awake or asleep, it should be able to detect the interrupt and, if sleeping wake up, and then carry out the interrupt processing.

Shouldn't any pulse wake up the SAMD51?

Do you have a link to the rain gauge datasheet? 

steve_mcdonald

I have approached this another way.  I collect the rain gauge pulse at a bistable latch (4013 - D type schmitt trigger latch) so that each pulse sets or resets the latch, effectively debouncing and stretching the pulse until the next pulse arrives.  Every second pulse gives either a 1 or a 0 output consecutively.  That makes reading it at the microprocessor very simple and effectively timing independent.  It has been totally reliable and consistent.  

You could use the pin change interrupt to wake the micro, read the latch state and go back to sleep. 

PerryBebbington

I have approached this another way.  I collect the rain gauge pulse at a bistable latch (4013 - D type schmitt trigger latch) so that each pulse sets or resets the latch, effectively debouncing and stretching the pulse until the next pulse arrives.  Every second pulse gives either a 1 or a 0 output consecutively.  That makes reading it at the microprocessor very simple and effectively timing independent.  It has been totally reliable and consistent.
++Karma; // That's clever!

falkenauge

I have approached this another way.  I collect the rain gauge pulse at a bistable latch (4013 - D type schmitt trigger latch) so that each pulse sets or resets the latch, effectively debouncing and stretching the pulse until the next pulse arrives.  Every second pulse gives either a 1 or a 0 output consecutively.  That makes reading it at the microprocessor very simple and effectively timing independent.  It has been totally reliable and consistent.  

You could use the pin change interrupt to wake the micro, read the latch state and go back to sleep.
Thank you for the idea, I'll definitely try it. 
"You can never know everything, and part of what you know is always wrong. Perhaps even the most important part. A portion of wisdom lies in knowing that. A portion of courage lies in going on anyways."
--The Eye of the World

Go Up