Friday, April 29, 2011

Better output buffer for an R-2R ladder DAC

One day I needed a simple R-2R ladder DAC, and needed an output buffer for it, so I started to design one. Initially I was planning to use the LM358, but then I remembered seeing an op amp from TI that would be more suited for the job.

First off, I'd like to clear up two things for those that might wonder.

Why I need an output buffer? For example the R-2R ladder digital-to-analog converter circuit cannot drive anything by itself. You should be able to observe the waveform with an oscilloscope (typically 1 megaohm input impedance) but probably cannot even drive a sound card input (~10kohm) with only the ladder. You need a buffer amplifier that has a voltage gain of 1 and can drive a low input impedance. 

Why linearity is so important? So you get the value you wanted out from the circuit without any distortion.

The TLV2472 single-supply op amp makes a great buffer. Unlike with the LM358, the output is linear from 0 to VDD so you don't have to have an extra voltage supply for the op amp (with LM358 you need to keep the VDD about 1.5V higher than the maximum output voltage).

This figure is from TI's "Single-supply Op-Amp Design Techniques" application note. The noninverting amplifier with TLV2472 appears linear from 0V to the VDD (5V in this case).

The LM358 has been popular in these buffers because it is linear near the lower supply voltage (GND, 0V), but with TLV2472 you get the linearity also near VDD, like seen in the above picture.

The buffer circuit.

The buffer circuit is basically taken from the Texas Instruments application report "Single-Supply Op Amp Design Techniques". It's a non-inverting amplifier with a voltage gain of 1. If someone wonders, I created the schematic with the great free tool ExpressSCH, which is part of the free ExpressPCB PCB design software.

The TLV2472 (click for datasheet) can be used with a single supply voltage of 2.7 - 6.0 V. This makes it possible to use for example 3.3V, which is common in all the low-cost develpoment boards (Arduino, LPCXpresso, Launchpad, STM32VLDiscovery...)

Just keep in mind that the 3.3V from the digital device might be quite noisy for the op-amp, so some filtering might be necessary. Ideally the analog portion of your circuit would have it's own regulated and filtered supply, but for most hobby projects I believe the noisy digital 3.3V supply is more than enough.

Note that I haven't tested this circuit yet! I will post a "part 2" article when I get to build and test this. If you try this before that, or have something to say, please comment!

Monday, March 14, 2011

Overview of the LPCXpresso development platform

I got hold of the LPCXpresso development platform. This is a nice, thin 32-bit development platform with a built-in USB programmer for only 20€.

The LPCXpresso. On the right is the target board, on the left is the LPC-Link USB JTAG debugger.
An interesting design feature of the board is that the LPC-Link USB JTAG debugger portion of the board can be separated from the target and used separately to program NXP's other Cortex-M0, Cortex-M3 and ARM7/9 devices.

The separated LPC-Link debugger. Picture: NXP

There's three versions of the board. I got the one with the LPC1114 32-bit ARM Cortex-M0 microcontroller. They've also made boards with the LPC1343 and the LPC1769 Cortex-M3 controllers. Check the embedded artists homepage for more info about these. This article focuses on the LPC1114 version.

The target portion of the chip features the LPC1114, a 12 MHz crystal and some limited prototyping space.
The LPC-Link portion of the board has a LPC3154 for the debugging, three LVC125 buffers and a 10-pin JTAG header.
The LPC-Link portion of the board uses a LPC3154 for the debugging. Looking at the datasheet, this chip seems more powerful than the LPC1114 it's programming. There's also a 10-pin JTAG header for JTAG programming.

The backside of the board is bare.
Compared to for example ST's STM32VLDISCOVERY, there seems to be more customer support and there's even an official toolchain for Linux provided.

LPCXpresso development platform features (LPC1114 version)
 - LPC1114 32-bit ARM Cortex-M0 microcontroller
 - All pins of LPC1114 are accessible on expansion connector
 - Built-in LPC-Link USB JTAG debugger that can be used on it's own
 - An LED
 - Small prototyping area on board
 - Can be powered via USB or external 3V

