An intriguing mix of micros

I’m working with a commercial product at the moment that consists of multiple wireless devices connecting to one another. Most systems I have worked on stick to a single microcontroller or RF frontend, or at least a single family of microcontroller and RF frontend.

Not this one.

Node 1 – A Texas Instruments MSP430F2132 as the microcontroller and an Analog Devices ADF7021 RF front end.

Node 2 – A Texas Instruments MSP430F1111A as the microcontroller and an Infineon TDK 5100 RF front end.

Node 3 – A Renesas H8/3008 as the microprocessor (yes, no integrated flash or RAM) and an Atmel AT86RF211SW.

All components were purchased at the same time, in fact, as part of a kit. They are all manufactured by the same company.

It amazes me that they could even work together. I just can’t understand why someone would architect a system like this. Any ideas?

Arduino misconceptions 3: it isn’t low power enough to be run from battery

People build their projects, then want to battery power them. Their solution is to use a large battery (e.g. a 12V lead acid), connected to the Arduino external power input. The battery lasts mere days, and they become frustrated and move on to processors perceived as low power, like the MSP430 and ARM Cortex M0 series.

What if I said you could run a ATmega328P, RF transceiver and sensors from AA batteries for months at a time? A lot of people just won’t believe it, thinking the ATmega328P is a dated, power hungry chip that needs an ugly wall wart for power.

So why are people struggling with battery power?

1. The standard Arduino board accepts an external power input of between 7-12V, which then passes through a delightfully named NCP1117ST50T3G low dropout linear regulator to get it down to 5V for the rest of the board. If you are using a 12V battery via this regulator, and drawing a measly 50mA, you end up burning 0.35W of power in the regulator and the Arduino only using 0.25W! That linear regulator is an evil thing.

2. Most Arduino boards run at 5V. The ATmega328P runs fine at 3.3V and even down to 1.8V. At 3.3V, the chip uses ~40% of the power, and at 1.8V, it uses ~10%. Massive gains! 1.8V can make interfacing to other systems a bit awkward, but 3.3V is generally fine.

3. Most Arduino boards run at 16MHz by default, but a lot of the time you don’t need to run that quickly. By dropping to use the 1MHz internal oscillator, you reduce the power consumption 8 times. If you go further, you can use 128kHz oscillator and the power consumption drops 70 times!

4. A lot of Arduino code uses delays() and never sleeps. The ATmega328P has a sleep mode which can easily use less than 10µA – if you use an external 32.768kHz watch crystal, you can get this down to fractions of a µA. Learn about these and use them.

Where do you find out all of this info? It’s at the end of the ATmega328P datasheet.

You can workaround all of these – I thoroughly recommend reading JC Wippler’s posts on Jeelabs in his quest to reduce power consumption on Arduino-like board.

Arduino misconceptions 2: Arduino is “slow”

For the second post about Arduino misconceptions, there is the a common idea circulating that the Arduino is “slow”. Most frequently I hear this in the context of reacting to user input, dealing with multiple sensors, using LED or LCD displays, or acting as part of a control loop. People advise faster microcontrollers such as the ARM Cortex series.

Let’s look at the fundamentals here:

  • The ATmega328P on the Arduino boards runs at 16MHz – that’s 16 million cycles per second.
  • The ATmega328P instructions take between 1 and 3 clock cycles (with the exception of the subroutine related instructions which take 4 or 5). The average is somewhere between 1 and 2 for most compiled C code.
  • We can then infer than the ATmega328P can carry out at least 8 million instructions per second!
  • It’s hard to directly translate these instructions to lines of C code. What looks simple in C can take tens of instructions, and what looks complex can be done in one. 
  • We can still say that the ATmega328P is going to tear through your code at a rate of knots, far faster than most people imagine.

So why do people say it is slow? I’d say the following reasons:

  • It is 16MHz, and most people’s PCs and phones operate in the 1GHz range, so it doesn’t sound like much. The ATmega328P is performing entirely different tasks though.
  • It is 8bit, and most modern processors are 32 or 64 bit. This doesn’t have many implications for projects using the Arduino though (but will be related to my next misconception!)
  • The frequent use of delay() in Arduino code. Delay() causes the processor to just churn – it can’t do anything else whilst it is running. So if you have 4 buttons which are meant to turn on 4 respective LEDs for 2s, the system becomes unresponsive if you use delay() for the 2s.
  • The frequent use of Serial.print() in most code for debugging or status reports. Arduino pre-1.0 uses to block when sending data out using the serial port. That meant an 80 character string output at 9600bps (the default, for some reason), would take over 80ms, during which time the processor could do nothing else! Even now that it uses interrupts, strings still take a long time to output.
  • Slow digitalRead and digitalWrite – these two functions are orders of magnitude (~60 cycles) slower than direct port access (~1 cycle!). Heavy I/O can look slow or latent as a result.
  • Bad code – the Arduino is exceptionally easy to use without understanding any of the underlying concepts of microcontrollers. As a result, code is sometimes simply bad.

A faster microncontroller can mask some of these issues, but without understanding some key concepts (interrupt handling and well structured state machines), you are going to be up against the same wall again in no time.

That’s not to say that faster microcontrollers aren’t needed sometimes – anything with heavy number crunching needs something more – but for a lot of situations an Arduino is more than capable in the hands of a good developer.

Arduino misconceptions 1: need to use external pull-up resistors

One of the first things you need to learn when interfacing switches to microcontrollers is the use of pull-up resistors. These ensure that the inputs to the microcontroller settle in either logic high or low when the switch is not made. They are fundamental, so fundamental that Atmel decided to build-in weak pull-up resistors into the ATmega328P used in the Arduino!

Simple pull-up resistor

Yet a lot of tutorials show external pull-up resistors being used with switches. There’s not really a problem with this – just that it is not required 99% of the time. It might be good to teach the concept, but I regularly see posts on forums where people have connected pull-ups incorrectly, causing them problems. I’ve even seen people confident enough to design a PCB, but have multiple external pull-ups for interfacing to a keypad!

InternalPullUp

So how do you use the internal pull-ups? It is very simple – when the data direction register is set to input, write a high to the output port:

pinMode(pin, INPUT);
digitalWrite(pin, HIGH);

Or, if you have moved away from the Arduino libraries:

DDRx &= ~(1 << pin);
PORTx |= (1 << pin);

What’s the other 1% where these internal pull-ups won’t do? There are two situations:

  1. The switch requires a pull-down rather than pull-up – though this can generally be avoided
  2. You need a strong rather than weak pull-up – sometimes devices draw power from the pull-up, and the 20kOhm internal pull-up is too large.

So, simplify  your circuits and remember this feature!

Strangest boardroom in London?

Every few months or so, I trawl several film location databases to find new places to look round. 95% of the sites are of no interest, and only a few of the remaining 5% can easily be found.

This place, off the Itasca location database, really got my interest with the strange turret like structure – it really looks like prison watchtower or similar.

Itasca_30001_001

So, it looks like a board room in there. Where’s the stairs though? What does that sign say “SLIDE TABLE TO OPEN FIRE EXIT”?

Itasca_30001_009

Oh right, so you actually slide the table apart to get to the stairs…

Itasca_30001_010

And down we go…

Itasca_30001_011

Imagine needing to go for a wee during a meeting.

For those interested, this is the old Fulton umbrella factory, just in the shadow of the Canary Wharf estate. I think it was vacated sometime last year.

Nadine Dorries bends the truth to support her agenda on social media

Nadine Dorries has passed comment on social media and the recent civil unrest. It’s an interesting topic, and one that could be debated for many hours. However, keeping to form, she bases her arguments on untruths and presents opinion as fact.

Her statement:

During 7/7, mobile networks were instantly closed down.

Is false.

The 7 July Review Committee in their report stated:

We subsequently found out that in fact ACCOLC had been activated, by the City of London Police, on the O2 network in a 1km area around Aldgate Station

ACCOLC, according to wikipedia is:

ACCOLC (Access Overload Control) is a procedure in the United Kingdom for restricting mobile telephone usage in the event of emergencies. It is similar to the GTPS (Government Telephone Preference Scheme) for landlines.

This scheme allows the mobile telephone networks to restrict access in a specific area to registered numbers only and is normally invoked by the Police Incident Commander (although it can be invoked by the Cabinet Office). The emergency services are responsible for registering their key numbers in advance.

Also in that report:

The O2 network was closed … at about noon, and remained closed until 4:45pm

That is neither instant (the first bomb was at approx 0850) or across more than one network, or in anything but a very small area.

Also, evidence given at the inquest (yes, this is protectively marked restricted and is on a gov.uk website):

Accolc

Mid-air heist

Browsing the Daily Mail website to find amusing stories about how anyone brown is out to ruin society, I came across an interesting story about a mid-air heist. A passenger on a small plane removed panels from the toilet, climbed into the hold, and stole a large sum of cash in transit. Very Hollywood.

It seems that the plane was a small ATR-42 turboprop plane – which normally only has one toilet. It must have been quite hard for him to monopolise it for the entire journey. I also wonder how he got the tools onboard to enable him to get into the hold – maybe the small airport security isn’t too rigourous? Also, where did he conceal such a large amount of cash when leaving the plane?

I like the idea of stealing high value items from the hold of a passenger plane. I can see many advantages – the cover of engine noise, the delay in being found out, the assumption that once the cargo is on the plane, it is safe. But on how many planes is this even possible? Outside of the Hollywood portrayal of cargo spaces (Air Force 1, Flightplan etc.), how many can be easily accessed from the passenger space?

On a side note, I have remembered how much I love cutaway diagrams:

TV Licensing, bit of a security lapse

I just had the TV Licensing man knock on the door. Their database has been looking at us, because we don’t have a license at this address. We do, however, have a license at our old address (despite which, the letters keep on arriving).

I inspected his ID. Their IDs are crap, and would be almost trivial to forge.

So I told him our old address and postcode. At this point, no names had been mentioned.

He then says, OK, I will transfer it across to the new address. He then turns the palmtop device round to me to show the transfer. I can see our details on the screen, so he clearly has access to the database and is probably for real.

But I have now transferred the license without knowing anything but an address and postcode. Are there going to be any further steps to authorise this process? Probably not.

So, if they knock on your door and you are sans-license, just make up an address and hope for the best…