关于后端:EECS-461模拟转换数字算法

6次阅读

共计 8037 个字符,预计需要花费 21 分钟才能阅读完成。

EECS 461 Fall 2023Lab 3: Analog-To-Digital Conversion

1 Overview

In this lab you will learn how to use the analog to digitalconverters on the NXP S32K144 microcontroller.You will then sample a sine wave produced by the signal generator and display the result on a virtualoscilloscope to study the phenomenon of aliasing. See Chapter42 in the S32K144 Reference Manual:“Analog-to-Digital Converter (ADC).”A block diagram of the ADC isfound in Figure 1.Figure 1: Block diagram of the ADC module.EECS 461: Embedded Control Systems 1 Fall 2023Lab 3 Analog-To-Digital Conversion ANin
Potentiometer(Turning Knob)PotJump (Connector)Figure 2: Pin connection matrix between external signals and S32K144microcontroller.

1.1 Analog-To-Digital Converter Module

The S32K144 contains two successive approximation register (SAR) A-D converter modules, referred toas 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 totriggerconversions; we shall only usesoftware triggered conversionsin Lab 3. The ADC also has single and continuous conversion modes; weshall only use single mode conversions.
The clock for the S32K144 ADC uses an 8 MHz clock instead of the 80MHz system clock.

2 Design Specifications

2.1 Hardware

The interface board has connections to eight of the input pins from the ADC module. The connectionsare made to pins ANin0 through ANin7. Each input is connected to a four-pin header consisting of theinput signal, ground, a +5 volt reference and one unused pin.A potentiometer is mounted permanently on the interface board toprovide a variable input signal forA/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 asine wave from a signalgenerator as input to the board.

2.2 Software

adc.h and adc.cThe first file, adc.h, contains function prototypes for three functions. You will be responsible for writing thedefinitions for these functions in the other file, adc.c (renameadc template.c). As with Lab 2, place the adc.h file in the includedirectory and yourcompleted adc.c file in the lib directory.
lab3o.cWhen 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. VariationsEECS 461: Embedded Control Systems 2 Fall 2023Lab 3 Analog-To-DigitalConversionin sample time are referred to as timing jitter, and are usually undesirable. To achieve fixedinterval 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 overthe serial port to thelab 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 periodicinterrupt routine that executes every 0.02 msec. We have not yet learned how to use theinterrupt timers on the S32K144, and thus this file is provided to you directly and you don’tneed to make any modifications. Place lab3o.c in the lab3o directory.virtual oscilloscope.slxThis file is a virtual oscilloscope program built inSimulink. As described in the discussionof 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. Theother plot is a frequency domain FFT of the data, which is useful for observing the frequencycontent of the data sequence from the serial port. We shall use the virtual oscilloscope to plotthe data collected at a 50kHz sampling rate using lab3o.c for sine wave outputs of variousfrequencies. You will observe the e↵ects of aliasing and imperfect reconstruction in both thefrequency and time domains. See example plots in Figure 3.Figure 3: Output of Virtual Oscilloscope Simulink Model: time samples and FFT of a 1 kHzsine wave.EECS 461: Embedded Control Systems 3 Fall 2023Lab 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 andtime specified on Canvas. PLEASE INDICATE YOUR ANSWERS CLEARLY. Note that you will needrefer to your Pre-Lab solutions while you are working in the lab. Youmust also, with your partner,design an initial version of your software before you come to your lab section. Your software does notneed to be completely debugged, but obviously more debugging beforecoming to lab means less time youwill 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 foundin the adc.h file and you shouldmodify 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 0x1Fto disable the ADC0 module for configuration (the disable setting in Section 42.4.2 is notapplicable to the S32K144 processor). To enable a conversion, set ADCH to the The AIEN bitfield enables an interrupt when a conversion is completed; we do not use thisfeature.
• CFG1 (Section 42.4.3): The MODE bitfield is set to specify the resolution of the ADC – use theull 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 acquirean 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 bitfieldsto 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 withapproximate 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 thesampled 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 thehandout (i.e., which of Figures 1-4) corresponds to the result you should see? Note:there is a 1-1 correspondence between

4 In-Lab Assignment

In the Post-Lab Assignment, you will be asked to consult the S32K144 reference manual and computeTconv, 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, beforethe call to the read ADC0 singlefunction, one of the LEDs is set to high and is set back to low after the function returns. Connect anoscilloscope 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.In this section of the lab, we read a sine wave output from a signal generator and display the result onthe oscilloscope. Because we can only output a digital signal, we cannot display the sine wave directlyin this way; instead, we convert the sine wave into a square wave. To do so, change your lab3.c file sothat when the‘ANin0’input measured in read ADC0 single is greater than approximately half of themaximum value for the A/D conversion a digital output is set to output high. Otherwise, the digitaloutput will output low. Connect a function generator to the‘ANin0’signal pin and generate a sine wavewith parameters 0-5 V, 2.5 V o↵set, 5 Vpp, and 3 kHz. Use an oscilloscope to observe both theinputsignal and the output signal. Use the stop and run features on the oscilloscope to freeze the waveform ifnecessary.As in Section 4.2, measure the amount of time Ts between successive oLab 3 Analog-To-Digital ConversionReferences[1] J. S. Freudenberg,“Sampling, Beats, and the Software Oscilloscope”available from the EECS 461Canvas website.EECS 461: Embedded Control Systems 7 Fall 2023

正文完
 0