LPC1114 features
 - 32-bit!
 - ARM Cortex-M0 architecture
 - Up to 50MHz clock frequency (12MHz crystal on board)
 - 8kB SRAM memory
 - 32kB Flash memory
 - Two 32-bit counters/timers
 - Two 16-bit counters/timers
 - A watchdog timer
 - 13 PWMs (using timers)
 - Communications: one UART, one I2C, two SSP
 - Integrated Power Management Unit (PMU) to minimize power consumption
 - Three reduced power modes: Sleep, Deep-sleep, and Deep power-down
 - Code Read Protection (CRP) with different security levels

If you want a short intro to the 1114 LPCXpresso, here's a nice slideshow presentation.


NXP's LPCXpresso homepage
LPCXpresso support page - with program examples
LPCXpresso IDE download page at Code Red
LPCXpresso official forum
LPCXpresso homepage at Embedded Artists

Datasheets, manuals
LPCXpresso - getting started (pdf)
LPCXpresso board schematics (pdf)
LPC1114 datasheet (pdf)
LPC1114 user manual (pdf)
LPC1114 erratasheet (pdf) - info on a bug in the built-in ADC
ARM Cortex-M0 technical reference manual
ARM Cortex-M0 generic user guide

Monday, February 7, 2011

Review of Arduino DAC solutions

I was in a need of an analog output output for my Arduino, and I found quite many different digital-to-analog converter (DAC) solutions by googling around. So finally I decided to gather them on one page as a reminder for myself and a guide for others. So here it comes!

R-2R ladder DAC

The most common way to build a DAC is to use a R-2R ladder circuit. Make: Online has a photo-guide for building one. However, this DAC has no output buffer, which would make this circuit a bit more reliable and working with all kinds of loads.

MAKE: Online's DAC shield

Make: Online - Proto-DAC shield for Arduino
A Direct digital synthesizer build using a R-2R ladder DAC - This is worth a look if you're interested in outputting audio.

R-2R ladder DAC with output buffer

For the best results, you should use an output buffer in the DAC. The buffer separates your R-2R ladder from the load you connect it to and makes the result non load dependent. Here's maybe the best tutorial I've seen for a R-2R DAC with an output buffer. It uses a common LM358 operational amplifier that can be driven from single supply. Note that in order to get the full output range to work with this circuit, you need to have a higher than 5V supply for the LM358. Of course, another way to get around this problem is to use a 5V supply but put a simple voltage divider in front of the op amp. Then you'll get lower than 5V output but don't lose fidelity.

Ikalogic's R-2R DAC with an output buffer.

Ikalogic's very good page on R-2R DACs

The 2 cent DAC by raalst

A very clever solution utilizing the integrated pullup resistors on the Atmega chip. You need only 1 resistor and as many output pins as you want bits. The output is a bit crude but 500kHz could be reached. The internal pullups are specified to be minimum 20kohms and maximum 50kohms so the result might not be the most accurate.

Arduino Forum - The 2ct DAC

Simple 10-bit DAC by avdweb

This design uses only two output pins, and the circuit is fairly simple, utilizing an op amp. The max settling time is 20ms, which is way too low for audio output. But the settling time could be enhanced with a circuit modification...

Arduino Forum - Simple 10-bit DAC
avdweb - Simple 10-bit DAC

Using the PWM as a DAC

Of course, you can also use the PWM outputs to get an analog output signal from the Arduino. Just put a low pass filter after the PWM output to get a nice & smooth output with a frequency range up to 16kHz, according to this Lab3 experiment.

A direct digital synthesizer realized with Arduino's PWM output.

Lab3 - Arduino DDS using PWM

Resistor/PWM hybrid DAC

