Monday, 17 October 2016

Pin Change Interrupts

I'd totally forgotten at the AtMega328 (and the AtMega in general) have Pin Change interrupts on all GPIO pins. You have to do some work in the interrupt handler to work out which pins changed state, but it does mean than handling four quadrature inputs on an Arduino might not be impossible.

Which is almost a shame, as I'm really getting into embedded Rust and my Launchpad project only works on a Stellaris Launchpad, not an Arduino.

Sunday, 2 October 2016

Motor Driver

As stocks seem to be dwindling, I decided to pick up the official Dagu Rover 5 controller board while I still could. This uses SP8M3 FETs to form the H-bridge, which should only drop about 0.3V, as compared to probably about 2V from the crude L298 drivers I used last time. The board also mixes the two quadrature encoder outputs into a single waveform using a XOR gate, which reduces the number of pins I need. There's also a nifty current sensor, just so I can keep an eye on the current consumption and shutdown in case something bad happens.

The only downside is that it's all 5V I/O.

Saturday, 1 October 2016

Pi Wars 2017

So, somehow I've managed to bag a place in PiWars 2017 in the Intermediate category.

The planned upgrades over my 2014 entry, include:

1. Four wheel drive.
2. Better, more efficient H-bridges.
3. More capable motor controller.
4. Switch to Pi Zero for space / efficiency.

Key holdovers include:

1. PS3 pad control via Bluetooth. This works so much better than WiFi, especially in the crowded PiWars auditorium.
2. On board LCD for mode select. Much better than trying to hook up a laptop.
3. The Rover 5 chassis. While the motors aren't too powerful, and it weighs a ton (not literally), and the wheels have some slip, and while I did win an Ar2Pi2 at the last jam, the Rover 5 is just so torquey and the tracks are so good for the obstacle course.

Undecided so far:

1. 6xAA NiMH or LiPo?
2. Launchpad or Arduino Pro Micro or Leaf pad Mini clone?
3. Rust or re-use the existing C?
4. Full OS or fast boot a bitbake image?


Must not leave it until the last minute.

Must not leave it until the last minute.

Must not leave it until the last minute.

Saturday, 6 August 2016

Old friends

So, I was trying to find a microcontroller board with a ton of 5V I/Os and, as usual, finding nothing at a reasonable price. A Pi Zero is $5, so why is a dev board for an 16MHz 8-bit MCU $50? But then I realised, I don't necessarily need 5V I/O - I need 5V tolerant I/O.

I've spent quite some time (as you might know if you've seen other blog posts) working with the TI Stellaris Launchpad - now known as the Tiva-C Launchpad for reasons I never did understand. I thought I've had a look at the datasheet and low and behold - 5V tolerant I/O.

So, a plan is forming:
  • Create a base board for the Launchpad, like I did for the in-car dashboard
  • Drive the L298 inputs from a open-drain GPIO with a pull-up.
  • Read the quadrature encoder inputs directly (the GPIO will deal with it OK).
  • It can interrupt on any GPIO pin, so no problem there.
  • It's fast - A 67MHz Cortex-M4F won't have any problems running four seperate PID loops.
  • The Pi can connect via USB for both power, control (Serial) and flashing/debug.
  • I know I can get the programmer to work.
  • I know I can program it in Rust...

PiWars 2017...?

I may have accidentally submitted a PiWars 2017 application. Ooops.

Key upgrades for the old robot, I think would include:
  • Proper four wheel drive
  • Closed loop motor feedback
  • Ultrasonic ranging on the sides as well as the front
  • Light sensors in place of the camera for line following
I dusted off the 2014 entry myself and some friends built and the LCD and the PS3 interface still work well. But I'd previously stolen most of the motor driver circuitry, so that needs revisiting.

To make the sensors work, I need more interrupt pins than the two that I have available on the AtMega 328 I used last time. I really need two for each wheel speed sensor, plus one for each ultrasonic sensor. I'd use a Cortex M4 like the Stellaris Launchpad, but the wheel speed sensors of course output 5V, as are most ultrasonic sensors and the inputs on the L298 H-Bridges I use.

I feel a custom circuit board coming. Oh dear oh dear.

Sunday, 10 April 2016


A few weeks ago, some enforced time off gave me time to do some research into a topic that some of my colleagues have been getting quite excited about. Rust.

Rust is a new language from Mozilla. Unlike Java and C#, it compiles down to machine code. Unlike Swift and Go it doesn't require an OS - a subset of the standard library (known as core) can be used on any platform. Unlike C++, it's been designed with good ideas from the start, including strong borrow semantics and pattern matching, and unlike C it contains good ideas, period. No more writing your own linked-list implementation on every platform you develop for. It's the first language I've seen where there's no "I'll just have to do this bit in C". Pure Rust, even on a Cortex M4, is the promise. But is it the reality?

First impressions weren't good. Rust's stable/beta/nightly model means that you can experiment with new features considered unstable. Unfortunately these features can and do change, and many of them are required to do bare metal Rust. So github is littered with projects which probably used to work for some platform or another, but don't any more. is probably the biggest, but when I checked a change in compiler internals meant that their clever Rust compiler plugin for auto building platform setup code no longer compiled. It was too much to unpick, especially for a newbie. I saw some good projects for bare metal on x86, but I really wanted to use my M4F Stellaris  Launchpad.

Eventually I found which did at least compile out of the box on Rust 1.9 nightly. Some time later, I've got running on the Stellaris.

Top tip - don't leave unimplemented!() in your code as it calls panic!().

Top tip 2 - Don't forget to keep generating a bin from the ELF, otherwise you're running one version of the code while debugging the other, and that's just baffling.