Our challenge, as ever is wakeup.  Beaconing is something we don’t need to do all the time, but listening is.  Sniffing the ether occasionally is fine, but it requires the transmitter to beacon for longer.  I need a spreadsheet to get my head around this.

I am beginning to wonder if I have misunderstood the BLE documentation.  It looks like scanning may be expensive, compared with maintaining a bonded connection.

I don’t have any idea how much power either process takes yet.

There is a limit to how many connections the system can simultaneously maintain, so that’s could be a difficult issue.

You can use BLE driver (the Master Emulator only support 1) that runs on S130, now you can have 3 but later you can have up to 8 peripherals simultaneously when BLE driver use S130 v2.0.

This is a very useful article describing all the little things you can do to minimize power

How to minimize current consumption for BLE application on nRF51822

Current measurement guide: Measuring current with nRF52832 Engineering B and S132 v2.0.0-7.alpha

I’m beginning to think that we need a lower-freqency radio to get the same range with a lower power budget.

The Friis equation demonstrates the superior propagation characteristics of a sub-GHz radio, showing that path loss at 2.4GHz is 8.5dB higher than at 900MHz. This translates into 2.67 time longer range for a 900MHz radio, since range approximately doubles with every 6dB increase in power. To match the range of a 900MHz radio, a 2.4GHz solution would need greater than 8.5dB additional power. 

The MicroSemi ZL70250 looks more interesting.

To be an effective wake-up radio we need to write the MAC layer software so that it simply toggles a bit whenever it receives a packet containing it’s address.  That could be a very simply bit of software indeed.  If it could duty-cycle listening then it’s budget could be arbitrarily low, at the expense of a higher beacon budget.

Connection-less scanning and advertising started working today.

Two ts06.2s are chatting.  Each advertises its presence for 2 seconds and waits 5 seconds before doing it again.  In a parallel thread, each is scanning for advertisements for 5 seconds every 10 seconds.  Amazingly they are managing to find each other.

The next job is to get those periods of activity to be shorter and use less power, and then it is on to DecaWave-land.

I have a bunch of the BLE stuff working.  I can simultaneously advertise, and listen for advertisements, and receive connections from a cell phone to upload range log reports and diagnostics, and continuously output diagnostics to the USB.
I tested my latest iteration doing simultaneous BLE advertise and discovery.  It ran for a day doing  30521 iterations before dying from lack of memory.  Clearly I have a space leak, or some unusual storm of events occasionally overwhelms the buffer pool.  One of the lovely bugs that takes a day to reproduce.
I'm planning to get the last bit of the BLE infrastructure working this week, and then I'm going to try and integrate the UWB ranging.  If I can shoehorn all this in without more RAM squeezing I shall be pleased, and mildly surprised.
We are getting closer to something primitively testable, and then the power monitoring can begin to start generating a power model, and figuring out the daily budget.
//Mik

Should we get a kit?  

Pledge €290 or more

We could add one of these chips to our platform, and stop worrying about BLE so much.  SemTech are offering free samples.

Fixed sensors can realistically be powered forever with just small solar panel.

Notice that the lowest RX current is still 10mA.   That MicroSemi chip could listen at 1.9mA, but the range was probably crap, and it was probably more sensitive to noise.  The nRF52 listens at 5.5 mA peak current in RX and TX (0 dBm) (was 9.7 Rx/8 Tx)

It also has the advantage of 512 kB flash/64 kB RAM, and we get a BLE radio for free-ish.

I merged a bunch of threads, and saved a bunch of stack space as a result.  There are only three threads now.  I wonder if this will be an issue later.

I changed the buffer management system to do more sharing.  I still have some more work to do on that.

The good news is that I now have a “whopping” 5.7K of RAM spare into which I have to shoehorn the DW data.

Good news, I have plenty of flash memory still available.

Bad news, it begins to look like RAM could be a challenge.

My proposed architecture (see below) uses 10 threads (1 main thread, and 9 others).  This architecture is clean and easy to understand.  At present I have 5 threads part implemented. Each thread demands a different amount of stack, which obviously has to be in RAM.   The amount depends on how deeply the procedure calls are nested.  I have tuned the current stack definitions down to the bare minimum required for them to run without overflowing.
By default, each stack requires 256 x 32-bit words – i.e. 1Kb.  I have tuned two of the stacks down to 768 bytes.  Assuming that I need another 6 threads then thats another 6K.   The current splash screen shows that there is only 1.3K left!
—- Touchstone Labs —-
RAM:     32K  (Avail: 22K / bss free: 1.3K)
FLASH:  256K  (Used:      119K)
SW:     BLE_RTX_UART(Feb 12 2016 01:40:04)
HW:     ts06.3
RTOS:   RTX V4.74 + SoftMach: s130
API:    DW1000 Device Driver Version 03.00.01
SPI0    0: ss:7, mo:6, mi:5, sck:4, Hz:125K, BLOCKING
BUTTONS 0:16 1:17
UART:   tx:14, rx:15, cts:255, rtx:255, hwfc:false
        SPLR Thread: 0x20005c90
DECA:   RSTN 25, EXTON 29, WAKEUP 28, IRQ 3
AntDel  TX: 16453 RX: 16453
I2C     SCL 9, SDA 8
DC2DC   SHDNn 20, PWRON 19, GG_ALARM 18
BARO    INT 13
IMU     INT 12
uSD     CDn 11, CS 10
        BLE Thread: 0x20005cc4 — handles all BLE events from soft-machine
        ADV Thread: 0x20005cf8 — kicks off periodic advertizing cycle
        CLI Thread: 0x20005d2c — responds to range commands sent over BLE
The DW libraries are not being used yet.  They actually demand a lot of I/O packet space themselves. 1-2K.

So what can be done?

Runtime libraries

A lot of the overhead goes in C runtime libraries to do text formatting and so forth.  The RTX documentation recommends 1Kb/thread, which I have nevertheless trimmed down to 768 bytes.  If I dispensed with all debug messages I could save some stack space.  That would make debugging more of a pain though.  

Combine threads

Combining threads into one unified handler is the easiest way to save space, but it also makes the architecture a lot less elegant, harder to understand, and debug  One approach is to combine all the non-BLE threads into one large hairy thread that can process all types of event.   Unfortunately the BLE events have to be handled by a high priority thread in order to meet the response requirements. So BLE handling needs it’s own thread 
Combining threads would require that there is a common message format for passing messages from each kind of interrupt handler to the unified event handler routine that does the actual processing work.  That in turn means that every message has to carry the overhead of the largest message – but not sure this is a big issue.

Make the main loop more useful

The diagnostic (TS UART) thread could perhaps be moved into the main idle loop, and maybe persuaded to run at a lower priority. 

Don’t write data to flash

My plan was to write all activity data to flash memory (or flash card) so that when the device moves back into range of a cloud connection it can upload all the activity data it has collected while disconnected.  Writing and reading flash is slow, and power intensive, so I put it in a separate thread. To be able to write the data without using flash it has to be stored in RAM.  There is clearly a trade off between stack space for a separate flash-writing thread, and a simpler scheme that just uses RAM. I don’t know how much RAM I need in practice.  The theoretical answer is “lots” because you don’t know how long you might be disconnected.  A flash-writing thread would require 1KB, but just using a 1KB RAM buffer might hold enough activity data for a first iteration.

What’s the best we could expect?

1 Combo main thread: RTX Idle is combined with TS_UART which saves one thread. 
0 Using RAM to store events, instead of flash updater
1 High priority BLE “interrupt” handler
1 Combo thread for BLE discovery/wakeup; DW activities; IMU; Flash updater
1 Timer thread
That gets us down from 10 threads to 4 threads.
So there is the possibility to save ~6K, but probably burn some in new IPC buffers
So maybe I can scavange 7KB is I sweat the details, and that might do the trick.  On the other hand the nRF52 processor has more RAM, but I’d have to port the code before I could continue.  It would be good to get some sort of results before rolling new hardware.
Now that I am more familiar with the vagaries of the major components I have the architecture planned out, but who knows if I can make it work.  I can already see that it is going to take quite a bit of experimentation with the many parameters to get the power budget down.
It’s getting quite complicated already as you can see from my back-of-the-envelope sketch.  Clearly this isn’t going to come together in a hurry.  Perhaps the most useful thing is that I have figured out what all the LEDs are for 😀
This is bugging me.  Early start for me today… not sure if I have solved the memory issues yet, but I wrote code to check the actual memory size of the machine, while also running RTX and the BLE s130 soft-machine.  

Here’s my startup splash screen, and it looks like the ts06.3 does have the bigger memory, which is at least one explanation of why the code was crashing on the TS06.2.  Doh!! I don’t really have any application code in this config – a null application I guess.
According to the loader, my null-app and all the libraries are consuming 77K of flash, and 7.8K of flash, including all the BLE and RTX buffers etc.  So it seems like I have some more rope left for a modest app.   

My next milestone is to see if I can get ranging information printed on my Android over BLE, and to check that you can do the same thing on the equivalent iPhone app.