Computing stuff tied to the physical world

Exploring LPC824 peripherals

When exploring the LPC824, there’s no point trying out the basic blinking and serial I/O examples, as we did with the LPC810 and LPC812 – the LPC824 is (mostly) compatible with those two chips and will behave in the same way. What about the new hardware?

Here is a demo app which reads out the ADC and reports its values on the serial port:

#include "sys.h"

int main () {
  tick.init(1000);
  serial.init(115200);
  analog.init();

  printf("\n[analog]\n");

  while (true) {
    int adc = analog.measure(10); // adc10 is 13p3 on LPC824
    printf("%d\n", adc);
    tick.delay(500);
  }
}

The actual code is wrapped into a class in sys.h. It sets up some registers, goes through the mandatory “ADC calibration procedure” when the ADC is turned on – then measure() does the actual analog-to-digital conversion and returns the result, in the range 0 .. 4095.

Here is a build and sample run:

$ make
arm-none-eabi-g++ [...] -c -o build/obj/main.o main.cpp
arm-none-eabi-g++ [...] -c -o [...] ../../../lib/arch-lpc8xx/sys.cpp
arm-none-eabi-gcc -o build/firmware.elf [...]
   text    data     bss     dec     hex filename
   1652       4       8    1664     680 build/firmware.elf
uploader -s /dev/tty.usbserial-* build/firmware.bin
found: 8242 - LPC824: 32 KB flash, 8 KB RAM, TSSOP20
hwuid: 07200207679C61AE4377A053850200F5
flash: 0680 done, 1656 bytes
entering terminal mode, press <ESC> to quit:

[analog]
1495
1493
1493
1493
1492

This corresponds to 1493 / 4095 * 3300 = 1203 mV.

Pretty easy, eh? Especially with the wrapped “Analog” class.

For this measurement, pin 3 on the chip and breakout board, aka GPIO 13, aka analog 10, was attached to a depleted AAA battery, as follows:

DSC 5116

Using an accurate meter, we get:

2015 06 09 11 21 18  1

That’s not exactly the same. There seems to be a small offset in this setup: when shorted to ground, the reading is 43. If we subtract that, we get: (1493-43) / 4095 * 3300 = 1168 mV.

[Back to article index]