Showing posts with label Gizmo. Show all posts
Showing posts with label Gizmo. Show all posts

Thursday, May 1, 2014

Testing the AD5697R DAC

Yesterday I tested an interesting DAC: the AD5697R. This an interesting 12 bit dual channel Digital to Analog Converter (DAC). I plan to use it on a project where it will susbstitute some operational fixed voltages. 
Using a DAC instead of a potentiometers make those voltages adjustables by the microcontroller that manages all the system. Moreover, as the DAC features an internal reference the voltage values are independent on power supply variations. 

Unfortunately, as is more and more habitual this days the DAC only comes in SMD packages and they are not board friendly at all. This 16 pin device comes in the 3mm x 3mm Lead Frame Chip Scale Package (LFCSP) package and in the 5mm x 4.4mm Thin Shrink Small Outline Package (TSSOP) package. That's tinny!

Adpating the chip to protoboard use

I selected the 16 TSSOP package as it's easier to solder although it features a 0.65 pin pitch that is about 1/4of the standard 2.50 (100 mil) DIP pitch. To test it on a protoboard I used an SMD adapter. The following figure shows the adapter I used before soldering the chip. The image also serves to show the pitch difference between TSSOP and 100 mil DIP.

TSSOP16 Adapter
As is normally the case, the adapter costs more than the DAC chip itself.
This adapter, however, has one problem: It uses dual rows of pins at either side of the chip. That's bad for a protoboard as you will short odd and even pins.
The solution was to extend the adapter after I soldered the chip:

Adapter extension




Using the extension half of the 100mil pitch pins are soldered to the original adapter and the other half to the extension.


Test circuit

So far so good. Time to test the chip.
In order to test the chip I used the F3 Gizmo to send the I2C commands the chip needs to operate.

Test circuit for the DAC
The circuit only needs four main wires: 3V supply, ground and the I2C SDA and SCL lines. A0 and A1 are connected to ground although this is not shown in the above schematic.

Test circuit on the protoboard

Test of the DAC

Once the test circuit is mounted it's time to test the DAC by sending some I2C commands.

The 7 bit I2C address for the DAC is

0 0 0 | 1 1 A1 A0

As A1=A0=0 the address will be:

000 1100 = 0xC

Using the F3 Gizmo ISCAN word whe can check that the I2C channel is operational:

     ISCAN
     0xC

To send data to the DAC we must send 3 Bytes to it's I2C address.

The first Byte indicates the command and the channel.
The 4 MSBs are the command. The command I tried is:

0011 (3h) Write to and update DAC channel n

This command directly writes a binnary data to one or both DAC channels.

The 4 LSBs of the first Byte selects the channel to adress:

    0001 (1h) DAC A
    1000 (8h) DAC B
    1001 (9h) DAC A and DAC B

The two following Bytes to send are the data to send to the DAC. As two bytes are 16 bits and the DAC channels are 12 bits only, the last 4 LSBs bits are discarded.

The DAC uses an internal 2.5V bandgap reference. The full scale (FFFh code) should be 1 LSB below the reference for the selected GAIN=1. If the GAIN pin was at VDD the selected GAIN would be 2 and the full scale value would be one LSB below 5V.

In order to set the A channel to the maximum value we can must send the following data:

  Command: 3h
  DAC addressed: 1h
  Code to send: FFFh
  Last dummy nibble: 0h

We can use the following F3 Gizmo command in order to send the data:

   0xC 0x31 0xFF 0xF0 3 0 I2CT

As a result the output goes to 2.5V as expected.

To set any other value we must compute the 12 bit value. For instance, to set the output to 1V we must use the code:

   code =4096 * 1 / 2.5 = 1638 = 666h

Using the F3 Gizmo that means sending the following command:
   0xC 0x31 0x66 0x60 3 0 I2CT

As you can see from the multimeter reading the response is quite good.

Measuring the response to code 0x666
Having the DAC an internal reference makes very easy to generate exact absolute output values.

The test was a success. Now I can test the rest of the I2C functionality before deploying the DAC in the project.

Saturday, April 26, 2014

Presenting the F3 Gizmo

Today I present the F3 Gizmo. A firmware solution for the STM32F3 Discovery board.

Motivation

The STM32F3 Discovery board is a fantastic board full of features that ST  sells at a very low cost. In includes a STM32F303 ARM Cortex M4 32bit microcontroller running at 72 MHz, 8 LEDs, one Gyroscope and one combined Accelerometer/Magnetometer. The microcontroller itself includes several communication ports: Serial, SPI, I2C, CAN, USB... as well as a lot of other peripherals like GPIOs, timers, Operational Amplifiers and Comparators.
The problem is that it is not easy to program. At least not as easy as an Arduino for instance.

STM32F3 Discovery Board


