Logo Banner

Velleman K8055 - [K8055 Hardware Tutorial]

K8055 Hardware Tutorial: Analog Inputs

Analog vs Digital signals

First of all you should realize there are two different kind of signals the K8055 can handle: analog and digital signals.

A digital signal only knows two different states: HIGH or LOW (1 or 0). These two states correspond with a certain voltage level (0/5 V). Digital signals are used to read the state of switches/push buttons.

An analog signal can have any value between 0 V and 5 V (these values are examples). Computers cannot work directly with analog values: they have to be converted into a digital value first. This is done by an A/D converter. A possible source for an analog signal is a potentiometer, a variable resistor.

A/D conversion

The Velleman K8055 has two inputs to measure analog voltages. The initial configuration of the K8055 allows you to measure voltage between 0 and 5 V.

Inside the K8055 the analog signal is first processed by some analog circuits. After this processing it is applied to an A/D converter inside the microcontroller: converter will convert the analog signal to a digital value.

The A/D converter has a resolution of 8 bits. This means it can generate a binary value between 00000000 and 11111111 (0 - 255 in the decimal system). The A/D converter can convert any voltage between 0 and 5 V. This means the measuring resolution is 5 V/255=19.6 mV.

So: applying 0 V to the A/D converter will read as a zero. Applying 5 V will read as 255. The value between those two limits is quite linear: a voltage of 2.5 V will correspond with a digital value of 127 or 128.

In reality the A/D converter is not completely accurate. I did some research on this subject while doing my K8055 Voltage Recorder project. On these pages you can find more information about the accuracy of the A/D converter.

Connecting an analog source

Connecting an analog source with the K8055 is very easy: connect its "+" with the AN1 input, and connect its ground with the GND input of the K8055. The polarity of the signal is VERY important: the K8055 can only read positive signals.

There is one important thing you should always keep in mind: all analog/digital channels of the K8055 share a common ground (GND) connection! Forgetting this can cause short circuits.

The K8055 has a default input range of 0 - 5 V for the analog inputs. You should not exceed this range: it might damage your K8055 and even worse. But if required, you can increase the range. This can be done by putting a resistor between the analog source and the analog input:

You will need to calculate the required value for this resistor. This can be done with the formula below. In this formula you need to fill in the absolute maximal input voltage you expect at the inputs. See a PDF that explains how I got this formula

In some cases you want to measure very low voltages, let's say a voltage between 0 and 20 mV. Earlier you could read the resolution of the A/D measurement is 19.6 mV. So trying to read a 20 mV signal ... won't work well. The solution is easy: you need to amplify the input signal before you apply it to the A/D converter. Lucky you! The K8055 has an optional gain: it can be activated by soldering a resistor for R8 or R9 (each channel has a separate gain).

The gain is 1 (no amplification) if the resistors aren't soldered. If soldered, the gain will depend on the values of resistors R8/R10 for analog channel 1, R9/R11 for analog channel 2. The K8055's manual gives you two formulas to calculate the gain for each channel:

They may look familiar: these are the formulas to calculate the gain of a non-inverting Opamp (Operational Amplifier). Usually it is not the gain you need to know, but the resistor value you need to obtain a specific gain. You can use these two formulas for this (*):

(*) R10 and R11 are known resistors: they have a value of 10k.

Let's go back to our case where we wanted to measure a 20 mV signal. To measure it properly, it should be amplified 250 times: 20 mV * 250 = 5 V. The resolution of the A/D conversions will then become 78 ÁV. Better, no?

One more thing: the K8055 has a variable resistor for each analog input. You should turn it completely clockwise or it will influence your input signal.

How to program it?

First of all: I will not teach you how to write programs. Please view my K8055 software tutorial on how to get started. The following code assumes you have created a Visual Basic 2010 project with a Form called "Form1". The form has 1 button which is named "Button1". You also need to add my K8055 class to your project.

    Public Class Form1
      Dim myK8055 As New K8055()
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim readValue As Integer
        readValue = myK8055.ReadAnalogInput(1)
        MsgBox("Digital Value read = " & readValue)
      End Sub
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        myK8055.connect(SK5:=False, SK6:=False)
      End Sub
    End Class		

This example will initialize the K8055 during the loading of the form. The jumper settings are false/false: there are no jumpers installed for SK5 and SK6.

During the Button1.click event the analog value of A/D channel 1 is read, and is put into the readValue variable. This variable is then shown in a message box. So, each time you press the button the current value of the A/D channel is shown.

Copyright ©1998-2022 Vanderhaegen Bart - last modified: August 24, 2013