This is a good explanation on how to combine two PWM outputs in order to double the bit resolution. So combining two 8-bit arduino PWM outputs you can get a 16-bit PWM output! Remember Arduino's limits if you plan on going down this road. I mean, the Atmega chip is just 8-bit...
Link doesn't work? Try this one via the Wayback Machine

SPI-interfacing two Microchip MPC4921 DAC chips with Arduino

Stepan Schulz used SPI to interface two MPC4921 12-bit DAC chips. This saves you pins compared to the R-2R ladder. Using the onboard SPI of the Arduino like Stepan, you need 5 pins, but you can save one (maybe even two) if you code the SPI code by hand.

Stepan's post on the Arduino forum
See the code here
MPC4921 datasheet

Audio shield with MCP4921 DAC

Adafruit industries' Wave shield is an audio shield for Arduino that also uses the MCP4921 SPI DAC chip. You can play back 12-bit 22kHz wav files. This means the maximum output frequency is 11kHz.

Adafruit Industries - Wave shield

Midivox - synthesizer shield with the MCP4921

Another shield that uses the MCP4921 DAC chip. This one's quite cool, it's a monophonic synthesizer with MIDI input and the synth engine has an attack / release generator and a cool filter! Proves that the Arduino can be used to generate synth sounds.

Narbotic instruments - Midivox - A synth shield featuring the MPC4921.

DAC using AD420 16-bit serial-input DAC has a good article for using the AD420 with Arduino. There's schematics, pictures and a code example. - High-accuracy 16-bit DAC for Arduino
AD470 datasheet

That's it for now. Thanks for reading! Please comment, if you have anything to add!

[Edit: randy pointed out this site with some hints for Arduino audio DAC solutions. Thanks!]

Tuesday, February 1, 2011

Vinculo - Arduino clone with USB slave / host capability

I just got hold of  FTDI chip's new Vinculo developing platform, so here's a quick review for you!

Vinculo is a 25€ development platform for the FTDI Vinculum II (VNC2) dual USB host/slave microcontroller. The board design has been copied from Arduino, and they even advertise it as Arduino-inspired and Arduino shield compatible. FTDI seems to have realized the potential that comes when having a large hobbyist userbase...

Vinculo could be called a USB-enabled Arduino, but that really doesn't do the board justice. There are many features that set it apart from the Arduino, and it also beats Arduino in all the specs (see below). Of course, it's not nearly as user-friendly as the Arduino as a first platform.

Look what I got in the mail!

Vinculo board with the programming header uncovered (the pins on the right).

