Data Acquisition with Esduino Xtreme
Abiran Raveenthiran – raveea3 – 1310644
Table of Contents Abstract ......................................................................................................................................................... 3
Introduction and Background ....................................................................................................................... 3
Design Methodology ..................................................................................................................................... 4
Quantify Signal Properties ........................................................................................................................ 4
Precondition/Amplification/Buffer ........................................................................................................... 4
ADC (Analog to Digital Converter) ............................................................................................................ 6
Data Processing (Algorithm Flowchart) .................................................................................................... 7
Control/Communicate (Algorithm Flowchart) .......................................................................................... 8
Full System Block Diagram ........................................................................................................................ 8
Full System Circuit Schematic ................................................................................................................... 9
Results ......................................................................................................................................................... 10
Preconditioned Circuit Results ................................................................................................................ 10
Final Result .............................................................................................................................................. 11
Discussion.................................................................................................................................................... 12
Conclusion ................................................................................................................................................... 13
Appendices .................................................................................................................................................. 14
Appendix A .............................................................................................................................................. 14
Appendix B .............................................................................................................................................. 16
Abstract In this paper we are trying to display a voltage input on a pc display. This was accomplished with
the use of a conditional circuit, A/D converter and a PC display. The voltage is first converted using the
signal-conditioning circuit to change the range of voltages between -2V and 2V to 0V and 5V. This was
accomplished by modifying a level-shifting and scaling circuit. The numbers are inputted through the
Esduino and Codewarrior which then sends the output to matlab. Matlab is the PC display and projects a
graph similar to the original input. To test the preconditioned circuit, the output is confirmed using an
oscilloscope to measure the peak amplitude which the modified level-shifting and scaling circuit
successfully accomplished. As expected, the output generated a graph, on matlab, displaying a waveform
of 0 to 5V.
Introduction and Background Data are facts or information used to calculate, analyze or plan something. Engineers need to be
able to acquire data in the most cost-effective, least complex and efficient method possible for the task
at hand. A core component of a modern computer that can be implemented to assist in analyzing data is
a microcontroller. A microcontroller is an inexpensive, single integrated circuit which is dedicated to
perform one task and execute one specific application.
The purpose of this project is for students to understand how data acquisition system operate in
the many industries engineers can be present and have their own hand’s on experience on the topic. One
of the primary objectives for this course include having the capability to collect analog data using the
microcontroller and using the data to be able to process and communicate it.
This project will use a signal conditioning circuit to convert and amplify a given input voltage,
process the data through and serially transmit the data through a graph on a PC display. A start and stop
should be implemented either a software command or physical button.
The requirements for this project were based on my student number 1310644. This resulted in:
ADC Channel: 6
ADC Resolution: 10
Bus Speed: 8 MHz
Sampling Frequency: 420 Hz
Figure 2
Design Methodology
Quantify Signal Properties ADC Channel: AN6
ADC Resolution: 10
Bus Speed: 8 MHz
Sampling Frequency: 420 Hz
Sampling frequency is implemented using the delay of 1/420Hz=2.3ms delay
The analog signal is an AC centred about 2.5V with an amplitude of 2.5V will be inputted with
various frequencies.
Precondition/Amplification/Buffer The analog signal needs to be altered before entering the A/D converter. The analog signal needs
to be converted to be between 0V to 5V.
Fig. 1 is a voltage translation circuit; specifically, a level-shifter and scaling circuit. It was used to precondition, amplify and buffer the analog signal given that needs to have a slight modification for the project. The branch with R2 needs to be moved to the dotted line. This creates an offset of +2.5V. Using the equations (1) and (2), basic circuit analysis techniques and trial and error, a configuration of resistors was found that met the conditions. Fig. 2 has the values of resistors for the configuration which was possible with the resistors available. Fig. 3 is the modified circuit with the resistor values.
For confirmation on the circuit, it as simulated in
www.falstad.com/circuit/ which is an applet that can be used to build and simulate circuits. For the
simulated circuit, a signal 0±2V with a frequency of 150Hz was supplied, Fig. 5. The simulated circuit was
able to convert the signal to a maximum of 4.91V and minimum of 29.68mV, as seen in Fig. 4. This meets
the requirements of the voltage being within the 0V to 5V range.
Component and Values Found
Resistors Value
R0 10kΩ
Rf 12.2kΩ
R1 10kΩ
R2 24.7kΩ
Figure 1 – Level Shifting and Scaling Circuit from Textbook
(1)
(2)
Figure 3 – Simulated Circuit in Falstad Widget
Figure 4 – Vout in Scope
Figure 5 – Vin in Scope
t
t
Figure 6 – Physical Circuit
ADC (Analog to Digital Converter) The Esduino Xtreme from Technological Arts is implemented with a full featured Freescale S12
microcontroller having Flash, EPROM ad SRAM memories, SCI, SPI, and CAN communications subsystems,
dual 8-bit DACs, sophisticated 16-bit timer channels. PWM and multichannel 12-bit analog to digital
conversion capability along with other features which can be found in the Esduino Xtreme User Guide.
The ADC channel used for my specifications was PIN 6. The device was programmed using C and
Codewarrior was used as the IDE.
𝑏𝑎𝑢𝑑 𝑑𝑖𝑣𝑖𝑠𝑜𝑟 =𝐵𝑢𝑠 𝐶𝑙𝑜𝑐𝑘
16 ∗ 𝐵𝑎𝑢𝑑 𝑅𝑎𝑡𝑒
The above equation can be used to find the baud divisor which was 52. The bus speed required
for my student number is 8 MHz. To set the bus speed, there are three equations found in Week 8 Lecture
2 & 3 (Doyle, 2016). Using the following equations and given values, SYNDIV was found to be 15 for bus
speed 8MHz.
𝑓𝑉𝐶𝑂 = 2 ∗ 𝑓𝑅𝐸𝐹 ∗ (𝑆𝑌𝑁𝐷𝐼𝑉 + 1) = 32 𝑀𝐻𝑧 𝑓𝑅𝐸𝐹 = 1 𝑀𝐻𝑧
𝑃𝐿𝐿𝐶𝐿𝐾 = 𝑓𝑉𝐶𝑂 (𝑃𝑂𝑆𝑇𝐷𝐼𝑉 + 1) = 16 𝑀𝐻𝑧⁄ , 𝑃𝑂𝑆𝑇𝐷𝐼𝑉 = 1
𝐵𝑢𝑠 𝐶𝑙𝑜𝑐𝑘 = 𝑃𝐿𝐿𝐶𝐿𝐾 2⁄ = 8 𝑀𝐻𝑧
The implementation can be seen in the code in Appendix A.
Data Processing (Algorithm Flowchart) Codewarrior
Start
Initialize All Variables
Set Bus Clock, AC Channel and Resolution
Set Baud Rate
Loop Whie True
Set/Take the Values from Regster
Output Value
New Cell
Delay
MATLAB
Break
Never Breaks
Control/Communicate (Algorithm Flowchart) Matlab
Full System Block Diagram
Start
Initialize Port, Baud Rate
Set Conditions
No Conditions
Plot in New Window with Start Button
GUI Window
Function Generator
0±2V
Level-Shifting and Scaling
Circuit 10-bit ADC
Esduino Serial Communication
at 420Hz
PC Display (Matlab/Real
Time)
Full System Circuit Schematic This is the top view of the full system circuit. The yellow jumper from the circuit connects to the
AN6 channel of the Esduino (D4). From the Analog Discovery to the circuit, the red wire supplies 5V, the
black wire is ground, white wire supplies -5V, yellow wire supplies the sinusoidal input to be converted.
Figure 7 – Full Circuit Schematic
Results The PC used to output the information is Lenovo B50-80 with a processor Intel(R) Core(TM) i5-
5200U @2.20GHz 2.20GHz with RAM of 4.00 GB.
Preconditioned Circuit Results The graph below shows both the output voltage (C1) and input voltage (C2) generated in the
Waveforms software by Diligent for the Analog Discovery. The frequency chosen for the graph below is
150Hz. It clearly shows the output as a sinusoidal signal between 0V to 5V which was converted from the
input of a sinusoidal signal between -2V and 2V. C2 also has a frequency of 150Hz and an Offset of 0V.
Figure 8 – input and output of preconditioned circuit
Final Result This graph outputted on matlab is the exact graph as expected. As predicted lower and higher
frequencies change the quality of the graph produced on matlab.
Figure 9 – output results graphed on matlab
Discussion Maximum Quantization Error for the 10-bit ADC is
𝑉𝐷𝐷
2𝑅𝑒𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛 𝑜𝑓 𝐴𝐷𝐶 = 5
210 = 4.88mV which results in
an error of 4.88
5∗ 100 = 0.0977%.
My maximum standard communication rate is 115200.
Serial communication is a communication protocol that allows systems to communicate an swap
information such as the Esduino and PC to communicate with each other.
My primary limitation speed is caused by matlab which takes the longest to do.
The Nyquist rate should be at least twice the maximum frequency of the analog signal to
effectively reproduce the lossless digitization. Since the Nyquist rate is 300 Hz, the maximum frequency
is 150Hz. If the frequency is more than half the Nyquist rate, the high-frequency data will alias. Alias is a
false lower frequency component that appears in the sampled data acquired at too low a sampling rate.
Input signals with sharp transitions are not accurately reproduced because the point may be
missed depending on the Nyquist frequency. As seen in the image below, the sample rate of the waveform
affects the new waveform being reproduced.
The more points sampled, the more accurate
the waveform produced will be and will more
accurately reproduce input signals with sharp
transitions.
Figure 10 – the effects of different Nyquist rates.
Conclusion Data acquisition is the process of measuring an electrical or physical phenomenon with the
assistance of a computer. The overall objective for this project include having the capability to collect
analog data using the microcontroller and using the data to be able to process and communicate it. These
listed steps are what data acquisition is. The project provides a hands on environment for students to do
data acquisition and understand the data collected. Analog to digital conversion is one of many types of
data acquisitions that an engineer will conduct in their professional career.
The real world applications of an analog to digital converter are near endless and is implemented
in a number of devices that we use on a regular basis. This is just one of many types of data acquisition
that an engineer will conduct in their professional career. By simply putting a transducer before the
preconditioned circuit, we can apply this project to many real world applications such as measuring and
collecting data for different temperature, pressure, light, weight, airflow, humidity and many other types
of data. Engineers can be found in a variety of industries and projects which involves collecting in a variety
of methods. This project gives insight and a start to the collection of various types of data for students to
learn and apply to future projects.
Appendices
Appendix A //CodeWarrior
// Abiran Raveenthiran 1310644 2DP4 Project
#include <hidef.h>
#include "derivative.h"
#include "SCI.H"
void delayby1ms(int x);
unsigned short val; // global variable
void main(void)
//Bus
CPMUCLKS = 0x80; //PLLSEL = 1, Same as the lecture slide
CPMUOSC = 0x00; //OSCE = 0, Same as the lecture slide
CPMUSYNR = 0x1F; //VCOFRQ = 0, SYNDIV = 31.
CPMUFLG = 0x00;
// ADC channel
ATDCTL1 = 0x2F; // 10-bit resolution.
ATDCTL3 = 0x88; //
ATDCTL4 = 0x02; //
ATDCTL5 = 0x26; //
switch(9600)
case 2400: SCI0BDL=163; break;
case 4800: SCI0BDL=81; break;
case 9600: SCI0BDL=52; break;
case 19200: SCI0BDL=20; break;
case 38400: SCI0BDL=10; break;
default: SCI0BDL = 52; // 9600
SCI0CR1 = 0;
SCI0CR2 = 0x0C;
for(;;)
val=ATDDR0; // read result from data result register 0
SCI_OutUDec(val);
SCI_OutChar(CR); //new cell
delayby1ms(2.38); // 1/420
//
void delayby1ms(int k)
int ix;
/* enable timer and fast timer flag clear */
TSCR1 = 0x90; /* timer interrupt disabled, set prescaler to 1*/
TSCR2 = 0x00;
TIOS |= 0x01;
TC0 = TCNT + 8000;
for(ix = 0; ix < k; ix++)
while(!(TFLG1_C0F));
TC0 += 8000;
TIOS &= ~0x01;
Appendix B //Matlab Code
function varargout = START(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @START_OpeningFcn, ...
'gui_OutputFcn', @START_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin1)
gui_State.gui_Callback = str2func(varargin1);
end
if nargout
[varargout1:nargout] = gui_mainfcn(gui_State, varargin:);
else
gui_mainfcn(gui_State, varargin:);
end
% End initialization code
% --- Executes just before START is made visible.
function START_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to START (see VARARGIN)
% Choose default command line output for START
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes START wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = START_OutputFcn(hObject, eventdata, handles)
varargout1 = handles.output;
s = serial('COM3','BaudRate',9600,'Terminator','CR'); % CR is a terminator,
creates a new cell but also acts as a terminator.
fopen(s);
%total reading time, seconds
Totaltime=0.5;
%sampling frequency, Hz
frequency=420;
%resolution, bits
resolution=10;
%full scale voltage, V
V=5;
normFactor=V/(2^resolution);
data=zeros(1,frequency*Totaltime);
while(1==1) %repeat forever
for i=1:frequency*Totaltime+1; %use a while loop because matlab
automatically uses matrices in for loops STORES VALUE IN VECTOR
data(i)=normFactor*str2double(fgetl(s)); %
i=i+1;
end
plot(data);
ylabel('Voltage (V)')
xlabel('time (s)')
pause(0.05);%Difference between the two plots
end
clear all;
delete(instrfindall);
close all;