首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
EECS 461代写、代做C/C++设计编程
项目预算:
开发周期:
发布时间:
要求地区:
EECS 461 Fall 2023
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 1 Fall 2023
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 2 Fall 2023
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 3 Fall 2023
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.
• SC1[0] (Section 42.4.2): According to Table 41-2, the ADCH bitfield should be set to 0x1F
to disable the ADC0 module for configuration (the disable setting in Section 42.4.2 is not
applicable to the S32K144 processor). To enable a conversion, set ADCH to the desired channel.
The AIEN bitfield enables an interrupt when a conversion is completed; we do not use this
feature.
• CFG1 (Section 42.4.3): The MODE bitfield is set to specify the resolution of the ADC – use the
full 12-bit resolution. The ADICLK bitfield selects the ADC clock – use Alternate clock 1.
• CFG2 (Section 42.4.4): The SMPLTS bitfield selects the sample time, or time taken to acquire
an analog voltage for conversion. Use the default value of 13 ADC clock cycles.
• SC2 (Section 42.4.7): Set the ADTRG bitfield to specify software triggered conversions, and the
REFSEL bitfield to select the default reference voltages, VREFH and VREFL.
• SC3 (Section 42.4.8): Set the ADCO bitfield for single conversion mode. Set the other bitfields
to disable calibration and hardware averaging.
2. uint8 t ADC0 complete(void): This function returns the value of the COCO bit from the SC1[0]
register. The COCO bit equals 0 until the conversion is complete, when it is set to 1. Reading the
result of the ADC conversion clears the COCO bit.
3. uint32 t read ADC0 single(uint16 t inputChannel): This function does four things:
• Initiate conversion by writing the ADC channel number to the ADCH bitfield of the SC1[0]
register.
• Wait for conversion to complete.
• Read Data Result Register R[0] (Section 42.4.5).
• Convert the result to millivolts.
4. Suppose that we sample a sine wave with frequency f0 Hz in a software loop with
approximate execution time Ts seconds (and thus with sample frequency fs = 1/Ts
Hz). Assume that the frequency of the sine wave f0 is approximately (but not exactly)
equal to the sample frequency. State an expression for the apparent frequency of the
sampled sine wave. What is the approximate value of this frequency?
5. During the In-Lab, you will be asked to sample sine waves output from the signal generator in
a timed 50kHz software loop and display the results on a software oscilloscope. As described in
the handout “Sampling, Beats, and the Software Oscilloscope”, you may see a variety of di↵erent
phenomena, depending on the frequency of the sine wave with respect to the sampling frequency.
EECS 461: Embedded Control Systems 4 Fall 2023
Lab 3 Analog-To-Digital Conversion
For each of the sine wave frequencies listed below, which of the four plots in the
handout (i.e., which of Figures 1-4) corresponds to the result you should see? Note:
there is a 1-1 correspondence between Figures 1-4 and sine waves (a)-(d).
(a) f0 = 12.4 kHz;
(b) f0 = 55 kHz;
(c) f0 = 10 kHz;
(d) f0 = 24 kHz.
4 In-Lab Assignment
4.1 Single Mode Conversion Testing
1. Write a simple C program called lab3.c that uses the init ADC0 single and read ADC0 single
functions from adc.c to retrieve the value of an analog input from the potentiometer and store it
to a variable called iAnalog.
2. Run the lab3.c. Adjust the potentiometer to change the analog signal sent to the pin between 0
and 5 volts. Verify that the value of iAnalog has changed and that you can correctly read the full
voltage range.
4.2 Timing
In the Post-Lab Assignment, you will be asked to consult the S32K144 reference manual and compute
Tconv, the amount of time required for the hardware to perform one A/D conversion. We now measure
two other times of interest. Modify your lab3.c file so that, before the call to the read ADC0 single
function, one of the LEDs is set to high and is set back to low after the function returns. Connect an
oscilloscope to the GPO output pin.
1) Measure TRead, the amount of time required for one execution of the function read ADC0 single.
2) Measure TLab3, the period with which read ADC0 single is called.
Record these times for later analysis.
4.3 From Sine Wave to Square Wave
In this section of the lab, we read a sine wave output from a signal generator and display the result on
the oscilloscope. Because we can only output a digital signal, we cannot display the sine wave directly
in this way; instead, we convert the sine wave into a square wave. To do so, change your lab3.c file so
that when the ‘ANin0’ input measured in read ADC0 single is greater than approximately half of the
maximum value for the A/D conversion a digital output is set to output high. Otherwise, the digital
output will output low. Connect a function generator to the ‘ANin0’ signal pin and generate a sine wave
with parameters 0-5 V, 2.5 V o↵set, 5 Vpp, and 3 kHz. Use an oscilloscope to observe both the input
signal and the output signal. Use the stop and run features on the oscilloscope to freeze the waveform if
necessary.
As in Section 4.2, measure the amount of time Ts between successive calls to read ADC0 single, and
thus determine the frequency fs at which the sine wave is being sampled. Record these values for later
analysis. First try an input sine wave with frequency f0 much smaller (say by a factor of ten) than fs,
and record the approximate frequency of the resulting square wave. Next, try an input sine wave with
frequency f0 that is about equal to the sample frequency (say 95%), and again record the frequency of
the resulting square wave. Repeat a few times with di↵erent values until you are comfortable with the
relation between sine wave and square wave frequencies.
EECS 461: Embedded Control Systems 5 Fall 2023
Lab 3 Analog-To-Digital Conversion
4.4 The Virtual Oscilloscope
In this section of the lab, we again read sine wave output from a signal generator, and we output the
measured data over the serial port to a virtual oscilloscope program written in Simulink. To do so, use the
file lab3o.c and the Simulink model virtual oscilloscope.slx provided on the course website to plot
the data. Attach the signal generator to your interface board as shown by your instructor. Demonstrate
the working virtual oscilloscope to your instructor using a 3 KHz sinusoid. (Remember to put the signal
generator in high-Z mode). Recall that the data plotted by the virtual oscilloscope is collected by the
program lab3o.c at a 50 kHz sampling rate.
Increase the input signal frequency slowly until you see the “beat” phenomenon illustrated in Figure 3
of [1]. Record the frequency of the input signal and the resulting beat period for later analysis. Further
increase the input signal frequency until you see aliasing, as illustrated in Figure 2 of [1]. Record the
signal frequency and the resulting alias frequency for further analysis. Demonstrate to your GSI that you
can produce all four cases discussed in [1].
Save a copy of your code to hand in with the Post-Lab Assignment.
5 Post-Lab Assignment
1. According to Section 42.5.4.5 of the S32K144 Reference Manual, the time Tconversion required to
perform one A-D conversion consists of (i) the time Tsample required to sample the analog signal;
(ii) the time Tcompare required to set all 12 of the converted bits; and (iii) some additional overhead
time. Given that the ADC clock TADC is set to 0.125 µsec (fADC = 8 MHz) and the bus clock is
set to TBUS = 0.025µsec (fBUS =40 MHz), what are the values of (i) Tsample, (ii) Tcompare, and
Tconversion? Express your answer in µseconds.
2. In Section 4.2, you measured TRead, the amount of time required for one execution of read ADC0 single,
and TLab3, the period with which read ADC0 single is called. What values did you get for
TRead and TLab3? Recall that Tconversion is the amount of time required to perform one
conversion. Why is TRead greater than Tconversion? Why is TLab3 greater than TRead?
Assume e↵ects due to hardware inaccuracies are negligible. Limit your complete response to less
than 5 sentences.
3. For In-Lab part 4.3, what values did you record for the loop sample time and frequency?
For the low frequency input case, what value of input sine wave frequency did you use,
and what was the frequency of the resulting square wave? For the case fs ⇡ f0, what
values of input sine wave frequency and output square wave frequency did you record?
Verify that these values are consistent with your answer to question 4 of the Pre-Lab.
4. When you used the virtual oscilloscope in Section 4.4, you recorded signal frequencies that resulted
in aliasing, and in beats, as depicted in Figures 2 and 3 of [1].
(a) What was the frequency f0 of the sine wave from the signal generator that resulted
in aliasing? What was the frequency fA of the resulting alias? Verify that these
signals di↵er by an integer multiple of the sampling frequency by finding that
value of k for which f0 kfs = ±fA.
(b) What was the frequency f0 of the sine wave for which you observed periodic beats
on the virtual oscilloscope? What were the period and frequency fbeat of the
resulting beats? Verify that fbeat = 2(fN f0).
Be sure to upload a copy of your code with your solutions to the Post-Lab.
If you have comments that you feel would help improve the clarity or direction of this assignment, please
include them following your postlab solutions.
EECS 461: Embedded Control Systems 6 Fall 2023
Lab 3 Analog-To-Digital Conversion
References
[1] J. S. Freudenberg, “Sampling, Beats, and the Software Oscilloscope” available from the EECS 461
Canvas website.
EECS 461: Embedded Control Systems 7 Fall 2023
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
代做ece5550: applied kalman ...
2024-12-24
代做cp1402 assignment - netw...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!