Lab 4 UART Transmitter -...

23
BYU ECEn 320 Lab 4 UART Transmitter

Transcript of Lab 4 UART Transmitter -...

Page 1: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Lab 4UART Transmitter

Page 2: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

UART Transmimtter Specification

VGA

Serial

A1 Expansion Connector

PS2

A2 Expansion Connector

B1 E

xpansion C

onnectorPower

Send ASCII value on 8 toggle switches to serial port for display on screen when button 1 is pressed.

Page 3: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Top Level System Block Diagram

Clock/Reset GeneratorSwitch and Button Interface

Button Debouncer

tx_test

txTransmitter

Two Entities:

tx_test - top level file to test the transmitter

tx - The transmitter itself, which is instantiated in the body of tx_test

You will reuse the transmitter in a later lab

7 segmentdisplay ctrl

Page 4: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Transmitter Tester (tx_test)Block Diagram

tx8

data_in

tx_out

clk (50 MHz)

rsttx_busy

send_characterDebounce Circuit

button

switch(7 downto 0)

txd

clk_in

display cntrlsignals

Page 5: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Transmitter (tx) Block Diagram

FSM

ShiftRegister

BitTimer

8data_intx_out

clk

rst

clrTimertx_bit

shift

clk

rst

clk

rsttx_busy

send_character load

TransmitOut

shift_out

stopstart

Page 6: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Bit Timer

FSM

ShiftRegister

BitTimer

8data_intx_out

clk

rst

clrTimertx_bit

shift

clk

rst

clk

rsttx_busy

send_character load

TransmitOut

shift_out

stopstart

Page 7: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Bit Timer - Transmitter Clocking• Everything is clocked on same global clock

(clk)• Global clock is 50MHz• The Bit Timer controls the timing of bits

coming out of the serial port.• Bit Timer needs to create timing pulse at

rate of 19,200Hz– That is the baud rate of our serial port– Divide factor = 50,000,000/19,200 = 2604.1666…– We will use 2604 cycles/pulse

Page 8: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Transmitter Bit Timer• Bit timer can be created from a counter

– Can be cleared, otherwise increments up to 2603 and rolls over

– Signal tx_bit is asserted during the last cycle (cycle 2603 in this case)

clk

tx_bit

state

serial_out

2604 cycles

“one bit”

Page 9: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Building a Parameterizable Bit-Timer• To make our transmitter more reusable, we

will use generics for the clock rate and baud rate

generic CLK_RATE : Natural := 50_000_000;generic BAUD_RATE : Natural := 19_200;generic BIT_TIMER_WIDTH : Natural := 12;...constant BIT_TIMER_COUNT : Natural := CLK_RATE/BAUD_RATE;signal BIT_TIMER : unsigned(BIT_TIMER_WIDTH-1 downto 0);

• Use the constant BIT_TIMER_COUNT in the design of your counter to determine when to return to 0– Changes in generics will automatically result in changes to the

counter

Page 10: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Shift Register

FSM

ShiftRegister

BitTimer

8data_intx_out

clk

rst

clrTimertx_bit

shift

clk

rst

clk

rsttx_busy

send_character load

TransmitOut

shift_out

stopstart

Page 11: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Shift Register• A shift register is used to load the

“parallel” data from the switches and “shift” the data out on the serial port– The “LSB” of the shift register drives the “shift_out”

signal

• load: The shift register should load all data from the switches

• shift: The shift register should shift right

Page 12: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Transmit Out

FSM

ShiftRegister

BitTimer

8data_intx_out

clk

rst

clrTimertx_bit

shift

clk

rst

clk

rsttx_busy

send_character load

TransmitOut

shift_out

stopstart

Page 13: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Transmit Out• Additional logic is needed to make sure the

TX signal is valid and clean– Outputs a ‘0’ when start is high

– Outputs a ‘1’ when stop is high

– Outputs selected data bit from shift_out otherwise

• This signal should be registered in a flip-flop to prevent glitches before leaving the chip– The Flip-Flop will remove any transient glitches.

Page 14: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Transmitter FSM

FSM

ShiftRegister

BitTimer

8data_intx_out

clk

rst

clrTimertx_bit

shift

clk

rst

clk

rsttx_busy

send_character load

TransmitOut

shift_out

stopstart

Page 15: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Transmitter FSM• Controls the operation of all elements in the

transmitter– Controls clearing of Bit timer– Controls loading and shifting of shift register– Controls transmit out (start bit, stop bit, or shift bit)

• Inputs:– send_character: Control signal to initiate transfer– tx_bit: Indicates the end of a bit time

• Outputs:– tx_busy: Transmitter is busy (middle of transmit)– clrTimer: Clear the bit timer– load: Load switch data into shift register– shift: Shift shift register– stop: Send a stop bit– start: Send a start bit

Page 16: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Transmitter State Diagram (Transitions)

STRT

RETRN

send_character

tx_bit

send_character

tx_bit

IDLE

send_character

send_character

STP

tx_bit

tx_bit

rst

B0

tx_bit

B1

tx_bit

B2

tx_bit

B3

tx_bit

B4

tx_bit

B5

tx_bit

B6

tx_bit

B7

tx_bit

tx_bittx_bittx_bittx_bittx_bittx_bit

tx_bit tx_bit

See following two pages for a description of the states and the state machine outputs

Page 17: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Transmitter FSM States• IDLE: Waiting for signal to start transmit• STRT: Issue start bit• B0-B7: Send a bit (B0 = send bit 0, etc.)• STP: Send stop bit• RETRN: Wait for “send_character” to clear

Page 18: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Transmitter FSM Outputs• tx_busy:

– true when not in IDLE state• load:

– Occurs on transition from IDLE state to STRT state– STATE = IDLE and (send_character = ‘1’)

• shift:– Occurs on each transition between Bx and Bx+1– tx_bit = ‘1’ and (STATE = B0 or STATE = B1 . . . or STATE =

B7)• stop:

– True when in STP, RETRN, and IDLE state– Transmitter must drive a ‘1’ when IDLE (i.e. a STOP bit)

• start:– True in STRT state

• clrTimer:– True in IDLE state (the counter is free running otherwise)

Page 19: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Signal Debouncing

Page 20: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Signal Bouncing• The buttons will “bounce” many times each time

the button is pressed– Pressing the button generates a very noisy analog signal– The corresponding digital signal will transition many times

until the button settles

• Additional circuitry must be added to “debounce”the button– If this bounce is not removed, one press of the “send

character” button will result in many distinct send character signals

– You will see many characters send to the PC

• You must add a debouncing circuit to this signal

Page 21: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Button Debounce Circuit

DebounceLogic

A digital equivalent of a low pass filter

switch settle time switch settle time

button settle time is typically around 10 msec

buttoninput

output

Page 22: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Debounce Circuit

Tsample > Tsettle

D Qbouncy debounced

en

Timer/Clock Divider

Tsettle

Tsamplebouncy

debounced

clk

clk

en_sample

en_sample

Page 23: Lab 4 UART Transmitter - ece320web.groups.et.byu.netece320web.groups.et.byu.net/labs/Lab4-UART_Transmitter/uart_transmitter.pdf · Lab 4 UART Transmitter. BYU ECEn 320 UART Transmimtter

BYU ECEn 320

Debounce Circuit• You can create a debouncer by “sampling”

the input signal infrequently (~10 ms?)– Create a counter to measure the delay time– Sample the input signal every time the counter rolls

over

• You should make the delay parameterizable (with generics) so you can adjust the debounce time