nRF5 action!



  • @NeverDie
    Theoretically it is 2 clock ticks at 32768khz so 0.000061035secs i think.
    But how long it takes to go into sleep mode and come out of sleep mode i am not sure.
    But of course the sleep function only allows millis.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    As a follow-up to rmtucker's line of inquiry, what is currently the shortest deep sleep that's supported? Is it one millisecond, or something else?

    Why do you need this type of short sleeps?

    Sleep is for battery powered devices. A device that wakes up more than 1000 times in the second might be hard to drive with a battery.

    @rmtucker said in nRF5 Bluetooth action!:

    @NeverDie
    Theoretically it is 2 clock ticks at 32768khz so 0.000061035secs i think.

    This is correct.

    But how long it takes to go into sleep mode and come out of sleep mode i am not sure.

    It's simple to evaluate with micros() before and after a sleep().


  • Hero Member

    I haven't yet upgraded to the current version, so maybe this is moot (?), but the following code in a loop:

      digitalWrite(TEST_PIN,HIGH);
      sleep(100); // Sleeps for 100ms
      digitalWrite(TEST_PIN,LOW);
      sleep(100); // Sleeps for 100ms 
    

    holds the TEST_PIN first HIGH for 250ms and then LOW for 250ms. That means 150ms of sleep overhead, which seems like a lot.

    I measured the length of time the TEST_PIN is HIGH or LOW using an oscilloscope. Ran it on an Ebyte nRF52832.


  • Hero Member

    Nevermind. I just now upgraded to the current versions, and it seems to be fixed.


  • Hero Member

    So, with the current libraries and an Ebyte nRF52832 that's using its external crystal oscillator, I'm now measuring the sleep overhead as being 260us. I expect that may be even less if using the internal 32768Hz resonator.


  • Hero Member

    I tried measuring the sleep overhead with the Ebyte nRF52832 running on its internal resonator, and surprisingly it wasn't that much faster: it appears to be about 220us.

    Here's the test script:

    #include <MySensors.h>
    
    #define TEST_PIN 19  // (P0.19) 
    
    void setup() 
    {
      hwPinMode(TEST_PIN, OUTPUT_H0H1);  
      digitalWrite(TEST_PIN, LOW);  
    }
    
    void loop() {
      digitalWrite(TEST_PIN,HIGH);
      sleep(1); // Sleeps for 1ms
      digitalWrite(TEST_PIN,LOW);
      sleep(1); // Sleeps for 1ms  
    }
    

    Here's the scope capture:
    0_1504148461469_NewFile1.jpg

    Of course, this assumes (?) that the mcu sleeps for exactly 1ms, and during the extra 220us it is either ramping down or ramping up.

    BTW, I don't anticipate sleeping for a mere 1ms at a time. However, to get a good measurement of the overhead using the oscilliscope I had to set the sleep period that low.

    I can, however, well imagine having a use for sleep periods lasting 100ms.


  • Hero Member

    Anyhow, it's not academic, as the plan is to approximate the "listen-mode" of an RFM69, but using the nRF52832. For that to be power efficient, I need the mcu to wake-up and fall-asleep very, very fast. For comparison, an atmega328p can wake-up in 3.8usec.

    On page of the nRF52832 datasheet, it advertises:

    Fast wake-up using 64 MHz internal oscillator

    However, I'm not sure how to set that up. There's no menu check-box for that on the Arduino IDE tools menu like there is for the 32768Hz internal resonator. On the other hand, I'm not sure that it matters, because apparently the 64Mhz external crystal, which is what's slowing down the wake-up, is required to operate the radio.


  • Hero Member

    Here's the current drain through a 1-ohm resistor:
    0_1504182375553_NewFile2.jpg
    i.e. 1mv=1ma.

    As you can see, there's a rather long tail before it finally falls asleep.

    Here is the same, but superimposed onto the TEST_PIN capture:
    0_1504182439451_NewFile3.jpg


  • Hero Member

    Good news. It appears that DCDC is already implemented on the Ebyte nRF52832 and working automatically!

    Just for grins, I decided to measure the Tx time and current draw from sending a 13 byte payload in a packet, and I was happily surprised to see how low the current draw was:
    0_1504186181522_NewFile4.jpg

    The yellow trace marks the start and stop of the packet transmission process from a software point of view, but the blue trace measures the current (as before 1mv=1ma). As you can see, the transmission current never seems to rise above 2.5ma. The only (?) explanation I can think of is that DCDC must be working. Right? Tx power is set to be 4dbm.

    It would be great if someone else would confirm/refute the measurement.


  • Hardware Contributor

    @NeverDie said in nRF5 Bluetooth action!:

    It would be great if someone else would confirm/refute the measurement.

    I don't think it's possible, from the datasheet peak current is 7.7mA at +4dB with DCDC enabled with 3V power supply.
    Current gain from 3V=>1.7V DCDC conversion is already included in this measurement so you should not be able to go lower.

    How did you make your measurement across the resistor ?


  • Hero Member

    @Nca78
    You're right. It didn't ring true, so I setup some different capture hardware, and this time the image is a lot crisper:
    0_1504198507583_NewFile5.jpg
    This time I powered it from a 3.3v supercap and with the 1 ohm resistor soldered securely onto a PCB, with the o-scope leads on either side of it.

    So, sadly, it doesn't look DCDC after all, because on this capture the peak is exceeding 20ma. 😞

    It's interesting how lengthy (and energy intensive) the phase is that's just prior to the transmission itself. I presume that's mainly just the PLL coming up to speed? It looks as though the actual current expended in the prelude exceeds that of the actual Tx proper!

    I'm guessing that in the earlier scope capture, the probe must have slipped into 10x mode, because the shape is similar, just proportionately reduced by roughly that factor.


  • Hero Member

    BTW, I assembled my third board now, and it sleeps at about 9.9ua. The first one sleeps at about 6ua, and the second at about 9ua. It would be interesting to know why the first board is so much less, but it seems that about 9-10ua is the more typical number. That also seems to agree with @d00616 's measurements.


  • Hero Member

    Interestingly enough, you can put the radio into receive mode and then sleep the mcu with the radio still in receive mode. Here's a screenshot of current consumption while receiving, where I alternate between leaving the mcu active or sleeping it (each for duration of 500ms). In-between, I sleep everything (both radio and mcu) for 1 second:
    0_1504213277663_NewFile7.jpg


  • Hero Member

    Here's the mode that I'm most interested in: Putting the radio into Rx for about 1ms per 100ms interval to listen for remote commands. The rest of the time everthing (both radio and mcu) are in deep sleep waiting for the RTC to wake them up.

    Here's a close-up of the current drawn during that roughly 1ms interval:
    0_1504214970391_NewFile8.jpg

    I ran this just now, and my solar setup can easily handle this load during the daytime, even from deep indoors far from the windows. This was the scenario that really stressed the RFM69+atmega328p combo when I tried doing it using the RFM69's listen mode. I'll see tonight how the 10F supercap handles the load without any solar assist. 🙂

    Because of the nRF52839's 2Mbps datarate, I can probably cut the listen window down substantially from 1ms to much less (much less than would be possible with an RFM69, due to its maximum of 300kbps datarate), but for ease of programming I'm starting with this.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    Here's the mode that I'm most interested in: Putting the radio into Rx for about 1ms per 100ms interval to listen for remote commands. The rest of the time everthing (both radio and mcu) are in deep sleep waiting for the RTC to wake them up.

    When you take a look into the PPI section, you are able to let the CPU sleep until a radio packet is received. With PPI, the listen mode can be activated and deactivated without CPU interaction.

    The nRF5 MCUs are able to to a lot of things without waking up the CPU. That's a really cool feature.


  • Hero Member

    @d00616 said in nRF5 Bluetooth action!:

    @NeverDie said in nRF5 Bluetooth action!:

    Here's the mode that I'm most interested in: Putting the radio into Rx for about 1ms per 100ms interval to listen for remote commands. The rest of the time everthing (both radio and mcu) are in deep sleep waiting for the RTC to wake them up.

    When you take a look into the PPI section, you are able to let the CPU sleep until a radio packet is received. With PPI, the listen mode can be activated and deactivated without CPU interaction.

    The nRF5 MCUs are able to to a lot of things without waking up the CPU. That's a really cool feature.

    Sounds like it has potential. Any demo code for this? The datasheet seems a bit sketchy.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    @d00616 said in nRF5 Bluetooth action!:

    @NeverDie said in nRF5 Bluetooth action!:

    Here's the mode that I'm most interested in: Putting the radio into Rx for about 1ms per 100ms interval to listen for remote commands. The rest of the time everthing (both radio and mcu) are in deep sleep waiting for the RTC to wake them up.

    When you take a look into the PPI section, you are able to let the CPU sleep until a radio packet is received. With PPI, the listen mode can be activated and deactivated without CPU interaction.
    The nRF5 MCUs are able to to a lot of things without waking up the CPU. That's a really cool feature.

    Sounds like it has potential. Any demo code for this? The datasheet seems a bit sketchy.

    These are some snippets of the radio code. There are fully useable PPI and some predefined. For fully useable PPI into the EEP register, you put the address of an EVENT register and in the TEP register, you put the pointer to an TASK register.

       /** Configure PPI (Programmable peripheral interconnect) */
        // Start timer on END event
        NRF_PPI->CH[NRF5_ESB_PPI_TIMER_START].EEP = (uint32_t)&NRF_RADIO->EVENTS_END;
        NRF_PPI->CH[NRF5_ESB_PPI_TIMER_START].TEP = (uint32_t)&NRF5_RADIO_TIMER->TASKS_START;
        // Disable Radio after CC[0]
        NRF_PPI->CH[NRF5_ESB_PPI_TIMER_RADIO_DISABLE].EEP = (uint32_t)&NRF5_RADIO_TIMER->EVENTS_COMPARE[0];
        NRF_PPI->CH[NRF5_ESB_PPI_TIMER_RADIO_DISABLE].TEP = (uint32_t)&NRF_RADIO->TASKS_DISABLE;
        ...
        // Set PPI
         NRF_PPI->CHENSET = NRF5_ESB_PPI_BITS;
        ...
      // Clear PPI
        NRF_PPI->CHENCLR = NRF5_ESB_PPI_BITS;
    

    Then you have to enable or disable the register. It could be necessary to reset the events. You can use the NRF_RESET_EVENT macro to do this job.

     NRF_RESET_EVENT(NRF5_RADIO_TIMER->EVENTS_COMPARE[0]);

  • Hero Member

    I have a brute force version of "listen mode" working using just the libraries, but I have to re-initialize the radio after each cycle because it appears to lose its settings every time I sleep it.

    Anyway, finding a way to add DCDC mode to these modules will probably have the biggest near-term impact on current consumption. That said, I'm sure plenty of energy savings can also be found by honing the code.


  • Hero Member

    Actually, even just sleeping the MCU with a simple command like:

    sleep(100);
    

    is apparently enough to require a re-init of the radio afterward. Not sure why that would be.


  • Hero Member

    Comparing Figures 169 and 170 in the nRF52832 datasheet, it looks as though simply adding two inductors in series between DCC and DEC4 should be all that's needed to provide the needed hardware support for DC/DC. Looks as though the 10uH inductor also needs to be able to support a minimum of 50ma, according to the BOM (Table 145).

    So, is it as simple as that together with enabling register DCDCEN? Or, is there anything more to it?


  • Hardware Contributor

    Yes. This is like that. I use 2 inductors (better) in serie. Why more complicated 😉


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    Actually, even just sleeping the MCU with a simple command like:
    sleep(100);

    is apparently enough to require a re-init of the radio afterward. Not sure why that would be.

    sleep() deinitializes the transport with transportDisable(). This results in power down the radio.

    At the moment I review the ESB code. I think the nRF5 is 12-13µs after an nRF24 in RX mode and 432µs before an nRF24 in TX. This can result in unstable connections when debug messages are disabled.


  • Hero Member

    Sort-of working. Here's a screen shot with the DC/DC modification. Compare to the earlier one above:
    0_1504447563700_NewFile1.jpg
    Probably non-optimal placement of the inductors: between the DCC and DEC4 pins on my breakout board for the nRF52832.

    This is reason enough to do an new version of the breakout for the Ebyte module to improve the inductor positioning.

    Here's the enable code:

      NRF_POWER->DCDCEN=1;  //enable the DCDC voltage regulator as the default.
    

    If it's this easy, I'm just surprised that the module makers haven't included it. The difference in build cost is de minimus, but the difference in delivered value is huge.

    Also, it sounds like I'll have to write a variant of sleep that sleeps just the MPU while leaving the radio in receive mode. That's an easy win to improve the current consumption.


  • Hero Member

    Good news! I went back and re-rechecked using an un-modified Ebyte module, and, indeed, this time I'm sure that the DCDC inductors are already on it! What follows is the proof. Here is the current drawn when the above DCDCEN is enabled on an unmodified Ebyte module:

    0_1504461945615_NewFile2.jpg

    Now, here is the current drawn with the exact same script on the exact same unmodified Ebyte module, but with the DCDCEN line of code commented out:

    0_1504461988147_NewFile3.jpg

    QED.

    As you can see, the savings in current consumption are considerable with the DCDC enabled!

    [Edit: although looking at it again, the timescale seems way off. Argh. Something still isn't right.]


  • Hero Member

    Scratch the preceeding post. I redid it more carefully this time, and I believe it confirms that the Ebyte module does not have the two inductors required for DC/DC mode.

    Here is the current drawn by an unmodified Ebyte nRF52832 module which is programmed to be receiving for about 1.5ms every 100ms:
    0_1504472450738_NewFile1.jpg
    0_1504472465572_NewFile2.jpg


  • Hero Member

    Here is what happens with exactly the same hardware (no inductors yet added), but with DCDCEN enabled:
    0_1504472667206_NewFile3.jpg

    0_1504472696820_NewFile4.jpg
    It basically seems caught in a boot loop.


  • Hero Member

    Now, adding the two inductors between DCC and DEC4, and re-measuring, we get:
    0_1504472770946_NewFile1.jpg

    0_1504472782958_NewFile2.jpg

    No less importantly, it does receive and decode packets!

    Conclusion: Ebyte nRF52832 modules don't come with the DC/DC inductors already installed. However, they can be added, resulting in some current reduction.


  • Hero Member

    I've baked these findings into a new breakout board for the Ebyte nRF52832:
    https://www.openhardware.io/view/471
    The new breakout board will enable the module to work in DC/DC mode.


  • Hero Member

    I may have found a clue as to why the reset pin (pin0.21) on the nRF52832 isn't working.

    On the nRF52832 DK, I read the following register values:
    PSELRESET[0]=21
    PSELRESET[1]=21

    which is as expected. However, on the Ebyte nRF52832 module, I read those register values as:
    PSELRESET[0]=4294967295
    PSELRESET[1]=4294967295

    which makes no sense. The values match, but they don't correspond to a pin number that can represent RESET.

    These two registers are described in the nRF52832 datasheet.


  • Mod

    @NeverDie not sure if you've already noticed, but 4294967295 is the maximum value for an unsigned 32-bit integer. So the value is 0xFFFFFFFF. That often means uninitialized. I don't know why it would be uninitialized though.


  • Hero Member

    @mfalkvidd

    Maybe because they just never were?
    Those particular registers are "The user information configuration registers (UICRs) are non-volatile memory (NVM) registers for configuring user specific settings." So, it would seem that initializing them just once would be enough, since they're non-volatile.

    In any case, good catch! It explains both why they are that value and also why they match.


  • Hero Member

    @NeverDie said in nRF5 Bluetooth action!:

    4294967295

    Also, since 4294967295 equals 0xFFFFFFFF, then bit 31 is a '1', which, according to the datasheet, means the pin is disconnected (see section 14.1.60 PSELRESET[0] of the datasheet for the detail].


  • Hero Member

    @mfalkvidd said in nRF5 Bluetooth action!:

    So the value is 0xFFFFFFFF. That often means uninitialized. I don't know why it would be uninitialized though.

    There's a chance we may have unwittingly done it ourselves! Remember back to when we were doing an explicit "Erase All"? From the datasheet:

    11.5 Erase all
    When erase is enabled, the whole Flash and UICR can be erased in one operation by using the ERASEALL
    register.

    Furthermore, from page 29 of the datasheet:

    After erasing UICR all bits in UICR are set to '1'.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    @mfalkvidd said in nRF5 Bluetooth action!:

    So the value is 0xFFFFFFFF. That often means uninitialized. I don't know why it would be uninitialized though.

    There's a chance we may have unwittingly done it ourselves! Remember back to when we were doing an explicit "Erase All"? From the datasheet:

    This is part of the arduino-nrf5 code -> https://github.com/sandeepmistry/arduino-nRF5/blob/dc53980c8bac27898fca90d8ecb268e11111edc1/cores/nRF5/SDK/components/toolchain/system_nrf52.c#L156

    I don't have any idea why this is not included in the binary. When the reset menu is selected then "-DCONFIG_GPIO_AS_PINRESET" is given to gcc.

    When system_nrf52.c is completely ignored, then the erratas are not handled.


  • Hero Member

    Here is some verbose code which properly sets the registers to use pin P0.21 as the RESET pin:

    Serial.println("Testing...");
    delay(10000);  //give preparation time to open serial tty
    Serial.print(counter);
    Serial.print(", PSELRESET[0]=");
    Serial.println(NRF_UICR-> PSELRESET[0]);
    Serial.print(counter++);
    Serial.print(", PSELRESET[1]=");
    Serial.println(NRF_UICR-> PSELRESET[1]);
    
    Serial.println();
    Serial.println("Write-enabling CONFIG.");
    NRF_NVMC->CONFIG=1;  // Write enable the UICR
    
    Serial.println();
    Serial.println("Now designating pin pO.21 as the RESET pin.");
    NRF_UICR-> PSELRESET[0]=21;  //designate pin pO.21 as the RESET pin
    NRF_UICR-> PSELRESET[1]=21;  //designate pin pO.21 as the RESET pin
    
    Serial.println();
    Serial.println("Confirming that RESET pin assigment took hold:");
    Serial.print(counter);
    Serial.print(", PSELRESET[0]=");
    Serial.println(NRF_UICR-> PSELRESET[0]);
    Serial.print(counter++);
    Serial.print(", PSELRESET[1]=");
    Serial.println(NRF_UICR-> PSELRESET[1]);
    
    Serial.println();
    Serial.println("Return CONFIG to read-only mode.");
    NRF_NVMC->CONFIG=0;  // Put the UICR back into read-only mode.
    

    Running it once seems to be good enough, unless there were to occur another "Erase All" or "Burn bootloader" event.

    Here is the output from running the code which shows that it succeeded:

    Testing...
    0, PSELRESET[0]=4294967295
    0, PSELRESET[1]=4294967295
    
    Write-enabling CONFIG.
    
    Now designating pin pO.21 as the RESET pin.
    
    Confirming that RESET pin assigment took hold:
    1, PSELRESET[0]=21
    1, PSELRESET[1]=21
    
    Return CONFIG to read-only mode.
    

  • Hero Member

    Until a more elegant solution can be found, I'm using this in the setup() routine as the workaround:

      if (((NRF_UICR-> PSELRESET[0])==0xFFFFFFFF) && ((NRF_UICR-> PSELRESET[1])==0xFFFFFFFF)) { //if the two RESET registers are erased
        NRF_NVMC->CONFIG=1;  // Write enable the UICR
        NRF_UICR-> PSELRESET[0]=21;  //designate pin P0.21 as the RESET pin
        NRF_UICR-> PSELRESET[1]=21;  //designate pin P0.21 as the RESET pin
        NRF_NVMC->CONFIG=0;  // Put the UICR back into read-only mode.
      }
    

    The code has the positive virtue of not writing to the RESET rregisters unless both registers are erased. That helps ensure that the non-volatile memory does not get worn out prematurely.


  • Hero Member

    @NeverDie said in nRF5 Bluetooth action!:

    Until a more elegant solution can be found, I'm using this in the setup() routine as the workaround:

      if (((NRF_UICR-> PSELRESET[0])==0xFFFFFFFF) && ((NRF_UICR-> PSELRESET[1])==0xFFFFFFFF)) { //if the two RESET registers are erased
        NRF_NVMC->CONFIG=1;  // Write enable the UICR
        NRF_UICR-> PSELRESET[0]=21;  //designate pin P0.21 as the RESET pin
        NRF_UICR-> PSELRESET[1]=21;  //designate pin P0.21 as the RESET pin
        NRF_NVMC->CONFIG=0;  // Put the UICR back into read-only mode.
      }
    

    The code has the positive virtue of not writing to the RESET rregisters unless both registers are erased. That helps ensure that the non-volatile memory does not get worn out prematurely.

    Good news! I've confirmed that doing this does indeed solve the problem I previously had with the EByte nRF52832 module not reacting to a reset on pin P0.21. After inserting the above code block into the nRF52832's setup() routine, I can now, using ESP-LINK, remotely reset an nRF52832 module:
    https://www.openhardware.io/view/443/nRF52832-ESP-LINK-Shield-for-ESP8266-Wemos-D1-Mini


  • Hero Member

    With that issue now settled, I'm moving on to a different topic: what happens if you put the radio into Tx mode, but with an empty buffer (i.e. nothing to send)? In this scenario an RFM69 transmits a continuous pre-amble, and I'm wondering whether the nRF52832 does the same?
    With an empty buffer, does it transmit anything at all? Anyone happen to know?

    The reason I ask is that I want to program the radio to send a continuous signal so as to quickly wake-up a receiver. With packets, there's the lag time of receiving and decoding the packet, rather than just reacting to a high RSSI. In this way, I can use much narrower listen windows and thereby save a lot of current consumption.


  • Hero Member

    According to the datasheet, the typical RSSI sample period is just 0.25us. However, what spoils that a bit is that the radio has to come up to speed beforehand.

    Anyhow, on the receive side, I now have at least that much working.


  • Hero Member

    It looks as though the start-up time for the radio is about 390us. So, it does save a lot of current to first check the RSSI level rather than to always listen for a packet.


  • Hero Member

    When I measure RSSI on the nRF52832, I get what seems like a rather odd range of values: between about 94 and 127. If I have no other nodes transmitting, then the RSSI is generally around 100. If I set up another node which deliberately transmits on the same channel, then the RSSI is pegged at 127.

    Is that what others here are also seeing? Here's the test code:

    uint8_t theRSSI;
    void loop() {
      
    NRF_RADIO->TASKS_RXEN=1;  //start revving up the receiver
    while (!(NRF_RADIO->EVENTS_READY)) {} //busy-wait until radio ready to receive
    NRF_RADIO->TASKS_RSSISTART=1;  //Take exactly one RSSI sample
    while (!(NRF_RADIO->EVENTS_RSSIEND)) {}  //Busy-wait until RSSI sample is completed.
    theRSSI = NRF_RADIO->RSSISAMPLE;
    
    Serial.println(theRSSI);
    Serial.flush();
    sleep(1000);
    }
    

  • Hero Member

    Unfortunately, when I use the above code block and test the current using an oscilliscope, it becomes clear that the radio never actually goes to sleep:

    0_1504740304312_NewFile1.jpg
    So, to do that, I add the line:

    NRF_RADIO->TASKS_DISABLE=1;  //turn-off the radio
    

    just prior to sleep(100). Doing that largely eliminates the current drain while sleeping:
    0_1504740345602_NewFile3.jpg

    However, if I do that, then the RSSI that gets reported is always 127. Why? Do I need some other way to check the radio states? Maybe STATE from section 23.14.25 STATE of the datasheet would work better?


  • Hero Member

    Found a breakout board for the nRF51822-04: https://oshpark.com/shared_projects/zqDQaykJ
    alt text


  • Hero Member

    The datasheet is possibly a bit misleading when it says:

    For the RSSI sample to be valid the radio has to be enabled in receive mode (RXEN task) and the reception
    has to be started (READY event followed by START task).

    I'm finding that the radio needs to be in either RXIDLE state or RX state to get a plausible RSSI measurement. I can't get a reasonable RSSI measurement while within the RXRU state.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    The datasheet is possibly a bit misleading when it says:

    For the RSSI sample to be valid the radio has to be enabled in receive mode (RXEN task) and the reception
    has to be started (READY event followed by START task).

    I'm finding that the radio needs to be in either RXIDLE state or RX state to get a plausible RSSI measurement. I can't get a reasonable RSSI measurement while within the RXEN state.

    In the ESB code, I use the bitcounter event to start the rssi sample task via PPI. The results are looking plausible.


  • Hero Member

    I've found that I get a slightly stronger RSSI signal by about 3dB if I measure it while in the RX state rather than the RXIDLE state.


  • Hero Member

    @d00616 said in nRF5 Bluetooth action!:

    In the ESB code, I use the bitcounter event to start the rssi sample task via PPI. The results are looking plausible.

    Do you know of any good PPI tutorials? The datasheet seems awfully skimpy on its explanation of exactly how to use it.

    Right now I have RSSI triggers working on the receiver (presently using the MCU, not PPI), but it takes 1400 samples to guarantee not missing any transmissions. That's because of the gap between single shot packets when they get sent. If I can reduce that to one sample, by finding a way to make a transmitter transmit continuously, then that will save a lot of energy on the receiver.

    There is a way to do more rapid fire transmission of packets, so that would be the fall-back plan if I can't find a way to, for example, send a continuous preamble.


  • Hero Member

    Answering my own question: it turns out that if you enter into TX mode without any payload, it just sends a null packet and returns to TXIDLE. So, it is not like the RFM69, which would simply send an indefinitely long preamble until there's a payload to send.

    The goal is to close the gap between packets as much as possible. So, I'm getting some improvement by just immediately switching back into TX mode (to send another null packet) the moment I've confirmed that TXIDLE state has re-occured.


  • Hero Member

    As it turns out, using the above method packs the null packets so tightly that I can rely on a single RSSI measurement (instead of 1400 of them) to guarantee that a transmission won't be missed. So, the goal is achieved.

    It sounds as though combining PPI with this would drive the energy consumption even lower! 🙂


  • Contest Winner

    @NeverDie Thank you sharing your experience here. It helps me of better understanding some nRF5 internals. It would be awesome if you share your code.

    @NeverDie said in nRF5 Bluetooth action!:

    Do you know of any good PPI tutorials? The datasheet seems awfully skimpy on its explanation of exactly how to use it.

    To understand PPI you have to be in mind that nearly everything is driven by tasks and events. If you want to do something, you have to start a task like 'NRF_RADIO->TASKS_TXEN=1'. If a task ends it generates an event like 'NRF_RADIO->EVENTS_READY'. You can replace NRF_RADIO with another periphery the registers have an equal naming scheme.

    For an event an Interrupt can be enabled with the NRF_RADIO->INTENSET register. Each event correspondents with a bit in that register. In an interrupt, you have to reset the NRF_RADIO->EVENTS_READY register to 0 to allow triggering a new interrupt. For compatibility, you can use the NRF_RESET_EVENT macro in interrupts. This reads back the register on nRF52 to avoid caching effects. Interrupts doesn't matter for PPI 🙂

    The next fine thing are Shortcuts. Shortcuts are limited to the same peripheral unit. Bits in the NRF_RADIO->SHORTS register are corresponding to a connection between an event and a test. If the event is triggered the task is started. This allows to trigger things like send an packet after the radio is ready. To use this, you have to enable the shortcut in the NRF_RADIO->SHORTS register.

    To break the limits of shortcuts, there is the PPI unit with 32 channels. Some of the channels are predefined but interesting to see how things are implemented with BLE. The other PPI channels are flexible. To use one of these channels, you have to write a pointer of your event register, like '(uint32_t)&NRF_RADIO->EVENTS_END' to the NRF_PPI->CH[YOUR_CHANNEL].EEP register and a pointer to your task you want to start in the NRF_PPI->CH[YOUR_CHANNEL].TEP register like '(uint32_t)&NRF_TIMER0->TASKS_START'. Then you have to enable the PPI channel by setting the corresponding bit like 'NRF_PPI->CHENSET |= (1 << COUR_CHANNEL)' that's all.

    The nRF52, but not the nRF52 comes with NRF_PPI->FORK[YOUR_CHANNEL].TEP registers. in my reading you can start a second task with this register like writing to NRF_PPI->CH[YOUR_CHANNEL].TEP.

    I have no idea about using the PPI Groups.

    Arudino provides a PPI library for the primo: http://cdn.devarduino.org/learning/reference/ppi I think we have to use this library to be compatible in the future. I hope there is a chance to port things to arduino-nrf5 back.

    Edit: The arduino PPI library is not flexible enough to support radio events. 😞


  • Hero Member

    Thanks! At least notionally, the PPI sounds excellent. Presently, if I want to move the radio into a particular state which takes a few state changes to get there, using the MCU with a conservative coding style, I have to initiate the first state change, then busy-wait until the new state is confirmed, then make the next state-change, etc. It sounds as though the PPI is a good fit for this, because it would eliminate the busy-waits. It would automatically transition from one state to the next using just the interrupt scheme you outlined until the target state is reached. Well, at least in theory. Meanwhile the CPU could be doing other things or sleeping. This does sound like a definite improvement, especially for more efficient control over the radio. 🙂


  • Hero Member

    @d00616 said in nRF5 Bluetooth action!:

    @NeverDie Thank you sharing your experience here. It helps me of better understanding some nRF5 internals. It would be awesome if you share your code.

    Here it is:

    #include <MySensors.h>
    #include <nrf.h>
    
    void setup() 
    {
      NRF_POWER->DCDCEN=1;  //enable the DCDC voltage regulator as the default.
    
      //guarantee RESET pin is working
      if (((NRF_UICR-> PSELRESET[0])==0xFFFFFFFF) && ((NRF_UICR-> PSELRESET[1])==0xFFFFFFFF)) { //if the two RESET registers are erased
        NRF_NVMC->CONFIG=1;  // Write enable the UICR
        NRF_UICR-> PSELRESET[0]=21;  //designate pin P0.21 as the RESET pin
        NRF_UICR-> PSELRESET[1]=21;  //designate pin P0.21 as the RESET pin
        NRF_NVMC->CONFIG=0;  // Put the UICR back into read-only mode.
      }
    
      NRF_RADIO->FREQUENCY=123;
      NRF_RADIO->MODE=2;  //set 250kbps datarate.  May as well stretch out the NULL packet as much as possible.
      
      NRF_RADIO->TASKS_DISABLE=1;  //turn-off the radio to establish known state.
      while (NRF_RADIO->STATE!=0) {}  //busy-wait until radio is disabled
      NRF_RADIO->TASKS_TXEN=1;  //wake-up the radio
      while ((NRF_RADIO->STATE)!=10) {}  //busy-wait until radio has started TXIDLE
      
      //Assertion: radio is now in TXIDLE state.
    }
    
    
    void loop() {
    
        //assume radio is in TXIDLE state.
        NRF_RADIO->TASKS_START=1;  //Move from TXIDLE state to TX state.  This sends a NULL packet.
        while ((NRF_RADIO->STATE)!=11) {}  //busy-wait until radio is in TX state
        while ((NRF_RADIO->STATE)==11) {}  //busy-wait until radio is back to TXIDLE state
        //Assertion: radio is now back to TXIDLE state
     }
    
    

  • Hero Member

    So, to make the above code work as a PPI, all I would need is some kind of linkage such that whenever the "event" of TXIDLE occurs, then a "task" (in this case it would be TASKS_START) is executed to move the radio back into the TX state.

    Hmmm.. Still not obvious though from just the datasheet how to actually setup even that simple linkage.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    So, to make the above code work as a PPI, all I would need is some kind of linkage such that whenever the "event" of TXIDLE occurs, then a "task" (in this case it would be TASKS_START) is executed to move the radio back into the TX state.

    This is a use case for shortcuts. PPI is not required.

    There is no TXIDLE event but looking at the state diagram is TXIDLE a result of ether READY or END event. You can enable following shortcurts:

    NRF_RADIO->SHORTS = RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_START_Msk;
    

    In PPI this should be the code (untested):

    #define CHANNEL (1)
    NRF_PPI->CH[CHANNEL].EEP = (uint32_t)&NRF_RADIO->EVENTS_END;
    NRF_PPI->CH[CHANNEL].TEP = (uint32_t)&NRF_RADIO->TASKS_START;
    NRF_PPI->CH[CHANNEL+1].EEP = (uint32_t)&NRF_RADIO->EVENTS_READY;
    NRF_PPI->CH[CHANNEL]+1.TEP = (uint32_t)&NRF_RADIO->TASKS_START;
    NRF_PPI->CHENSET = (1 << CHANNEL) | (1 <<( CHANNEL+1));
    

  • Hero Member

    Thanks! That helps my understanding quite a bit. I've tested the following shortcut code, and it works:

    
    #include <MySensors.h>
    #include <nrf.h>
    
    void setup() 
    {
      NRF_POWER->DCDCEN=1;  //enable the DCDC voltage regulator as the default.
    
      //guarantee RESET pin is working
      if (((NRF_UICR-> PSELRESET[0])==0xFFFFFFFF) && ((NRF_UICR-> PSELRESET[1])==0xFFFFFFFF)) { //if the two RESET registers are erased
        NRF_NVMC->CONFIG=1;  // Write enable the UICR
        NRF_UICR-> PSELRESET[0]=21;  //designate pin P0.21 as the RESET pin
        NRF_UICR-> PSELRESET[1]=21;  //designate pin P0.21 as the RESET pin
        NRF_NVMC->CONFIG=0;  // Put the UICR back into read-only mode.
      }
    
      NRF_RADIO->FREQUENCY=123;
      NRF_RADIO->MODE=2;  //set 250kbps datarate.  May as well stretch out the NULL packet as much as possible.
      
      NRF_RADIO->TASKS_DISABLE=1;  //turn-off the radio to establish known state.
      while (NRF_RADIO->STATE!=0) {}  //busy-wait until radio is disabled
      NRF_RADIO->SHORTS = B100001;  //Implement shortcuts: READY_START and END_START
      NRF_RADIO->TASKS_TXEN=1;  //wake-up the radio transmitter and move it into state TXIDLE.
    
      //The shortcuts will take-over the moment the state TXIDLE becomes activated.
    }
    
    
    void loop() {
    
    }
    
    

  • Hero Member

    Is there any example code which illustrates the use of interrupts on the nRF52832?


  • Hero Member

    Looks as though it should be possible to send tightly packed meaningful packets, not just null packets, using almost the same methodology.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    Is there any example code which illustrates the use of interrupts on the nRF52832?

    Yes. In a sketch, you have to put the interrupt routine into one line. You can define the interrupt only once. If you want to use the radio ISR, you can't enable the radio in MySensors.

    https://github.com/sandeepmistry/arduino-nRF5/issues/52

    https://github.com/mysensors/MySensors/blob/development/drivers/NRF5/Radio_ESB.cpp#L500


  • Hero Member

    Interestingly enough, it turns out all I need to do is transmit one packet, and afterward just leave the radio in TXIDLE mode. That's because, as indicated in the datasheet, it transmits a carrier wave of one's (or any pattern you program) after the packet, expecting that another packet will be sent soon. This is illustrated in Figure 37 of the DS.


  • Hero Member

    So, I've got the transmit side of this problem figured out. Next up: the receiver side, which already works using the MCU.
    The next step will be to see whether I can setup timed events from the RTC which can be used to trigger the PPI to measure the RSSI without waking up the MCU. Also, I'll need some way for the PPI to evaluate the magnitude of the RSSI without involving the MCU. Ideally it would also trigger a Rx sequence if the RSSI is above threshold and wake the MCU if something gets received. Not sure how much of this will be possible, but that's the wish list.

    I'd say the energy consumption is already pretty good after switching to the RSSI paradigm, but if this succeeds, then it may cut what remains of the energy consumption roughly in half. At that point, I think we will have wrung just about every possible bit of efficiency out of this radio, with the remaining to-do's as mostly mop-up and maybe some fine tuning (e.g. to better mitigate against false positives on the RSSI threshhold trigger).


  • Hero Member

    So, I figure the way to get started is to do something "easy", like maybe use the PPI to blink an LED.

    We want the lower power RTC, not the system clock. We want to use the RTC TICK event, so that the mpu can be powered down while the PPI is running.

    So, because I want a timer event every 100ms, that means the prescaler should be 3276.


  • Hero Member

    So, just starting on this, where I'm at is:

    #include <nrf.h>
    #include <MySensors.h>
    
    
    #define LED_PIN 18
    
    bool toggle=false;  //track whether or not to toggle the LED pin
    
    void setup() {
      NRF_CLOCK->LFCLKSRC=1;  //use the crystal oscillator.
      NRF_CLOCK->TASKS_LFCLKSTART=1;  //start the crystal oscillator clock
      while (!(NRF_CLOCK->EVENTS_LFCLKSTARTED)) {}  //busy-wait until the clock is confirmed started.
    
      NRF_RTC1->TASKS_STOP=1;  //stop the RTC so that we can set the prescaler
      NRF_RTC1->PRESCALER=3276;  //once per 100ms
      NRF_RTC1->TASKS_START=1;  //start the RTC so that we can start getting TICK events
    
      hwPinMode(LED_PIN,OUTPUT_H0H1);  //establish P0.18 as the LED pin.
    }
    
    void loop() {
      if (NRF_RTC1->EVENTS_TICK) {
        toggle=!toggle;
        digitalWrite(LED_PIN,toggle);
      }
    }
    

    Unfortunately, this does not work because (NRF_RTC1->EVENTS_TICK) always reads as zero. Not sure why(?).



  • @NeverDie you will need long range capabilities on both sides of the link. So two preview kits work great. Long range is supported by SDK 14 and the current softdevice.



  • @scalz the nRF52832 has a hotter receiver. ( better sensitivity.) at 1 mb/ s then the nRF24l series. Overall link Budget is better. 840 even better with a 8dB output.


  • Hardware Contributor

    @Jokgi
    of course I agree !
    that's why in the past i preferred rfm69 modules (better range of course, but more power hungry). 832 being better than nrf24, i'm now using it. And I also like the 840dk (neat package) 👍
    That said, if i remember well, nrf52832 is not fully BLE5 long range compatible as 840 is.


  • Hero Member

    @Jokgi said in nRF5 Bluetooth action!:

    @NeverDie you will need long range capabilities on both sides of the link. So two preview kits work great. Long range is supported by SDK 14 and the current softdevice.

    I'm not disagreeing, but presently modules for it (other than the preview DK) aren't yet available. Meanwhile, hopefully nearly all of what's being learned here about the nRF52832 will be of direct relevance. For instance: PPI.


  • Hero Member

    @NeverDie said in nRF5 Bluetooth action!:

    Unfortunately, this does not work because (NRF_RTC1->EVENTS_TICK) always reads as zero. Not sure why(?).

    It should be working, but it isn't. Nor do I see a way to check it with an oscilliscope. So, my current theory is that it gets set but cleared so quickly that it can't be read by the MCU. So, the next step will be to assume that it is, in fact, working, and to use it as a PPI trigger, which is what this is all building toward anyway.

    On the other hand, perhaps there's an easy way to have the EVENTS_TICK set an interrupt bit, which would persist until it was cleared? Hmmm. No, not quite, but there is INTENSET, which will set an interrupt on an EVENT_TICK. That will do. Exactly which interrupt gets triggered though? Figure 46 shows that an IRQ signal is sent to NVIC ( the Nested Vectored Interrupt Controller). According to the table in sectoin 7.3, the NVIC has 37 interrupt vectors. According to section 15.8:

    A peripheral only occupies one interrupt, and the interrupt number follows the peripheral ID. For example, the
    peripheral with ID=4 is connected to interrupt number 4 in the Nested Vectored Interrupt Controller (NVIC).

    So, based on that, we need to know the ID number for the RTC, and then we'll know which interrupt number to track. According to Table 10, the Peripheral ID for the RTC is 11 (well, at least it is for the RTC0, so I will recode to use RTC0 instead of RTC1).

    Now, according to Table 10, the memory location that corresponds to Peripheral ID 11 is 0x4000B000. Therefore, it is this memory location we need to examine to know if a TICK interrupt has occured.


  • Hero Member

    Close, but no cigar. What I found out is that if I set the TICK interrupt with:

          NRF_RTC0->INTENSET=1;  //set the TICK interrupt bit
    

    then at the following memory addresses, the value stored there immediately becomes 1:
    4000B300
    4000B304
    4000B308

    and if I clear the TICK interrupt with:

          NRF_RTC0->INTENCLR=1;  //clear the TICK interrupt bit
    

    then the values at those same memory addresses immediately becomes zero. I can toggle back and forth as much as I want, and this is always true.

    However, none of this is telling me whether the TICK interrupt has actually triggered. Where do I find that?

    Based on the current pre-scaler, COUNTER increments once every TICK (i.e. once every 100ms). However, is there an actual TICK flag somewhere that goes high at those times and then low again after getting cleared? Or, is it only accessible indirectly by using PPI?


  • Hero Member

    OK, I came up with a simple equivalent. Basically, every time COUNTER is incremented, I reset it to zero. It then effectively acts much the way a TICK should. For whatever reason, once EVENTS_TICK goes high, it just stays high forever. So, it doesn't seem very useful per se, though maybe there's a way to clear it that I haven't yet found.


  • Hero Member

    Strangely enough, the overflow is the same: once it goes HIGH, it stays that way:
    https://pastebin.com/vypuVJeh

    So, I would think there must be some way (?) to clear them.


  • Hero Member

    I found the answer. Unlike EVENTS in other peripherals, which are read-only, the EVENTS in RTC are RW. So, the way you clear the TICK and OVRFLW events is just by setting them to zero manually:
    e.g.

    NRF_RTC0->EVENTS_TICK=0;
    

    LOL. Of course, the DS never mentions this.

    In any case, with that change, it can now work properly:
    https://pastebin.com/nHWAGFkd


  • Hero Member

    However, it does raise the question: if I were to use EVENTS_TICK to trigger some PPI actions, how could PPI also be used to set EVENTS_TICK back to zero so that those actions can be repeated on the next TICK? I haven't yet found an PPI TASKS that can directly manipulate, or even just clear, a particular memory location.


  • Hero Member

    Since there are no apparent shortcuts pertaining to the RTC, it looks as though all non-MCU manipulations will have to happen via PPI.

    I don't see how to clear a TICK using PPI, so I think the simplest thing would be clearing the counter back to zero if it hits one.

    If there's no way to do this basic thing, then I see no way to have a "listen mode" equivalent for the nRF52832 that runs via PPI.

    So, adapting what @d00616 wrote earlier, maybe the PPI code to do that would be:

      #define CHANNEL (1)
      NRF_PPI->CH[CHANNEL].EEP = (uint32_t)&NRF_RTC0->COUNTER;  //when COUNTER goes from zero to one.
      NRF_PPI->CH[CHANNEL].TEP = (uint32_t)&NRF_RTC0->TASKS_CLEAR;  //clear COUNTER back to zero.
      NRF_PPI->CHENSET = (1 << CHANNEL) ;
    

    Well, it does compile, but it doesn't work. 😞 I think it doesn't work because COUNTER is not an event.

    Unfortunately, changing COUNTER to EVENTS_TICK fails also:

      NRF_PPI->CH[0].EEP = (uint32_t)&NRF_RTC0->EVENTS_TICK;  //when TICK occurs.
      NRF_PPI->CH[0].TEP = (uint32_t)&NRF_RTC0->TASKS_CLEAR;  //clear COUNTER back to zero.
      NRF_PPI->CHENSET=1;   //Enable Channel 0.
    

    Unfortunately, the PPI Example code from Nordic's SDK doesn't look even remotely similar to what we're doing here.

    Anyhow, the last thing I tried was this:

      NRF_RTC0->INTENSET=1;  //Allows TICK to create an interrupt.
      NRF_PPI->CH[0].EEP = (uint32_t)&NRF_RTC0->EVENTS_TICK;  //when TICK occurs.
      NRF_PPI->CH[0].TEP = (uint32_t)&NRF_RTC0->TASKS_CLEAR;  //clear COUNTER back to zero.
      NRF_PPI->CHENSET=1; //enable Channel 0.
    

    hoping that it might make a difference, but it still fails. Why? What is wrong with it?



  • @NeverDie said in nRF5 Bluetooth action!:

    EVENTS_TICK

    From the datasheet:

    15.6 Events
    Events are used to notify peripherals and the CPU about events that have happened, for example, a state
    change in a peripheral. A peripheral may generate multiple events with each event having a separate
    register in that peripheral’s event register group.
    An event is generated when the peripheral itself toggles the corresponding event signal, and the event
    register is updated to reflect that the event has been generated. See Figure 10: Tasks, events, shortcuts,
    and interrupts on page 68. An event register is only cleared when firmware writes a '0' to it.
    Events can be generated by the peripheral even when the event register is set to '1'.
    

    Maybe I don't get the problem here, but the way I see it, you have to actively write a '0' to the event register to clear it, but in fact it shouldn't matter, because the timer can nevertheless generate an event.


  • Hero Member

    @Uhrheber said in nRF5 Bluetooth action!:

    you have to actively write a '0' to the event register to clear it

    This is right. I later confirmed it (see above), but thank you for the passage in the datasheet. I could have sworn that somewhere the DS said that events were read-only, but the passage you quoted contradicts that recollection. So, thank you again.

    Any thoughts on the PPI question (directly above your post)?



  • So, you want to shut the CPU down, leaving only RTC and PPI running, and generate a wakeup event every 100ms, did I get that right?
    I didn't dig that far into the datasheet, and also I don't have any board for testing (yet).

    Also, I didn't check whether the debugger will survive a power down/up cycle.
    Does it?


  • Hero Member

    @Uhrheber said in nRF5 Bluetooth action!:

    So, you want to shut the CPU down, leaving only RTC and PPI running, and generate a wakeup event every 100ms, did I get that right?

    Yes. I hope to do more than only just that using the PPI while the CPU sleeps, but that does seem like the first step.


  • Hero Member

    @Uhrheber said in nRF5 Bluetooth action!:

    Also, I didn't check whether the debugger will survive a power down/up cycle.
    Does it?

    Don't know. I haven't started using the debugger yet.



  • In this example from Nordic, they're using the RTC's compare interrupt:
    http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52%2Fdita%2Fnrf52%2Fapp_example%2Fsolar_beacon%2Fintroduction.html

    Average current consumption is 19µA, including sensor reading, data transmission and Bluetooth advertizing.
    Not too bad, I'd say.


  • Hero Member

    @Uhrheber said in nRF5 Bluetooth action!:

    In this example from Nordic, they're using the RTC's compare interrupt:

    Yeah, but that part of it is running on the MCU, not the PPI.

    void RTC0_IRQHandler(void)
    {
        NRF_RTC0->EVTENCLR = (RTC_EVTENCLR_COMPARE0_Enabled << RTC_EVTENCLR_COMPARE0_Pos);
        NRF_RTC0->INTENCLR = (RTC_INTENCLR_COMPARE0_Enabled << RTC_INTENCLR_COMPARE0_Pos);
        NRF_RTC0->EVENTS_COMPARE[0] = 0;
        
        m_rtc_isr_called = true;    
    }
    

  • Hero Member

    Anyhow, I don't see a way to do an RFM69 style "listen mode" using just the PPI on the nRF52832. I think this may be a dead end.


  • Hero Member

    Looks as though there is EVTEN, which on the RTC needs to be enabled to get the PPI to work. Shown in Figure 46.


  • Hero Member

    Bingo! Added this, and it now works:

      NRF_RTC0->EVTENSET=1;  //enable routing of RTC events to PPI.
    

    🙂


  • Hero Member

    More good news. As far as the PPI is concerned, an event such as OVRFLW is still just as active as if it had been cleared, even if it hasn't. Here's the proof:

      NRF_RTC0->TASKS_TRIGOVRFLW=1;
    
      NRF_PPI->CH[0].EEP = (uint32_t)&NRF_RTC0->EVENTS_OVRFLW;  //when RTC overflow occurs.
      NRF_PPI->CH[0].TEP = (uint32_t)&NRF_RTC0->TASKS_TRIGOVRFLW;  //set COUNTER to be near another overflow.
      NRF_PPI->CHENSET=1; //enable Channel 0.
      NRF_RTC0->EVTENSET=B10;  //enable routing of RTC OVRFLW events to PPI.
    

    functions as follows:
    https://pastebin.com/Z09e7tMK


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    Anyhow, I don't see a way to do an RFM69 style "listen mode" using just the PPI on the nRF52832. I think this may be a dead end.

    It looks like you are implementing a new radio protocol and you are coming forward.

    What do you think about forking the MY_RADIO_NRF5_ESB into a new one? The nRF5 code is designed to implement additional protocols for nRF5.

    If you remove the address reverse code, there are no OTA conflicts with the ESB protocol. The address width can be enhanced by 2 bits to allow better AES encryption and lager packages.


  • Hero Member

    @d00616 said in nRF5 Bluetooth action!:

    It looks like you are implementing a new radio protocol and you are coming forward.

    Yes, I'm presently focused on trying to reduce the amount of energy consumed by probably the hardest case of all: a battery/solar/supercap receiver that needs to be both highly responsive (within 100ms) and listening 24/7 without running out of juice. Of course, one can always throw bigger batteries or bigger solar panels at the problem, but I'm first trying to be as ultra efficient as possible so that won't be necessary. The benefit will be smaller size, not to mention lower cost.

    I am posting my findings as I go because there is precious little in the way of working examples, so I may yet still be of help to others in that way. From the view count, it does seem that people are reading this thread, even if not many are posting.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    I am posting my findings as I go because there is precious little in the way of working examples, so I may yet still be of help to others in that way. From the view count, it does seem that people are reading this thread, even if not many are posting.

    btw. Thank you for sharing you knowledge here. In my option this is very helpful for me.


  • Hero Member

    @d00616

    I think you'll find this interesting:

      NRF_RADIO->TASKS_DISABLE=1;  //sleep the radio
      while (NRF_RADIO->STATE) {}; //wait until radio is DISABLED (i.e. STATE=0);
    
      NRF_RTC0->TASKS_TRIGOVRFLW=1;  //set COUNTER to trigger an overflow after 16 TICKS.
    
      NRF_PPI->CH[0].EEP = (uint32_t)&NRF_RTC0->EVENTS_OVRFLW;  //when RTC overflow occurs.
      NRF_PPI->CH[0].TEP = (uint32_t)&NRF_RTC0->TASKS_TRIGOVRFLW;  //set COUNTER to be near another overflow.
      NRF_PPI->FORK[0].TEP = (uint32_t)&NRF_RADIO->TASKS_RXEN;  //turn on the radio receiver
      NRF_RTC0->EVTENSET=B10;  //enable routing of RTC OVRFLW events to PPI.
    
      //When Radio state TXIDLE is reached, perform an RSSI sample.  There is no shortcut for this, so we must use PPI.
      NRF_PPI->CH[1].EEP = (uint32_t)&NRF_RADIO->EVENTS_READY;  //After event READY, radio shall be in state TXIDLE.
      NRF_PPI->CH[1].TEP = (uint32_t)&NRF_RADIO->TASKS_RSSISTART; //Take the RSSI sample
    
      NRF_PPI->CH[2].EEP = (uint32_t)&NRF_RADIO->EVENTS_RSSIEND;  //After event RSSIEND, RSSI measurement is finished and radio will be in state TXIDLE.
      NRF_PPI->CH[2].TEP = (uint32_t)&NRF_RADIO->TASKS_DISABLE; //Sleep the radio
      NRF_PPI->CHENSET=B111; //enable Channel 2, Channel 1 and Channel 0.
      sleep(1000000000);  //sleep a million seconds so as not to interfere with current measurements.
    

    It sleeps the MCU, and using just PPI, it wakes up the radio every 16 TICKS (each tick is 100ms) and measures the RSSI. Then it puts the radio back to sleep.

    So, looking at the current consumption from a macro viewpoint, it's this:
    0_1505333124723_NewFile2.jpg

    The taller peaks are when the RSSI measurements happen. Zooming in on one of the RSSI measurements, the current consumption is this:

    0_1505333166548_NewFile1.jpg

    As you can see, very little, and only for a very short time!


  • Hero Member

    So all I need now is a way for the PPI to compare the RSSI measurement it obtained above with a threshold benchmark to decide whether or not to wake the MCU, which can take it from there. From that point onward, the regular ESB code could be used. 🙂


  • Hero Member

    Nordic could have taken this a lot farther if they had included some comparison tasks, so that the PPI could make decisions about what to do next. However, I don't see that there are any that can be used for comparing an RSSI measurement against a benchmark. Too bad. 😞



  • Great that it works.

    But I'm not so convinced about the usefulness of this method, anyways.
    I know that a lot of receivers use simple RSSI measurement to implement a low power listening mode, but when you are in a noisy environment, the system will wake up quite often, draining the battery fast. And unless you live in a very remote area, 2.4 GHz IS a noisy environment.


  • Hero Member

    @Uhrheber said in nRF5 Bluetooth action!:

    Great that it works.

    But I'm not so convinced about the usefulness of this method, anyways.
    I know that a lot of receivers use simple RSSI measurement to implement a low power listening mode, but when you are in a noisy environment, the system will wake up quite often, draining the battery fast. And unless you live in a very remote area, 2.4 GHz IS a noisy environment.

    And your better alternative is....?


  • Hardware Contributor

    @NeverDie said in nRF5 Bluetooth action!:

    From the view count, it does seem that people are reading this thread, even if not many are posting.

    I'm following your work with interest of course 😉 On my side i'm pretty busy on other stuff (rpi and my HA) so i'm missing time for try..I'll be back soon on this!

    @NeverDie said in nRF5 Bluetooth action!:

    t what to do next. However, I don't see

    I thought too, about implementing this kind of listenmode for rfm69 in my HA. What i don't like so much, is I think i would need a dedicated node for the scheduling and it complicates a bit thing. I'm not fond of using gw resources for the wakeup broadcast.
    I think, maybe I'm wrong, that, ideally, the best would be "time slots" so everything would be in sync, no flooding broadcast, lost msg, collisions etc.. but that implies some work regarding the lib, and some hw issues (with simple 8bits without precise rtc).

    Keep the good work!



  • @NeverDie None, unfortunately. The manufacturer would have to take care of that, by implementing a low power mode in the receiver (maybe with reduced sensitivity), and an additional low power wakeup pattern detector.
    There are transceiver that can do that, but the nRF52 can't.

    Some of the simple 433MHz OOK receivers have a low current consumption, but they're pretty insensitive, high bandwidth and low speed, so of not much use except switching some battery powered lamp, or such.

    Some time ago I searched for a transceiver with low current receive mode, to use it in a battery powered node, that could be woken up by rf, but found nothing.
    All of the standard data transceivers are pretty power hungry.





  • @Toyman Indeed:

    Nonetheless, larger AA or AAA type
    batteries are still required to reliably achieve operation times
    of a year or longer with high advertising rates.

    As I thought.
    And for more advanced modulations, like LoRa, the power consumption is even higher.


  • Hero Member

    @Uhrheber said in nRF5 Bluetooth action!:

    Some time ago I searched for a transceiver with low current receive mode, to use it in a battery powered node, that could be woken up by rf, but found nothing.

    TI and Silicon Labs have both had chips with "wake on radio". e.g. http://www.ti.com/lit/an/swra126b/swra126b.pdf

    The Rx current consumption of the nRF52832 seems pretty good, especially with DCDC regulator enabled. Seems to me that the RSSI detection implemented in PPI is a big improvement, even in noisy environments for the following reasons: the RSSI measurement takes only 0.25us, according to the DS. That's very little overhead. If the Radio gets switched on due to a false positive on the RSSI, well, it would have had to be switched on anyway even without the RSSI. I don't see the downside to this. The more noisy the environment, the less effective the technique is, but I don't see that you'd ever really be worse off for using it.


  • Hero Member

    @d00616
    If I'm using

    sleep(1000000000);
    

    to sleep the CPU while keeping the PPI active, is there a way for the PPI to subsequently wake the CPU so that the CPU can resume where it left off? I'm not seeing any TASKS which look suitable for doing that. Or do I need an altogether different configuration for sleeping the CPU?

    Back on August 5, @RMTUCKER had suggested using:

    sleep(digitalPinToInterrupt(10), FALLING,0);
    

    If I were to go that route, I could probably have the PPI toggle PIN 10 to do a wake-up, but I found that, for whatever reason, that method of sleeping had a much higher current draw.

    [Edit: scratch that. I just tried "sleep(digitalPinToInterrupt(10), FALLING,0);", and it appears to turn-off PPI. Oddly enough, it appears to leave the RTC running, which is actually just fine by me. However, I need the PPI running too. ]



  • @Uhrheber not really. If you read carefully, they claim almost 1year battery life with 1hz (once per sec) advertising.
    Typical MYS node sends data once per minute? So, actually, 2-3 years are easily achievable.


  • Hero Member

    It turns out the cost in current consumption of waking the MCU merely to check the RSSISAMPLE result is relatively high:
    0_1505404541889_NewFile6.jpg

    The first hump is the current drawn by the PPI and RSSI sample. The second hump is the current drawn by MCU.

    Measurement Scale: 1mv=1ma.

    Anyhow, the RSSISAMPLE measurement, as reported by the MCU, is abnormally high. It may be that I need to put the radio into RX state, instead of just RXIDLE, before taking the RSSI measurement.


Log in to reply
 

Suggested Topics

  • 8
  • 90
  • 3
  • 1
  • 1
  • 5

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts