Posts

Optimizing your nRF24 range with a simple test rig

Image
I'm working on a commercial project and I need a low power wireless interface to send data reliably in a crowded indoor environment. There are many standards and protocols to choose from, but the Nordic Semiconductor nRF24 and its 'shockburst' small packet protocol seemed like the best fit for the job. Three advantages of the nRF24 are its incredibly simple interface, that it uses very little power when idle and that it operates in the unlicensed spectrum near 2.4Ghz. Bluetooth low energy (BLE) could potentially do the same job, but the available devices and RF protocol are a bit more complicated and more expensive than this project requires. I started by buying some inexpensive nRF24L01+ development boards from Amazon that cost around $1 each. I wired them up to some ATmega328's for testing and tried the simple "Hello World" chat app; they worked as expected. Next, I added them to my product prototype and that's where the trouble began. My project h...

How low can it go? (optimizing for power)

Image
Background The Arduino (and later the Raspberry Pi) have created a huge marketplace of kits, modules and discrete parts. Vendors all over the world offer a large selection of sensors, displays, motor controllers and micro controllers for every need. This has opened up huge opportunities for individual makers to experiment and learn. Devices like these used to be very difficult to source and use in single piece quantities. If you're on a tight budget and have a lot of patience, vendors in China are willing to sell low quantities of parts directly to you at prices much lower than local vendors can offer. Over the last few years, one of my personal goals has been to familiarize myself with "The IoT". This has mostly involved buying parts, reading the datasheet, writing software to drive it and then sharing the results on GitHub . The only way I've been able to afford to acquire and test all of these parts is by buying them from China. My mailbox receives a steady stream...

My adventures in writing an OTA bootloader for the ATmega128RFA1

Image
This adventure begins with the acquisition of a low priced gadget from the secondhand market. The SMART Response XE was designed to be a classroom communicator that allowed students to vote and submit answers in real time to the teacher. Support ended a few years ago and what once cost $100-200 each are now available on eBay for $10 or less. The hardware is just asking to be hacked. Inside is: 60-key keyboard 384x136x2-bpp monochrome LCD ATmega128RFA1 MCU (128K Flash, 4K EEPROM, 16K RAM, integrated 802.15.4 MAC) 1Mb (128KB) SPI flash 4xAAA battery power supply This particular MCU is part of the AVR family of products and that makes it easy to write code using the Arduino IDE. I initially spotted this on Hackaday because a group of people in the Arduboy community decided that it could be fun to run their games on it. My interest is more in the learning side. For me, this device was a good way to learn about: Serial (SPI) FLASH memory AVR Bootloaders 802.15.4 wireless...

Software Optimization Specialist - cos'è?

Recently I've been talking with potential clients and have needed to explain in detail what it is that I do. My title and resume don't do a great job of conveying that information, so I thought it would be useful to collect my ideas here. Lately, the majority of my time is spent making other people's code run faster, but I also work with bits, bytes, pixels and embedded devices. The following are anecdotes from working with various clients. For security reasons, specific project details may be omitted. Back End / Server A while ago, I cold-called a company with a proposition. They run a "software as a service" that processes tons of images for clients using their own server machines. I asked if they were using open source software to run their business and if they were satisfied with the performance. It turns out that I caught them at a good time because they were having performance problems and were about to purchase more servers to handle their growing list...

With software, there's always a better way to do it

Image
Warning I will be naming and shaming a specific tech company, but most companies are guilty of the same thing. Scenario You define a standard used in the software industry and provide the reference code to make use of it. The standard is complex enough that developers don't want to re-invent the wheel by writing their own implementations. The reference code is incorporated into commercial products and used by millions (billions?) of people around the world. There is a slight problem - the reference code isn't properly optimized, so all of your users are wasting additional time+energy working with the data you've standardized. The Specifics The subject of this blog post is the OpenEXR image file standard created by Industrial Light & Magic . I'm not directly involved in working with these images, but my client is and I saw an opportunity to improve their productivity by optimizing access to them. There's nothing particularly wrong with the reference impl...

Mind the cache (reference to "mind the gap" in the UK tube)

Memory read and write performance may be identical as far as the physical memory is concerned, but CPU manufacturers have designed unique hardware to manage the very different situations of reading from and writing to memory (from a program's perspective). When reading from memory, your program normally needs the data as fast as possible and often will halt the CPU execution until the result of the read is completed. The cache logic is designed to improve the overall speed of memory by optimizing access to the current data set (a subset of the total memory). Intel (and recently ARM) have designed smart cache logic which can predict read patterns and prefetch memory into the cache in anticipation of it being needed. When writing to memory, there normally isn't any hurry to complete the write, so the write buffer can collect a few write requests without stalling the CPU. The data will work its way through the write buffer and cache logic and only stall the CPU when a write o...

SIMD

Image
The dead horse that I like to keep beating - everyone should use SIMD (single-instruction-multiple data) in their software wherever possible. It's basically free performance, so why not use it? Every PC (x86 machine) sold in the last 10 years has it and so do mobile/embedded machines for at least the last 5 years. What is SIMD? It's a set of instructions which usually make use of extra-wide registers (typically 128-bits) and can do multiple operations in parallel. A regular CPU instruction can perform a single math operation (e.g. integer addition), while a SIMD instruction can do 2, 4, 8, or 16 separate additions in parallel in the same amount of time. It means your program can do its work many times faster. Many programmers are already aware of the existence of SIMD, but may assume that by enabling the "auto-vectorization" option of their C compiler, their program will magically contain beautifully crafted SIMD code. You can already guess from my last sentence ...