Compared to Arduino, there are many differences:
 - The USB ports on the Vinculo can not used for programming the microcontroller - they are used for connecting host or slave devices.
 - You need also a 15€ USB programmer for the Vinculo (it's the small device on the right in the picture below)
 - Due to the flexibility of the VNC2 chip, the signals can be rerouted to different pins
 - Many feature & performance differences, more detail below.

Vinculo board and the programming & debugging module.

A close-up of the USB slave/host ports and the 9V jack.

Vinculo next to an Arduino Duemilanove.

 Vinculo board features:
 - 16-bit VNC2-64Q microcontroller (Arduino is 8-bit)
 - USB Type A connector for use in USB 2.0 host applications
 - USB Mini-B connector for use in USB 2.0 slave applications
 - Connector for external 9V power supply
 - Compatible with shields built by the Arduino community
 - 30 digital input/output pins (Arduino Duemilanove has 14)
 - 8 analog-to-digital converter inputs with 10 bit resolution (Arduino Duemilanove has 6 at same resolution)
 - 8 PWM outputs (Arduino Duemilanove has 6)
 - Variable clock speed: 12 / 24 / 48 MHz (Arduino Duemilanove is 16 MHz)
 - 256 kilobytes of FLASH memory (Arduino Duemilanove has 32 kbytes)
 - 16 kilobytes of RAM (Arduino Duemilanove has 2 kbytes)

Datasheets for the chips on board:
Vinculum-II Embedded Dual-USB Host Controller IC datasheet
MCP3008 8-channel 10-bit analog-to-digital converter datasheet

The pin headers in my Vinculo were all a bit crooked. I seem to have bad luck since my Duemilanoves look like this too. Here's the 8 ADC channels and Reset, 3V3, 5V, GND and Vin pins.
Also the two-row headers were a bit crooked. I'll have to use some force when installing the shields.


The language used to program the Vinculum is a subset of ANSI C. For Arduino users it should be no big challenge but still a bit more complex. The Arduino IDE actually goes so far that it completes the user code to be valid C++, with some extra header code. I don't think the Vinculum-II does any of that.

Unfortunately, the toolchain is only for Windows. This seems to be a very common grief in the embedded world. I'm not sure if it works under Wine. The development IDE can be downloaded for free from here. You need to register to download it. Be sure to install also the patch for the 1.2.2 version.

There's some firmware code examples on the FTDI chip page, with good documentation. You get examples for a 16x2 LCD interface, a graphical LCD interface and a Volt meter using an OLED screen.

If you make a USB slave device with this board, let's say for example some custom game controller, you'll need to use either the Virtual Com Port (VPC) driver or the D2XX direct USB access driver. I haven't gotten that far yet. See the links for the drivers, guides and programming examples.

Vinculo Prototyping shield

The Vinculo prototyping shield in it's package

I also got a 10€ prototyping shield for the Vinculo. The package contains a prototyping PCB, pin headers to fit the Vinculo board, and a minimal set of components: 2 pushbuttons, 2 green and 1 yellow leds and three resistors.

Contents of the prototyping package.

Related links
Vinculo board home
Vinculo board datasheet

Vinculum II homepage
Vinculum II datasheet
Vinculum II toolchain

That's it for now. Stay tuned for some more articles on this board!

EDIT 28. March 2011: Problems with the Vinculo platform.

I haven't had the time to work on this board yet, but others have. Unfortunately it seems that they're not very pleased with the toolchain and the documentation.

Josh Pieper has been hard at work exploring the various issues with the VNC2 Toolchain, and complains that the newly released version 1.4.0 didn't solve any of the many issues he has found & reported. Very good work!

In an element14 post, Josh also answers a question by nickname WestfW:
"Do any of the FTDI documents describe the architecture of the Vinculum2 CPU or chip/peripherals? I couldn't find anyhing in the docs I looked at, or anything that seemed likely on their web site.  They provide a C compiler and a bunch of libraries, but programming something of that complexity without more indication of how it works seems ... scary.

It seems like quite a lot of value stuffed into that chip.  About the same price as an FT232RL with a lot more capability..."

"FTDI appears to be keeping the architectural details closed.  I've been working on a project with the VNC2 and have run into serious problems in the compiler, linker, libraries, and IDE which make me think that the toolchain is just not that robust yet."

So, looks like Vinculo is a quite closed and immature platform. FTDI probably rushed the product to market. That's not strange at all, seems like nowadays every company does that. But not fixing the serious user-reported bugs in the toolchain - that's strange.

Let's hope FTDI fixes these problems in the next update and even gives some more information on this platform so the power of Vinculo could be fully unleashed among the hobbyists.

Sunday, January 30, 2011

Free toolchains for STM32VLDISCOVERY

How to program the STM32VLDISCOVERY board? ST does not provide a toolchain themselves, instead there are three different officially supported toolchains available, for which ST has provided simple tutorials. All of the three official toolchains are for Windows, so Linux users have to think of something else. Fortunately, multiple options exist for also Linux users.

Here's an overview of all the tools I'm aware of. First off, I'll explain the easy, official options. These are unfortunately only for Windows users.

Officially promoted toolchains

ST provides example code and documentation for three toolchains: Atollic TrueSTUDIO, IAR Embedded Workbench and Keil MDK-ARM.
Download ST's example firmware package here
User manual for the firmware package

Below are some quick facts & links about the official toolchains.

Atollic TrueSTUDIO (Windows)

This is an Eclipse-based development platform that includes an optimizing C/C++ compiler, editor and a debugger. With the free Lite version, you lose the C++ support, but you get unlimited code size and usage time. If you eventually use the Lite version to design an embedded product, they want you to note it in the user documentation of your product. There is also a 30-day trial version available which has all the functionality of the Professional version. If you use Windows, this toolchain is probably the best & easiest choice to start with. According to a forum post I read, it doesn't work under Wine.

Download Atollic TrueSTUDIO for STM32 here
Lite version vs. Professional comparison
ST user manual for Atollic TrueSTUDIO tutorial: Start new project using Atollic & STM32VLDISCOVERY tutorial: STM32 library examples in Atollic tutorial: how to use the ST code examples with Atollic

IAR Embedded Workbench (Windows)

IAR Embedded Workbench

The Kickstart edition is a free version of the IAR Embedded Workbench. It's limited to 32kB code size, but otherwise it's fully functional. You have to register it in order to get a license key.

ST User Manual for IAR Embedded Workbench
Download the Kickstart edition of IAR Embedded Workbench for ARM here

Keil MDK-ARM-Basic (Windows, under Wine in Linux)

MDK-ARM in action.

There's a free version available of the Keil MDK-ARM-Basic toolchain, but it comes with a 32kB code size restriction. You need to register on the site to get to the download. According to a forum post I read, the Keil toolchain works also in Linux under Wine.

ST User Manual for Keil MDK-ARM
Download the Keil MDK-ARM-Basic here.

STM32 ST-Link Utility (Windows)

ST-Link Utility

This free program from ST can be used to flash the microcontroller and to read and modify the memory contents on the fly. Unfortunately, it's only for Windows.

ST homepage: STM32 ST-Link Utility
Download the STM32 ST-Link Utility here
STM32 ST-Link Utility - User Manual

Alternative options

Here's a list of alternative programming tools for the discovery. Many Linux ones, also some Windows. Unfortunately, to my knowledge, the built-in ST-Link debugger does not work with Linux. Debugging is possible only through some effort. (Edit: Now ST-Link works under Linux too, see "Captn's missing link")

I have to say that I haven't tried out these options yet... If you have some experience and know better, please comment below!

GNU ARM toolkit (Linux, MacOS, Windows under CygWin)

A free toolchain under the GNU license.
GNU ARM toolkit homepage
Installing the GNU ARM toolkit - a blog post with some installation info

Sourcery G++ Lite Edition for ARM EABI (Linux, Windows)

This is a free command-line compiler tool for Linux & Windows.Get the embedded application binary interface (EABI) version. That version is meant for developing stand-alone programs for STM32.
Sourcery G++ Lite Edition homepage
STM32 development - a useful tutorial page

GCC (Any platform)

Here's a guide on compiling GCC with floating-point support for STM32 development.

stm32flash (Linux, Windows)

An open-source command-line tool for flashing STM32 processors using the STM32 bootloader. Support for Linux & Windows. Here's a guide how to program your STM32 with stm32flash.

stm32flash project homepage
STM32 development - a page with useful info on using open-source tools for STM32 development
a Blog post with some help on using stm32flash

STM32 ARM-Cortex bootloader (any OS)

A python script for flashing the STM32, runs on any OS with Python installed. The aforementioned stm32flash is said to be a better solution, but it's only for Linux & Windows, while this runs under Python anywhere.
STM32 ARM-Cortex bootloader home page

CooCox tools (Windows)

CooCox CoIDE

CooCox offers many free tools suitable for STM32F100RB. Unfortunately they are not compatible with ST-Link, but you can use their free and open CoLink programmer among others. Coocox CoIDE is a new, free and highly-integrated software development environment for ARM cortex M3 and M0 based microcontrollers. CoOS is a free and open realtime operating system for the Cortex-M series. CoFlash is a stand-alone flash programming software that uses their free CoLink programmer. Unfortunately, the software is for Windows only.
CooCox development tools
A forum post with help for CoIDE with STM32VLDISCOVERY

Raisonance Ride7 (Windows)

Raisonance Ride7 and RKit-ARM is a complete toolchain for ARM Cortex-M. There are some limitations to the unlicensed software. What the limitations are is not very clear, but at least there's no code size limitations. (Thanks error404)

Download Raisonance Ride7 and RKit-ARM and documentation here

Free Pascal (any OS)

Jeppe at the element14 forums pointed out Free Pascal. He says it's a fun and logical langugage to use, but not entirely finished yet. Still, should probably work for most uses.
Jeppe's post at the element-14 forums
Jeppe's page with some help for Free Pascal and the STM32F103 (should be quite close to F100RB)

Captn's missing link - ST-Link on Linux!

This guy has succeeded in making the ST-Link working under Linux. This means you can finally program the STM32VLDISCOVERY via it's built-in USB programmer under Linux! Quoting texane in the discussion: "an opensource stlink-like standalone software to program the discovery kit is on its way. It is a bit crappy yet (you will have to look inside the source), but it supports both flash and RAM programming plus some other features." Great news!

Captn's missing link
Texane's repository of the mlink source code with added flash access on Github:

Another ST-link upload / debug program for Linux, from the comments. Thanks Anonymous!

The creator, Donald Becker, writes:
"It's a command line program to do the usual download/upload/debug actions.
It can
  - write firmware into the flash (system and user memory)
  - read/verify/write to memory and devices
  - read and set registers and
  - change run state (run/debug/halt) and
  - single step"

arm-utilities Google code page
An introduction post in the Openocd-development mailing list

Using BusPirate for serial-wire debugging the STM32

Debugging the STM32VLDISCOVERY with a Bus Pirate

If you want to debug your STM32 in Linux, here's a page about using a handy tool called the Bus Pirate for that cause.

OK, that's it for now. If you have any other options, ideas or recommendations, please comment!

[Edit: added CooCox tools, Raisonance Ride7]
[Edit2: added Free Pascal]
[Edit3: added Captn's missing link]
[Edit4: added arm-utilities]

Overview of the STM32VLDISCOVERY evaluation board

The STM32VLDISCOVERY evaluation board.

The STM32VLDISCOVERY is a $10 evaluation board for the STM32 value line microcontrollers. It has a 64-pin STM32F100RB microcontroller, can be powered & programmed via USB, one user push button, a reset button and two user leds. The board is quite barren and doesn't have much features, just I/O pins - but that's exactly what we DIYers want! You can decide yourself what you want to use the ports for.

Only downsides to the board are bad Linux support (three proprietary windows toolchains are supported) & bad breadboard compatibility. Luckily, you can go around both issues with a bit of effort.

STM32F100RB features:
 - 32-bit!
 - CPU frequency max. 24 MHz (evaluation board has a 8 MHz crystal)
 -128 kilobytes of Flash program memory
 - 8 kilobytes of SRAM
 - Up to 7 16-bit PWM timers: 1 advanced control timer, 6 general-purpose timers
 - Communication interfaces: 2 x SPI, 2 x I2C, 3 x USART, 1 x HDMI-CEC
 - 12-bit analog-to-digital converter (ADC) with 16 channels
 - 12-bit digital-to-analog converter (DAC) with 2 channels
 - 51 general-purpose inputs / outputs (GPIOs)

There are actually two programmable microcontrollers on the board - in addition to the STM32F100R, there's an STM32F103 on the board, serving as a debug interface called the ST-Link. A curious thing about it is that the chip used for debug is actually more powerful than the chip you're supposed to program. If you're hardcore, you can make use of both chips and flash also the STM32F103, but you will lose the USB programming capability.

Related links
STM32VLDISCOVERY evaluation board homepage - data sheets, firmware package...
STM32F100RB microcontroller homepage - data sheets, application notes, user manuals...
Dangerous prototypes forum - Thread about STM32VLDISCOVERY