Author Topic: Using ListenMode as Wakeup timer  (Read 89562 times)

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Using ListenMode as Wakeup timer
« Reply #15 on: September 27, 2015, 05:35:34 PM »
I don't know if I can deal with the 100% wasted code in:
Code: [Select]
static void delayIrq() 
{
return;
}
But, other than that, GOOD WORK!  Now go to sleep!

Tom

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Using ListenMode as Wakeup timer
« Reply #16 on: September 27, 2015, 05:37:03 PM »
Quote
I gather you're using
radio.writeReg( REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_11 );
to map RSSI to DIO0?

Yup, that's what that line does.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #17 on: September 27, 2015, 05:38:58 PM »
Cool.  By the way, from an energy perspective, is it also better to use the RFM69 based wake-up timer method than the WDT, for cases where the delay is < 8 seconds?  i.e. maybe it should be the new default wakeup timer, except in cases where that interferes with something actively going on with the RFM69 radio.  I know, I know, RTFM....  IIRC, though, the answer would  be yes.
« Last Edit: September 27, 2015, 05:45:34 PM by WhiteHare »

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Using ListenMode as Wakeup timer
« Reply #18 on: September 27, 2015, 05:45:22 PM »
Quote
I don't know if I can deal with the 100% wasted code

Oh, that's right, with the Arduino libs a detachInterrupt is enough since the default handler does nothing. I initially had some code in there I think  ;)

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Using ListenMode as Wakeup timer
« Reply #19 on: September 27, 2015, 05:53:22 PM »
Quote
is it also better to use the RFM69 based wake-up timer method than the WDT, for cases where the delay is < 8 seconds?

At about 2 seconds the 2 RX windows themselves cost about the same as the WDT. Additionally you need to execute the code to start listen mode, end it and reinitialize the radio. We'll should time that to see how much power it costs.

Oh, and Kobuki, I hereby officially award you with Joe's highly coveted Listen Mode Medal.

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Using ListenMode as Wakeup timer
« Reply #20 on: September 27, 2015, 06:09:04 PM »
Quote
detachInterrupt is enough

Actually it's not since you want to make sure to register the interrupt to the rising edge. But

Code: [Select]
attachInterrupt( RF69_IRQ_NUM, NULL, RISING);

works.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Using ListenMode as Wakeup timer
« Reply #21 on: September 27, 2015, 08:15:49 PM »
Quote
I don't know if I can deal with the 100% wasted code

Oh, that's right, with the Arduino libs a detachInterrupt is enough since the default handler does nothing. I initially had some code in there I think  ;)
Sorry, I was being facetious. The 'return;' statement within an empty void function is unnecessary.  I guess I either need to elaborate or try to stop being funny (or both, or is it neither?)...

But, seriously, good work on testing this so quickly.

Thanks,
Tom

kobuki

  • Sr. Member
  • ****
  • Posts: 289
Re: Using ListenMode as Wakeup timer
« Reply #22 on: September 28, 2015, 07:51:19 AM »
Nice progress, Joe! And thanks for the medal, I'll put it in my virtual safe ;)

