Starting from:
$30

$24

Lab 2 A/D Converter Solution




This circuit connects a variable voltage to an ADC port on the ARM M0 MCU (Micro Controller Unit). Your software running on the ARM M0 MCU will read the digital value and display the percent and raw value of the voltage, VA.




The interface consists of some analog circuitry, wiring the circuit to the Nuvoton board, and running corresponding software on the ARM M0 MCU.







Figure 1: Input to an A/D converter




Voltage is measured at the output of the Potentiometer (VA). VCC and GND can be obtained from ports on the Nuvoton Nu-LB-NUC140 development board (Nuvoton).




A. Background:




A potentiometer can set a variable that is processed and used by the microprocessor. Typical applications include having the potentiometer represent a volume or level of ambient light, although a potentiometer can set just about any reference signal.




There are two basic styles of potentiometers: audio and linear. Audio potentiometers vary logarithmically as the sense of hearing is logarithmic. Recall, the definition of decibels is: ratio dB = 10 log10(ratio). This lab uses a linear single turn potentiometer.




The potentiometer in Figure 1 is part of an external circuit that provides an input signal to the Nuvoton. The NUC140VE3CN has an eight channel A/D converter connected to Port A on the Nu-LB-NUC140 development board.




B. ADC on the NUC140VE3CN:

The ADC on the M0 chip is a 12-bit A/D converter with an analog input voltage range of 0 to




Vref. For the Nuvoton board Vref is set at 3.3V. There are up to 8 single-end analog input channels and 4 pairs of differential analog input channels for compare functions. The maximum




conversion rate is 600 KHz and the maximum operating frequency is 16MHz. There are three operation modes: single mode, single-cycle mode, and continuous scan mode. The A/D







conversion can be triggered externally or by software. Conversion results are held in dedicated data registers for each channel with valid and overrun indicators. The ADC on the M0 chip is equipped with a digital compare function that can be used to monitor conversion results. Channel 7 on the NUC140VE3CN has 3 possible input sources, an external analog voltage (what we are doing in this lab), the internal bandgap voltage and the output of the temperature sensor on the Nuvoton board. The ADC also has a self-calibration function to minimize the conversion error.













Figure 2: Pin locations for Lab 2




In this lab you will create a program to use the A/D converter to sample and derive a digital value from the A/D port. Your first program should use the single mode operation and the second program use the continuous scan mode operation. In your report discuss the difference in performance, if any. Also compare the results if you include the self-calibration function vs. no calibration.







Pre-lab Assignments:



Familiarize yourself with the Technical Reference Manual, User Manual, schematics, and the Driver Reference Guide sections that discuss the ADC.



Complete the Pre-lab Questions.






Note: Each student must conduct the labs by themselves. You are not allowed to copy codes/content or to pair-up with other students to complete the labs. Each student must demonstrate individual tasks (after completion) to the professor and teaching assistant to get the full marks for the demo.







In-lab Tasks:

Construct the circuit in Figure 1 but do NOT connect VA to the GPA pin of the ADC channel you will be using.



Use lab equipment (multi-meter, oscilloscope) to verify that the potentiometer is operating correctly.



Verify the values of VA. Make sure VA does not exceed the specifications for the input port of the ADC. Also, record max and min measured VA values.



Connect the circuit, i.e. the GPA pin of the ADC channel you are using. Ensure your program includes the LCD display as a peripheral.



Write a C-routine to read an A/D port and display its value on the LCD. Display the value as a percentage, a floating-point voltage, and the raw digital value read from the A/D port. You will need to make a design decision as to how often and under what conditions your program displays the A/D values.



You have to write two programs for the ADC: first using the single mode operation and second using the continuous scan mode operation.



Implement a heartbeat signal using an interrupt service routine (ISR) and one of the RGB LEDs.



Include noise elimination in your code.



Test the boundary conditions of the Circuit. That is, make sure that the display is correct both when the potentiometer is turned completely off and completely on.



Create a table that records your results from the LCD Display and the multi-meter/ oscilloscope. See Figure 3.



Graph the results from your data table. The graph should be the input voltage (as measured) vs. ADC output voltage. Use linear regression to produce a best-fit line through the data points. It is OK to use software to do the linear regression analysis. Include this in your lab report.



Demonstrate all of the above designs/codes (working models) to your professor and teaching assistant.



Parts List:
The items on this list will NOT be repeated in the lab write-up but they are necessary for all labs.




A linear potentiometer
Connector wires.
USB to micro USB cable for programming



Deliverables:



To sign-off: Demonstrate to your professor and teaching assistant how the output display varies as the potentiometer varies. ALL the programs should have a heartbeat LED.



Lab Write-up: Follow the Lab Report Format as well as the rubric for Lab2. The report should include:



Introduction including a summary of the lab tasks.



In-Lab tasks, problems encountered, your solutions, including hardware and software.



Include the explanation of how you characterized the device, and your analysis of the values found. Discuss the difference in performance, if any, between the single mode and the continuous scan mode operations. Also









Table 1 and the Graph of your data as the potentiometer was varied.
Discussion and conclusion



Program/code listing for each task, including the programs for single mode operation and continuous scan mode operation.



NOTE: All the lab reports should be typed and turned in as a hard copy on time (check the syllabus for the due date), and a soft copy should be forwarded to the Teaching Assistant: Srikanth Ramadurgam on the due date and time.













Table 1: Voltage and Percentage of Full




Scale




Voltage Measured
Display Voltage
Digital Value
Percentage of Full
Value at Point VA




Scale








0.00 V
0.00 V
0x000
0%








0.50 V
0.50 V
0x068
10%








--
--
--
--








--
--
--
--








--
--
--
--








--
--
--
--








--
--
--
--








--
--
--
--








--
--
--
--








--
--
--
--








3.3 V
3.30 V
0xFFE
99.97%




















Figure 3: Table 1



















5. Pre-Lab Questions for Lab 2:

Name:___________________________







10 points total. Be sure to include units, as appropriate, with your answers.




What is the range of an n-bit A/D converter?















What is the range of the NUC140VE3CN converter, what is the resolution if the full-scale input range is 5V?
























Briefly describe the three operating modes of the ADC in the NUC140VE3CN. Use diagrams if necessary. Briefly describe the input modes




































What are the possible inputs for Channel 7 of the ADC and how do you select them



























How are the results accessed, what additional information is provided?























More products