There are software solutions that ease the use of this board. One case is the ChibiOS/RT Real Time Operating System (RTOS) that provides all the board initialization code, a Hardware Abstraction Layer (HAL) and and a mutithreaded operating system.
There are other solutions aside from ChibiOS/RT but this is the one I use.

Building a software solution for the STM32F3 Discovery board using ChiBiOS/RT as its foundation is much easier that trying to build from scratch or from the verbose libraries that ST provides but it is still complex. Not only that, but you have to piece together a development environment with compiler, editor, debugger, and so on although ChibiStudio eases this process.

Sometimes you have an idea to test quick and dirty and you don't need a fully featured development environment. Or you have a new SPI or I2C chip to check. In those cases you need to develop a small test program, compile it, flash it on the microcontroller and run it.


What is the F3 Gizmo

The F3 Gizmo tries to ease quick tests of ideas by providing a Forth like development environment in the STM32F3 board.

You only need to burn the F3 Gizmo firmware on a STM32F3 Discovery board, connect it to a PC using one USB cable and stablish a serial over USB connection using an emulator terminal .

F3 Gizmo Console
In the above figure we see the start of the F3 Gizmo as shown in the PuTTY terminal emulator. 
Just writing 0 LedSet in the console one LED (Number 0) in the board is lit. 
Just writing AccelRead we get the X, Y and Z readings on the acceleromenter.

Do you want to blink the led? Write:

: blink begin 0 ls 300 ms 0 lc 300 ms again ;
blink

The new  blink user word definition can be used just like the built-in  LedSet  word and it can be used in any new user word definition making the system perfect for incremental development.

What to check the addresses of an I2C device?  
Connect it and call  ISCAN

Do you want to access the internal microcontroller registers?
You also can:

0x48001000 CONSTANT gpioe  \Start of GPIOE
0x14 CONSTANT odr          \Offset of ODR register
gpioe odr +                \ODR register of port E
DUP @                      \Get current ODR value
1 9 LSHIFT OR              \OR with bit 9
SWAP !                     \Store new ODR


It is fast and it is interactive. You don't need anything on the host PC aside from the terminal emulator.
And it's Forth like.

And all operates in RAM. You can create new words (something like functions), erase them, rewrite them and you don't need to touch the flash memory of the microcontroller.
If any time you want to store the current RAM status you can use save it on the flash to recover it on the next reboot.

If you want to test a system that don't use the console, you can set a function to start when the board boots, save the RAM in flash and make it work standalone.

The F3 Gizmo don't pretend to be the next great development environment. It just tries to be a quick and easy access to the STM32F3 Board features.

Features

The F3 Gizmo makes a fixed assignment of several board pins. The following figure shows each allocated pin.
F3 Gizmo Pins
Currently the F3 Gizmo manages the following Board /MCU elements:
  • 8 User LEDs
  • 10 Digital I/O pins
  • 3 PWM digital outputs
  • 6 Analog input channels
  • 1 Analog DAC output channel
  • 2 General use Timers
  • 1 SPI Bus
  • 1 I2C Bus
  • 1 Giroscope
  • 1 Combined Accelerometer/Magnetometer
It also provides some features provided by the underlying ChibiOS/RT operating system:
  • Mutithreaded execution
  • Binary Semaphores
  • Mutexes
In the future I plan to include at least:
  • Two asyncronous serial lines
  • 2 Operational Amplifiers
  • 2 Comparators
  • 1 CAN bus
 

 Components

The F3 Gizmo is composed by three elements:
  • ChibiOS/RT : Provides the Board and MCU Start routines, the HAL for several of the microcontroller peripherals and all OS services.
  • CForth engine: Provides the basic machine independent programing and interpreter language.
  • F3 Gizmo port for the CForth engine. Provides the link between CForth and all MCU or board specific features. It also includes the low level code for the features that don't use the ChibiOS/RT HAL.

Installing the F3 Gizmo

To install the F3 Gizmo you just need its firmare file that is available in bin and hex formats and the STLink utility that ST provides.
You only need the bin file. The  hex is not necesary for the STLink utility.

F3Gizmo_V1.0(2014-04-25).bin

F3Gizmo_V1.0(2014-04-25).hex.zip

Of course you can also build it from its sources but you'll need an ARM toolchain:

F3Gizmo_V1.0(2014-04-25) Source.zip


Manuals

To learn how to use the F3 Gizmo you have two manuals:

The F3 Gizmo Manual explains how to install the firmware and use all STM32F3 Discovery Board Functionalities.

F3 Gizmo Manual v1.0 (2014-04-25).pdf

As the F3 Gizmo implements a Forth like language called CForth, you will also need the CForth manual as the F3 Gizmo manual don't explain the operations of the CForth engine.

CForth Manual v1.0 (2014-04-20).pdf

That's all for now. Just try it if you like.
In the future I will post more entries about the F3 Gizmo use.


13/5/2014 Update

The project is now on Github:

https://github.com/R6500/STM32F3_Gizmo