What you noted about the RSSI. Why do you receive 3 interrupts? Why isn't the chip waking up at the first? Or you just see it on the scope? Oh, and why the remapping? Isn't DIO0 signaling the state change with the default config (btw I don't know if you use a Tino proto or a Moteino)? Sorry for the many questions...

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Using ListenMode as Wakeup timer
« Reply #23 on: September 28, 2015, 12:32:33 PM »
Quote
What you noted about the RSSI. Why do you receive 3 interrupts?

The radio wakes the 328p three times with an RSSI until the selected time has passed. I would have expected 2 interrupts: one for the initial RX window right when listen mode is entered and one after the idle period. But I immediately get 2 during the first RX window and the the third at the correct  time.

Quote
Isn't DIO0 signaling the state change with the default config

You might want to check out the datasheet. All kinds of signals can be mapped to DIO0. In this case we don't want payloadready (which I use with normal listen mode), but RSSI detected.

kobuki

  • Sr. Member
  • ****
  • Posts: 289
Re: Using ListenMode as Wakeup timer
« Reply #24 on: September 28, 2015, 12:55:47 PM »
Hmm, it doesn't sound right. It can be circumvented by ignoring the bogus signals and then entering sleep mode, though. Haven't run your skecth yet, so it might not be a feasible solution.

I know about the mappings, but for the special purpose of external wakeup, I haven't fully explored their necessary settings yet. It seems from your code that you set RSSI IRQ for RX mode on DIO0, into which the module enters when waking itself up via its own internal RC timer to start RX mode for the defined period.

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Using ListenMode as Wakeup timer
« Reply #25 on: September 29, 2015, 08:40:01 AM »
Quote
It can be circumvented by ignoring the bogus signals and then entering sleep mode, though.

Sure. if you check my code I just call powerDown 3x - once for each interrupt. As I said two interrupts are completely expected. The second one during the first RX window is a bit surprising.

Quote
I know about the mappings, but for the special purpose of external wakeup

Nothing special for wakeup. the 328p wakes up on any interrupt. So by enabling interrupts and mapping a signal at the radio to DIO0 we'll get woken up by that signal, in this case "RSSI detected" which is active when RSSI has been detected as above threshold.

kobuki

  • Sr. Member
  • ****
  • Posts: 289
Re: Using ListenMode as Wakeup timer
« Reply #26 on: September 29, 2015, 08:48:43 AM »
As I said two interrupts are completely expected. ...

Why are 2 interrupts expected?

Nothing special for wakeup. the 328p wakes up on any interrupt. So by enabling interrupts and mapping a signal at the radio to DIO0 we'll get woken up by that signal, in this case "RSSI detected" which is active when RSSI has been detected as above threshold.

Not special for the 328p, but special use case of settings and interrupts for the RFM module, my original proposal which we're discussing right now. I thought that either in packet mode we might just get the same interrupt (remember that I suggested no sync word, no preamble), namely PayloadReady, or switching to another mode, eg. continuous mode + ook, we'd get it. BTW if it's indeed the case, I'm sure PayloadReady would fire only once until cleared. Would make life simpler and less quirks would be needed.

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Using ListenMode as Wakeup timer
« Reply #27 on: September 29, 2015, 11:04:29 AM »
Quote
Why are 2 interrupts expected?

Very simple: when you enter listen mode the radio immediately start an RX window. You get an interrupt for that window, but you want to wait for the second window to get the idle delay.

Quote
I thought that either in packet mode we might just get the same interrupt (remember that I suggested no sync word, no preamble), namely PayloadReady, or switching to another mode, eg. continuous mode + ook, we'd get it. BTW if it's indeed the case, I'm sure PayloadReady would fire only once until cleared. Would make life simpler and less quirks would be needed.

Oh, I see. You want to use OOK, fixed 1 byte packet length, no preamble, no sync word, etc. and then receive the noise as packet. Yeah, I don't know if that would work. In any case RSSI detection is faster than receiving a byte, so the RSSI approach is likely superior.

kobuki

  • Sr. Member
  • ****
  • Posts: 289
Re: Using ListenMode as Wakeup timer
« Reply #28 on: September 29, 2015, 11:15:27 AM »
Very simple: when you enter listen mode the radio immediately start an RX window. You get an interrupt for that window, but you want to wait for the second window to get the idle delay.

That's a bug in the RFM69, right?

Oh, I see. You want to use OOK, fixed 1 byte packet length, no preamble, no sync word, etc. and then receive the noise as packet. Yeah, I don't know if that would work. In any case RSSI detection is faster than receiving a byte, so the RSSI approach is likely superior.

No, I don't want to use OOK mode, but it's a possibility. All we want is some noise to trigger the interrupt. At the very high bitrate you've set in your test code, it would probably take around 50 uS to receive a byte, or maybe less. And if it works, there are no other tricks/circumventions needed. I will test it, I hopefully will have more time at the weekend.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #29 on: September 29, 2015, 11:31:22 AM »
@Kobuki There's no waiting for a byte.  The RSSI is remapped to DIO0, and is thus directly connected to D2.  As soon as RSSI goes HIGH (which you would expect to be immediately given the deliberately oversensitive settings), the ATMEGA328P is woken up.  What could be faster than that? [ Sorry in advance for jumping in if you were referring to something else.]
« Last Edit: September 29, 2015, 11:42:38 AM by WhiteHare »