0% found this document useful (0 votes)
11 views5 pages

Informe 4 Eng

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Informe 4 Eng

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1

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.

Start Bit: Each time a communication is initiated, the logic


signal starts at "0" because the bus is at a high level "1", when
Fig. 1. This is the table showing each ADC, its sequencers and pins in TIVA it is inactive.
Data Bit: After the start bit is the data we want to transmit. The
The TM4C1294NCPDT ADC module features 12-bit data bits can be 5, 6, 7, 8, 9 bits, etc.
conversion resolution and supports 20 input channels. Each Parity Bit: to verify the correctness of data transmission. Is
ADC module contains four programmable sequencers allowing divided in no parity, odd parity and even parity. [3]
the sampling of multiple analog input.
2

1.3 Import Serial


GPIO stands for General Purpose Input/Output. It’s a standard Finally, for the logic part of the program, we received data in
interface used to connect microcontrollers to other electronic the 'data' character variable and compared it with 'data1' and
devices. A GPIO is a signal pin on an integrated circuit or board 'data2' to determine the state of the LED.
that can be used to perform digital input or output functions

The most common functions of GPIO pins include:

• Being configurable in software to be input or output


• Being enabled or disabled
• Setting the value of a digital output
• Reading the value of a digital output
• Generating an interrupt when the input changes value
Fig. 4. In the image it can see the declarations of the comparison char variables
GPIO pins are digital, meaning they only support high/low or and those that will receive the data by UART.
on/off levels [3]

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

The most common functions of GPIO pins include:

• Being configurable in software to be input or output


• Being enabled or disabled
• Setting the value of a digital output Fig. 5. In the picture shows the configuration of the UART ports and the data
acquisition with UARTgets.
• Reading the value of a digital output
• Generating an interrupt when the input changes value Exercise 2. Send a value from Tiva to raspberry with serial
communication using UART.
GPIO pins are digital, meaning they only support high/low or In Tiva, use a potentiometer to read the values and send them
on/off levels [3] to Raspberry Pi with UART communication. After that, in
Raspberry control the PWM of a LED modifying the duty cycle
with the potentiometer values, in other words, the LED must
II. PROCEDURE change his intensity depending on the potentiometer.
Note: For this exercise the TIVA sends a value via UART and
the Raspberry Pi receive that value. Also, remember that Tiva
2.1 Part 1: Digital output in Raspberry resolution is 12 bits so the values of the potentiometer are in
Exercise 1. Using UART in the Tiva, control the behavior of the range of 0-4095.
the user LED PN1 with the following features:
• The initial state of the LED is turned off. On Raspberry Pi
• The LED must be turned on when the user sends the string For this exercise, the first step was to perform the recognition
“ON” in PuTTY. For this purpose, is needed to use UART of the potentiometer using ADC through the pySerial library.
configuration in the Tiva. To ensure that the correct port was used, the command 'ls
• When the user sends “OFF”, the LED must be turned off. /dev/tty' was utilized, and the port was verified to be ACM0.
Additionally, the board was set to operate at a baud rate of
The first step undertaken for this exercise was to import the 9600.
libraries "driverlib/uart.h" and "utils/uartstdio.c". Next, four
character variables were created, of which two were used to The LED input was assigned to pin 35, and the working mode
compare with the input received from PuTTY. The variables was defined based on the GPIO numbering. PWM was used to
'data1' represented the LED on state, and 'data2' represented create an object on pin 35 to govern the PWM modulation
the LED off state. with a cycle frequency of 1000. The duty cycle was then set to
start at 0.
Subsequently, we declared the ports N, UART0, and GPIOA,
since we will be working with them. Port A was declared, with Within the conditional 'while' loop, the value sent from the
PA0 as the receiver and PA1 as the transmitter. TIVA was read and converted to a range of 0 to 100 using a
3

formula that incorporated the 4095 bauds of the TIVA. Finally,


the duty cycle was adjusted using the '.changeDutyCycle'
function and printed.

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.

Exercise 3. Modify the previous exercise to control a DC motor


and change the duty cycle from 0 to 25%, 50%, 75% and 100%.
¿Is there any difference with the LEDcontrol?

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.

After a series of conditionals "if "that determine the PWM state


of the motor based on the potentiometer value, the motor's
power can be observed at 0% (off), 25%, 50%, 75%, and 100%
of its capacity.

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.

Within the while loop, an exception is included to clear the


values entering the GPIOs. Inside this exception, the start and
end pulses are read using the GPIO.input function.
Subsequently, the duration is calculated by subtracting both
values, and the distance is obtained using another formula.
Finally, the distance is sent to the TIVA using the ser.write
function.

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

In conclusion, this lab provided us with valuable hands-on


experience in connecting and communicating between devices
using the UART communication protocol. We were able to
successfully connect the TIVA and Raspberry Pi4, and learn
how to transfer data from various sensors and actuators such as

You might also like