Informe 4 Eng
Informe 4 Eng
LABORATORY 4
March 24
Jhoselin Adelaida Fernandez Chura
[email protected]
Summary – In this lab, we learned to connect two devices using the Each ADC module provides eight digital comparators.
UART communication protocol. For the first part, we connected
the TIVA and displayed the data by PuTTY. For the second part, The following table lists the external signals of the ADC
we connected the Raspberry Pi4 to the TIVA and sent data from a module and describes the function of each.
potentiometer by ADC, led and motor by PWM, and an ultrasonic
sensor by GPIO.
The AINx signals are analog functions for some GPIO signals.
The column in the table below titled
Keywords- ADC, Emitter, serial import, Transmitter, UART. "Pin Mux/Pin Assignment" lists the GPIO pin placement for the
ADC signals. [2]
I. INTRODUCTION
1.2 UART
1.1 ADC
An Analog to Digital Converter (ADC) is a very useful feature
that converts an analog voltage on a pin to a digital number. By
converting from the analog world to the digital world, we can
begin to use electronics to interface to the analog world around
us.
One of the most common technique uses the analog voltage to
charge up an internal capacitor and then measure the time it Fig. 2. This is UART communication that works by transmitting each binary
takes to discharge across an internal resistor. bit of the transmitted data bit by bit.
The microcontroller monitors the number of clock cycles that Universal Asynchronous Receiver/Transmitter, usually
pass before the capacitor is discharged. This number of cycles call UART, is a serial, asynchronous, full-duplex
is the number that is returned once the ADC is complete. communication protocol that is widely used in the embedded
[1] field.
A UART channel has two data lines. There is an RX pin and a
TIVA TX pin on each device (RX for receive and TX for transmit).
Each device’s RX pin is connected to the other device’s TX pin.
There are no shared clock lines.
Fig. 3. This is the data communication format with a start, data, parity and stop
bit.
1.4 UART
GPIO stands for General Purpose Input/Output. It’s a standard
interface used to connect microcontrollers to other electronic
devices. A GPIO is a signal pin on an integrated circuit or board
that can be used to perform digital input or output functions
Fig. 8. The image shows the configuration of ADC0, channel 19 and the logic
of the code, where the potentiometer reading by ADC is displayed and how
these readings are sent by UART.
Fig. 6. The picture shows the reading of the ACM0 port and the conversion of For this exercise, the TIVA portion is identical to the previous
the value read by the UART to show a Duty Cycle value from 0 to 100.
one, as the main difference lies in the object being controlled -
a DC motor, in this case.
On Tivaware
Regarding the Raspberry Pi part, the first step is to import
To begin the TIVA part of this exercise, the first step is to import
'pySerial' to enable the motor to be read. The 'ACM0' port is
the necessary libraries, which include 'uart. h', 'uartstdio. c', and
then enabled at a 9600 baud. GPIO pins 24 and 23 are defined
'adc. h'. Following this, the UART0, GPIOA, ADC0, GPIOK,
as 'in1' and 'in2', respectively, while pin 12 is designated as
GPION, and GPIOF ports are enabled. Port A is configured with
'enable'.
PA0 designated as the receiver and PA1 as the transmitter.
The 'BCM' mode is utilized, and the motor's direction of
Subsequently, the ADC0 is configured, with channel 19 being
rotation is set using 'GPIO.output' on 'in1' and 'in2'.
assigned. Finally, a character variable 'adc_value' is created. In
the program's logic to store the potentiometer reading value it
Similar to the previous exercise, the DC motor input is assigned
used the help of the 'itoa' function, this value is sent using
to 'enable', and the working mode is defined based on the GPIO
'UARTprintf' to the Raspberry Pi.
numbering. PWM is used to create an object on 'enable' to
govern the PWM modulation with a cycle frequency of 1000.
The duty cycle is then set to start at 0.
In the logical portion, the value obtained from the UART is read
and converted to an integer representing the potentiometer's
value.
Fig. 7. The image shows the enablement of the UART, ADC and GPIO ports.
4
On Raspberry Pi
The first step was to import the pySerial library to read the
ACM0 port. Following that, ports 18 and 24 were designated as
the trigger and echo, respectively, and were assigned input and
output values.
Fig. 9 The image shows the port assignment for in1, in2 and enable. In
addition to the sense of the engine and the creation of the object in enable
Fig. 11. In the image can be observed the import of libraries and the
designation of ports for trigger and echo.
Fig. 10. In the image it can be seen the value read by UART with readline, the
conversion of that string to int and the conditionals to give power to the motor
according to the values of the potentiometer.
Exercise 4.
Detect the distance of an object using the HC-SR04 ultrasonic
sensor in Raspberry Pi. Then send the value of the distance to
the Tiva with serial communication using UART. Finally follow
the next instructions:
• If the value of distance is above 10 cm, turn of all the user
LEDs in the TIVA.
• If the value of distance is between 10 – 8 cm, turn on the user
LED PN1.
• If the value of distance is between 8 – 6 cm, turn on the user Fig. 12. In the image you can observed the data collection of the initial and
LEDs PN1 and PN0. final pulse in order to find the duration, and with this to find the distance that
• If the value of distance is between 6 – 4 cm, turn on the user is sent by UART to the TIVA.
LEDs PN1, PN0 and PF4. • If the value of distance is below 4
cm, turn on all the user LEDs in the TIVA. On TIVA
For this second part, the libraries uart.h and uartstdio.c were
imported. Then, the uart ports, UART0 and GPIOA, were
5
enabled for the GPION LEDs and GPIO F. PA0 was configured the potentiometer, led, motor and ultrasonic sensor. This
as a receiver and PA1 as a transmitter. exercise allowed us to gain a deeper understanding of how the
UART protocol works and how it can be utilized in real-world
In the logic part, UARTgets was used to receive the distance applications. In addition, an error was observed in the ultrsonic
values from the ultrasonic sensor on the Raspberry. Using the sensor, since it could not measure at less than 4cm.
atoi function, we converted the distance data into integers and
with a series of "if" conditionals, we determined the state of the IV. REFERENCES
LEDs according to the distance. If the distance was greater than
10cm, between 8 and 10cm, between 6 and 8cm, between 4 and [1] N. Seidle. (2019, November 15). Analog to Digital Conversion. [Online].
Available: https://learn.sparkfun.com/tutorials/analog-to-digital-conversion/all
6cm, or less than 5cm, the appropriate LED state was set.
[2] TEXAS INSTRUMENTS. (2014.), Tiva™ TM4C1294NCPDT
Microcontroller, [Online]. Available:
https://www.ti.com/lit/ds/symlink/tm4c1294ncpdt.pdf?ts=1679643036331
[3] Kelvin. (2022, September 8). UART Communication Protocol and How It
Works. [Online]. Available:
https://www.seeedstudio.com/blog/2022/09/08/uart-communication-protocol
and-how-it-works/
V. ANNEXES
https://drive.google.com/drive/folders/1afugLO-
fdZfIkHfdjgUvtiTUeVHefv_B
Fig. 13 In this image it can see the import of libraries and port enablement.
Fig. 14. This image shows the reading of the distance value taken by UART
from the Raspberry and the conditionals that determined all the states of the
LEDs.
III. CONCLUSIONS