Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ITU Control & Automation Eng. Dept. KON 3 0 9 E Microcontroller Systems Experiment 4 : ADC and USART Construct the circuit as shown in

ITU Control & Automation Eng. Dept.
KON309E Microcontroller Systems
Experiment 4: ADC and USART
Construct the circuit as shown in the Figure.
Check your wiring and make sure that
no connection is made to the 5V supply.
The ADC peripheral should be configured to
sample CH0 and CH1 using Sequence A.
The serial port USART0 should be configured
for a baud rate of 38400 and as a serial
terminal.
Write a program that will do the following
in the main loop:
1. Prints out a message such as: "Press a key to start conversion."
2. Starts the ADC Sequence A when a key is pressed from the PC keyboard
3. Waits until one conversion on Sequence A is complete.
4. Converts the results to voltages on the two channels using the reference
voltage of 3V3.(Determine the resolution of the ADC by consulting the reference
manual. Use an int16_t, and represent the voltage in millivolts, as the terminal
program cannot print floating point numbers.)
5. Prints out the result of the conversion in the format :
"ADC0=xxxx mV, ADC1=yyyy mV"
6. Repeat.
Remember that the terminal program in the PC must also be set to the same
baud rate as Alakart. Otherwise, garbled output, or even, no output will be
seen.
Aim: Using the USART to report periodic analog voltage samples to the PC.
In this experiment, we will take sequence samples from the analog to digital
converter on two channels, and report the values back to the PC
For this experiment, you will need to consult the usual reference documents:
LPC824 user manual
LPC82x datasheet
Alakart schematic diagram
Write the code using the peripheral support libraries (Xpressso SDK) or direct
register programming or a combination of both.
PART I
Write in your report:
What values must be written to which registers so that ADC Sequence A
can be configured to sample CH0 and CH1.
How the serial port is set to 38400 Baud.
The frequencies of "main clock" and "system clock" by checking the
configuration functions. Write which functions you check and how you find
the result.
Store the code for this part in a folder named "EX4_PART1".
In PART I, we built an analog to digital converter that samples Sequence A once
when a key is pressed on your keyboard. In PART II, we will make the sampling
triggered by the SCT0 timer peripheral, in hardware and get the result using an
INT. This is typically how it is implemented in consumer products.
Keep the same circuit as in PART I but add a LED to a suitable PIO0 pin with a
resistor. This time the following peripherals must be set:
ADC as in PART I with "Sequence A" set to sample ADC0 and ADC1.
However, the ADC must be configured to be triggered from SCT0, OUT 3
Serial port USART0 terminal as in PART I, but with Baud rate 57600 Baud.
SCT0 set as an event generator and its output 3 changes at end of count
event. The duration of SCT0 must be calculated and set so that the ADC is
triggered every 500ms. Remember that system clock is configured to
24MHz in the projects provided with the serial port examples and not
30MHz.
"ADC conversion complete" INT is enabled and configured.
PIO0 is configured such that the pin where the LED is connected is an
output and the LED is turned OFF.
Write a program that will do the following:
1.ADC Sequence A is triggered for conversion by the SCT0 timer every
500ms (for 2 conversion sequences / second).
2.At the completion of the ADC sequence, an end of conversion INT is
triggered.
3.Within the ISR: ADC results are stored in a structure, a global volatile
variable is set to True and the LED is toggled.
4.Within the main loop of the program: The global variable is repetitively
queried (checked) to see if it has been set to True by the ISR. If it has been
set to True, then: The ADC results are converted to actual voltages in mV,
PART II
and printed in the same format as in PART I, and (very important!:) the
global variable is set back to False.
As a result, when the program is ran, we should see the LED flashing at 1s, and
the result of the conversion appears on the screen in millivots every 500ms.
Note that the conversion result is retrieved from the ADC within the ISR, but it is
printed out in the main loop. The ISR must signal the main loop that the
conversion is complete using a global variable that is called a "flag".
Use a chronometer to check that you really get the correct timing. (Time 20
blinks and make sure it is close to 20s)
Write in your report:
1. How the SCT0 is configured so that it can trigger the ADC every 500ms.
Provide the equation for the calculation by consulting the reference manual.
What values must be written to which registers?
2. Where is the INT vector defined? (Write the name of the file and copy the line
where it is defined, to your report)
3. Describe your program and show how each software function and hardware
peripheral interacts with the others.
Store the code for this part in a folder named "EX4_PART2".
This i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

Illustrate managers use of budgets in the planning process

Answered: 1 week ago