Skip to main content
留学咨询

辅导案例-CMPEN 472

By May 15, 2020No Comments

4/13/2020 CMPEN 472 Homework 10, The Pennsylvania State University www.cse.psu.edu/~kxc104/class/cmpen472/20s/hw/hw10/hw10.html 1/4 CMPEN 472, The Pennsylvania State University Homework 10: Analog Signal Acquisition with HCS12 Due: April 18, 2020 11:30pm Objective To learn timer module and interrupt based Analog Signal Acquisition programming. Textbook Reading (for next homework): 1. MC9S12C Family Data Sheet: Chapters 5, 8, 13, and 15 Instruction 1. Write a program to aquire analog signal through the HCS12 board and display the analog signal on a PC screen. 2. The program steps are as follows: 1. Initialize 2. Your program starts from ASCII monitor command ‘go 3100’ 3. Your program prints the message on the HyperTerminal ‘Baud rate changed! Please reopen the HyperTerminal with 115.2Kbaud’ 4. Change the SCI port baud rate from 9600 to 115.2Kbaud. 5. Wait for the first RETURN key hit on the SCI port 6. Print the message ‘Please connect the audio cable to HCS12 board’ on the new HyperTerminal (115.2kbaud) if the RETURN key was hit 7. Non-RETURN key hits are ignored 8. Also print the ‘Well>’ prompt on a new line 9. Wait for the RETURN key hit again on the SCI port 10. Non-RETURN key hits are ignored 11. Start a single Analog-to-Digital Conversion (ADC) of the signal on the AN7 pin and display the 8 bit result on the HyperTerminal if the RETURN key was hit. 12. You may check the result at this time: if the audio cable is correctly connected, the result display is between 123($7B) to 133($85). If the audio cable is not connected or incorrectly connected, the result display is between 0($00) to 32($20). 13. Also print the ‘Well>’ prompt on a new line 14. Wait for the RETURN key hit again on the SCI port 15. Non-RETURN key hits are ignored 16. Start a single Analog-to-Digital conversion of the signal on the AN7 pin and display the 8 bit result on the HyperTerminal if the RETURN key was hit. 17. Also print the ‘Well>’ prompt on a new line 18. The subsequent RETURN key hits, the last two steps are repeated. 19. If the RETURN key hit (then the ADC result display) was followed by the ‘a’ key hit, Print the following messages: 1. ‘Please disconnect the HyperTerminal’ 2. ‘Start NCH Tone Generator program’ 3. ‘Start SB Data Receive program’ 4. ‘Then press the switch SW1, for 1024 point analog to digital conversions’ 20. Wait for the Switch SW1 pressing 21. Start the Timer Module Channel 2 Output Compare interrupt generation at every 125usec (8KHz rate). Each time the Output Compare interrupt occurs, carry out the 4/13/2020 CMPEN 472 Homework 10, The Pennsylvania State University www.cse.psu.edu/~kxc104/class/cmpen472/20s/hw/hw10/hw10.html 2/4 following tasks: 1. Service the Output Compare (OC) register (update the counter compare number) for the next interrupt. Also clear the OC interrupt flag (if you selected the Fast Flag Clear option, updating the timer OC register for the next interrupt will also clear the interrupt flag). 2. Pick up the ADC result (from previous conversion) and transmit it to SCI port. Only the upper 8bit of the ADC result should be picked up and 1 byte of pure binary number should be transmitted (do NOT convert to ASCII). 3. Increment the transmit byte counter 4. Start a single Analog-to-Digital conversion of the signal on the AN7 pin 22. Wait for the transmit byte count to be 1030 23. Then repeat the last 3 steps, begining with Switch SW1 press waiting. 3. Copy the HW10 sample program 1, hw10samp1e.asm file. Study it, assemble it, debug it, and run it on the HCS12 board. This program use Timer channel 2 Output Compare interrupt generation of 125usec for the count down timer. You may use some parts of this program. (For simulator only, click here for the HW10 sample program 1, hw10samp1eSim.asm file.) 4. For the CodeWarrior Debugger/Simulation, please follow the updated Full Chip Simulator guide. 5. Copy the HW10 sample program 2, hw10samp2c.asm file. Study it, assemble it, debug it, and run it on the HCS12 board. This program shows how to change the serial port (SCI port) baud rate and transmit 1030 bytes of data with Switch 1 (SW1) press. It also shows how to receive the data on the host PC side. You may use some parts of this program. (For simulator only, click here for the HW10 sample program 2, hw10samp2cSim.asm file.) 6. Copy the HW10 sample program 3, hw10samp3b.asm file. Study it, assemble it, debug it, and run it on the HCS12 board. This program converts analog signal to digital data and transmits it in ASCII characters. This program is used to test the cable connections and ADC operation. You may use some parts of this program. (For simulator only, click here for the HW10 sample program 3, hw10samp3bSim.asm file. Also you will need to save the following two files [right click and select ‘Save Link As…’ option] to your project folder for simulating ADC: ADCcon7.cmd and WAVEsn10.cmw files. Please follow the Additional Simulation Guide to connect the ADC input pin to a signal generator.) 7. Additional comments on your final HW10 sample program are as follows: 1. The HW10 program must send the raw 8bit binary number (without ASCII conversion). 2. The sample program 3 use busy ADC wait for ADC completion, your HW10 program must use the Timer Module Channel 2 Output Compare interrupt every 125usec for each ADC completion. 3. Your HW10 program must do one ADC conversion at the rate of exactly 8KHz, 125usec a part. 4. The sample program 3 may converts ADC input channel 5 signal, your HW10 program must convert ADC input channel 7 signal. 5. The sample program 3 does one conversion per return key hit, your HW10 program must do 1024 (or 1030) conversions per each Push Button SW1 press. 6. The sample program 3 does ADC conversions with a return key hit, your HW10 program must do the ADC conversions with the Push Button Switch 1 press. 8. HCS12C128 board audio cable connection: 1. Connect RED wire to 5V, to pin 1 (of the 60pin connector J1). 4/13/2020 CMPEN 472 Homework 10, The Pennsylvania State University www.cse.psu.edu/~kxc104/class/cmpen472/20s/hw/hw10/hw10.html 3/4 2. Connect SILVER wire (or uninsulated copper wire) to GROUND, to pin 3. 3. Pin numbers are printed on the board: ‘2’, ’10’, ’20’, ’30’, etc. 4. Connect WHITE wire to AN7, to pin 10. 5. Connect the audio plug to speaker/ear phone jack (green) of your PC 9. Read the HCS12 board user Guide. HCS12 Users Guide, Schematic, Push Button Switch 1, etc. 10. Note that the Push Button Switch 1 is connected to the port P bit 0 in HCS12C128 board 11. To generate audio sound of sine wave and other waves on your Windows PC, go to Online Tone Generator page. For multiple frequency sounds, you may have the page open multiple times on your web browser. Multiple sounds are mixed then. Another way to generate audio sound of sine wave is that you download FREE SineGen 2.5/2.1 program from SineGen 2.5/2.1 page. Unzip the file on your PC and run SineGen.exe file to generate tone signal wave. You may run SineGen.exe file multiple instances to mix multiple frequency signals. 12. Copy the SBDRx3.zip file. It is a C++ program designed to run on your PC, connecting to COM port. It will ask your COM port number: 1, 2, 3, … 9 at the start. The program will receive 1026 bytes of raw data through COM port and save them into a text file for later processing. 1. Unzip SBDRx3.zip file into an empty folder. 2. Find the file SBDRx.exe and you can run it by double clicking it. 3. Or you may find the .cpp files and .h files, study them. 4. You may change the program and recompile it if you fix COM3 or COM5 port, or if you want the longer data lenth than 1024. 13. Your PC can run Hyper Terminal or SB Data Receiver (SBDR) program but not both at the same time!!! To run SBDR program, you must quit Hyper Terminal. To run Hyper Terminal, you must quit SBDR program. They both use the COM port of your PC, they can NOT be running at the same time. 14. Download SciLab Program from SciLab Home page. This program allows your PC to read and plot data. 15. While the SBDRx program is running, press the Push Button switch SW1. The SBDRx program will receive data bytes coming thro
ugh COM port of your PC. It will save 1024 data points received into the ‘RxData3.txt’ text file. You can view the ‘RxData3.txt’ file with Notepad or Wordpad program in your PC. 16. Once the ‘RxData3.txt’ file is created, run SciLab program. Then have the SciLab program read the data from the ‘RxData3.txt’ file and plot the data on a plot window. 17. For a sample SciLab commands for plotting data, copy the SciLabCOM.txt file. It shows the list of SciLab commands, you can view or edit with any text editor or SciLab. You can also run it (same as MATLAB .m file) in SciLab if you change the file name to ‘SciLabCOM.sce’ 18. Check the plot and verify the signal frequency. Use magnify feature to see the signal wave details. Identify one cycle of signal wave, check how many points are plotted. (for plotting, one may also use MS Excel) You may need to increase or decrease the audio signal volume to make the signal magnitude swing more than 60. That is, signal should be centered about 128 and goes to highest above 160 and goes to lowest below 100. 19. You can aquire another set of 1024 point ADC data as follows: 4/13/2020 CMPEN 472 Homework 10, The Pennsylvania State University www.cse.psu.edu/~kxc104/class/cmpen472/20s/hw/hw10/hw10.html 4/4 1. Close the SBDRx program (if not already closed) by moving the cursor on its window and hit ‘Ctrl’ and ‘C’ keys together. 2. Run the SBDRx program again (double click). 3. Press the switch SW1. 4. New set of data will be recorded into the ‘RxData3.txt’ file. 20. Change the tone frequency and wave type in NCH Tone program (Online Tone Generator, SineGen program, or any other audio tone generator) and repeat the data acquisition and plotting. 21. Write a report of your experiments. Your report must include: 1. Cover sheet with course and your information. 2. 440Hz Sign wave plots. 3. 1000Hz square wave plots. 4. 440Hz triangle wave plots. 5. Mixed 440Hz and 550Hz sign wave plots. 6. For each signal wave, plot full 1024pts and plot magnified 2 signal cycles. Note the signal shape difference among square, sign, triangle, and mixed waves. Identify one cycle of signal wave, and verify correct signal frequency by counting how many points are plotted in one cycle. 7. Run FFT on the mixed 440Hz and 550Hz sign wave data and plot the FFT result for an extra credit. You may use SciLab FFT command. You should expect two peaks, at 440 and 550. (You may also need to make the wave centered at 0 instead of 128 for FFT.) 8. Detailed explanation of each plot and operations. 22. Create your report in MS Word (.doc file). You can capture any window on the screen by pressing ‘Alt’ and ‘Print Screen’ keys together. Once captured, you can paste the window picture into the .doc file by pressing ‘Ctrl’ and ‘v’ keys together. 23. You will be sending both the report .doc file and program main.asm files for this homework. 24. Make your program user friendly by giving directions as to how to correctly use your program. Once your program is running, everything must be self explanatory to user at the Hyper Terminal. 25. Also, make your program ‘fool-proof’, never crash or stop based on wrong user response. 26. Design the program to start at $3100 and data to start at $3000. 27. Be sure to put much comments so that grader and others can clearly and quickly understand your program. Comments are very important in assembly language programs. 28. Copy your ‘main.asm’ file to ‘cmpen472hw10_YourLastName.asm’. For example, mine will be ‘cmpen472hw10_choi.asm’ Do not ZIP your ‘cmpen472hw10_YourLastName.asm’ file. 29. Name your Homework 10 report file to ‘cmpen472hw10_YourLastName_RPT.doc’. For example, mine will be ‘cmpen472hw10_choi_RPT.doc’ Do not ZIP your ‘cmpen472hw10_YourLastName_RPT.doc’ file. 30. Turn-in your project source code file through Penn State CANVAS. Upload your source code file into the CANVAS Assignment’s Homework submission. Be sure to select CMPEN 472 class and correct Homework number, and with correct file name. Congratulations on your 10th CMPEN 472 homework completion!

admin

Author admin

More posts by admin