Analog-To-Digital Conversion
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
EECS 461
Lab 3: Analog-To-Digital Conversion
1 Overview
In this lab you will learn how to use the analog to digital converters on the NXP S32K144 microcontroller.
You will then sample a sine wave produced by the signal generator and display the result on a virtual
oscilloscope to study the phenomenon of aliasing. See Chapter 42 in the S32K144 Reference Manual:
“Analog-to-Digital Converter (ADC).” A block diagram of the ADC is found in Figure 1.
Figure 1: Block diagram of the ADC module.
EECS 461: Embedded Control Systems
Lab 3 Analog-To-Digital Conversion ANin
GND
GND
5V
5V
6 4 2 0
7 5 3 1
Potentiometer
(Turning Knob)
PotJump (Connector)
Figure 2: Pin connection matrix between external signals and S32K144 microcontroller.
1.1 Analog-To-Digital Converter Module
The S32K144 contains two successive approximation register (SAR) A-D converter modules, referred to
as ADC0 and ADC1, each of which has 16 input channels. In Lab 3, we shall only use channel 0 of ADC0.
The ADC may be operated using either software or hardware to trigger conversions; we shall only use
software triggered conversions in Lab 3. The ADC also has single and continuous conversion modes; we
shall only use single mode conversions.
The clock for the S32K144 ADC uses an 8 MHz clock instead of the 80 MHz system clock.
2 Design Specifications
2.1 Hardware
The interface board has connections to eight of the input pins from the ADC module. The connections
are made to pins ANin0 through ANin7. Each input is connected to a four-pin header consisting of the
input signal, ground, a +5 volt reference and one unused pin.
A potentiometer is mounted permanently on the interface board to provide a variable input signal for
A/D conversion. Note the jumper that must be connected to the ANin0 signal pin for this to work,
as shown in Figure 2. In this lab, you will use this potentiometer as well as a sine wave from a signal
generator as input to the board.
2.2 Software
adc.h and adc.c
The first file, adc.h, contains function prototypes for three functions. You will be responsible for writing the definitions for these functions in the other file, adc.c (rename
adc template.c). As with Lab 2, place the adc.h file in the include directory and your
completed adc.c file in the lib directory.
lab3o.c
When using an A/D converter to sample an analog signal for an embedded control application,
it is almost always important that the samples be taken at a specified fixed interval. Variations
EECS 461: Embedded Control Systems
Lab 3 Analog-To-Digital Conversion
in sample time are referred to as timing jitter, and are usually undesirable. To achieve fixed
interval sampling, the program lab3o.c allows you to sample the output of a signal generator
at a 50kHz sampling rate. The sample values are then transferred over the serial port to the
lab station desktop so that they may be displayed on a Matlab based virtual oscilloscope.
To achieve the desired sampling frequency, the A/D conversions are performed in a periodic
interrupt routine that executes every 0.02 msec. We have not yet learned how to use the
interrupt timers on the S32K144, and thus this file is provided to you directly and you don’t
need to make any modifications. Place lab3o.c in the lab3o directory.
virtual oscilloscope.slx
This file is a virtual oscilloscope program built in Simulink. As described in the discussion
of lab3o.c, the data used by the oscilloscope is collected by the ADC at a 50kHz sampling
rate. When executed, the virtual oscilloscope sampled date plotted in the time domain. The
other plot is a frequency domain FFT of the data, which is useful for observing the frequency
content of the data sequence from the serial port. We shall use the virtual oscilloscope to plot
the data collected at a 50kHz sampling rate using lab3o.c for sine wave outputs of various
frequencies. You will observe the e↵ects of aliasing and imperfect reconstruction in both the
frequency and time domains. See example plots in Figure 3.
Figure 3: Output of Virtual Oscilloscope Simulink Model: time samples and FFT of a 1 kHz sine wave.
EECS 461: Embedded Control Systems
Lab 3 Analog-To-Digital Conversion
3 Pre-Lab Assignment
Pre-Lab questions must be done individually and a .pdf copy must be uploaded before the due date and
time specified on Canvas. PLEASE INDICATE YOUR ANSWERS CLEARLY. Note that you will need
refer to your Pre-Lab solutions while you are working in the lab. You must also, with your partner,
design an initial version of your software before you come to your lab section. Your software does not
need to be completely debugged, but obviously more debugging before coming to lab means less time you
will spend in the lab.
Within the file adc.c, there are three functions to be completed: init ADC0 single, ADC0 complete,
and read ADC0 single. The prototypes of these functions can be found in the adc.h file and you should
modify the code provided in adc template.c.
1. void init ADC0 single(void): There are several registers that need to be set to initialize the
ADC0 module. These are the Peripheral Clock Controller (PCC) register, the Status and Control
Registers SC1[0], SC2, and SC3, the the configurations registers CFG1 and CFG2.