Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
progkrets
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Solveig Langbakk
progkrets
Commits
c2a99f6f
Commit
c2a99f6f
authored
6 months ago
by
Nils
Browse files
Options
Downloads
Patches
Plain Diff
fikset calculate_parity og fått TxD til å oppdatere riktig etter syklus
parent
d16a0377
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Tx.vhd
+44
-23
44 additions, 23 deletions
Tx.vhd
Tx_tb.vhd
+1
-1
1 addition, 1 deletion
Tx_tb.vhd
with
45 additions
and
24 deletions
Tx.vhd
+
44
−
23
View file @
c2a99f6f
...
@@ -19,7 +19,6 @@ architecture Behavioral of Tx is
...
@@ -19,7 +19,6 @@ architecture Behavioral of Tx is
signal
baud_rate
:
baud_type
;
signal
baud_rate
:
baud_type
;
signal
baud_count
:
natural
range
0
to
5208
;
signal
baud_count
:
natural
range
0
to
5208
;
signal
baud_clk
:
std_logic
;
signal
baud_clk
:
std_logic
;
signal
last_baud_clk
:
std_logic
;
-- Parity type
-- Parity type
type
parity_type
is
(
no_parity
,
even_parity
,
odd_parity
);
type
parity_type
is
(
no_parity
,
even_parity
,
odd_parity
);
signal
parity_mode
:
parity_type
;
signal
parity_mode
:
parity_type
;
...
@@ -30,7 +29,8 @@ architecture Behavioral of Tx is
...
@@ -30,7 +29,8 @@ architecture Behavioral of Tx is
--ovrige signaler
--ovrige signaler
signal
data_reg
:
std_logic_vector
(
7
downto
0
);
signal
data_reg
:
std_logic_vector
(
7
downto
0
);
signal
bit_count
:
natural
range
0
to
7
;
--er den riktig? teller det opp mellom data_reg? eller ned?
signal
bit_count
:
natural
range
0
to
7
;
signal
bit_to_send
,
ready_to_send
:
std_logic
;
function
select_baud
(
baud
:
std_logic_vector
(
2
downto
0
))
return
baud_type
is
function
select_baud
(
baud
:
std_logic_vector
(
2
downto
0
))
return
baud_type
is
begin
begin
...
@@ -81,24 +81,25 @@ architecture Behavioral of Tx is
...
@@ -81,24 +81,25 @@ architecture Behavioral of Tx is
for
i
in
data
'range
loop
for
i
in
data
'range
loop
tmp
:
=
tmp
xor
data
(
i
);
tmp
:
=
tmp
xor
data
(
i
);
end
loop
;
end
loop
;
return
tmp
x
n
or
parity_bit
;
return
tmp
xor
parity_bit
;
end
function
;
end
function
;
begin
begin
p_bit_send
:
TxD
<=
bit_to_send
;
process
(
clk
,
rst_n
)
is
process
(
clk
,
rst_n
)
is
begin
begin
if
rst_n
=
'0'
then
if
rst_n
=
'0'
then
--resetter systemet
--resetter systemet
TxD
<=
'1'
;
--TxD <= '1';
bit_to_send
<=
'1'
;
Data_bus
<=
(
others
=>
'Z'
);
Data_bus
<=
(
others
=>
'Z'
);
last_baud_clk
<=
'0'
;
baud_rate
<=
baud_type
'right
;
baud_rate
<=
baud_type
'right
;
parity_mode
<=
parity_type
'left
;
parity_mode
<=
parity_type
'left
;
tx_state
<=
tx_state_type
'left
;
tx_state
<=
tx_state_type
'left
;
bit_count
<=
0
;
bit_count
<=
0
;
data_reg
<=
(
others
=>
'0'
);
data_reg
<=
(
others
=>
'0'
);
elsif
rising_edge
(
clk
)
then
elsif
rising_edge
(
clk
)
then
last_baud_clk
<=
baud_clk
;
case
adresse
is
case
adresse
is
when
"000"
=>
-- Konfigurasjonsinnstillinger
when
"000"
=>
-- Konfigurasjonsinnstillinger
if
Wr_sig
=
'1'
then
if
Wr_sig
=
'1'
then
...
@@ -109,7 +110,7 @@ begin
...
@@ -109,7 +110,7 @@ begin
when
"001"
=>
--Initilaiserer transmisjon
when
"001"
=>
--Initilaiserer transmisjon
if
tx_state
=
IDLE
and
Wr_sig
=
'1'
then
if
tx_state
=
IDLE
and
Wr_sig
=
'1'
then
data_reg
<=
Data_bus
;
data_reg
<=
Data_bus
;
tx_state
<=
START_BIT
;
ready_to_send
<=
'1'
;
else
null
;
else
null
;
end
if
;
end
if
;
when
"010"
=>
-- busy
when
"010"
=>
-- busy
...
@@ -125,34 +126,54 @@ begin
...
@@ -125,34 +126,54 @@ begin
when
others
=>
null
;
when
others
=>
null
;
end
case
;
end
case
;
if
(
baud_clk
=
'1'
and
last_baud_clk
=
'0'
)
then
case
tx_state
is
case
tx_state
is
when
IDLE
=>
when
IDLE
=>
TxD
<=
'1'
;
--UART er høy singal når det ikke sendes noe
if
ready_to_send
=
'1'
then
tx_state
<=
START_BIT
;
ready_to_send
<=
'0'
;
else
bit_to_send
<=
'1'
;
--UART er aktivt høy singal
tx_state
<=
IDLE
;
end
if
;
when
START_BIT
=>
when
START_BIT
=>
TxD
<=
'0'
;
if
baud_clk
=
'1'
then
tx_state
<=
DATA_BITS
;
tx_state
<=
DATA_BITS
;
else
bit_to_send
<=
'0'
;
tx_state
<=
START_BIT
;
end
if
;
when
DATA_BITS
=>
when
DATA_BITS
=>
TxD
<=
data_reg
(
bit_count
);
if
baud_clk
=
'1'
then
if
bit_count
=
7
then
if
bit_count
=
7
then
bit_count
<=
0
;
bit_count
<=
0
;
if
parity_mode
=
no_parity
then
if
parity_mode
=
no_parity
then
tx_state
<=
STOP_BIT
;
tx_state
<=
STOP_BIT
;
else
tx_state
<=
PARITY_BIT
;
end
if
;
else
else
tx_state
<=
PARITY_BIT
;
bit_count
<=
bit_count
+
1
;
end
if
;
end
if
;
else
else
bit_count
<=
bit_count
+
1
;
bit_to_send
<=
data_reg
(
bit_count
);
tx_state
<=
DATA_BITS
;
end
if
;
end
if
;
when
PARITY_BIT
=>
when
PARITY_BIT
=>
TxD
<=
calculate_parity
(
data_reg
,
parity_mode
);
if
baud_clk
=
'1'
then
tx_state
<=
STOP_BIT
;
tx_state
<=
STOP_BIT
;
else
bit_to_send
<=
calculate_parity
(
data_reg
,
parity_mode
);
tx_state
<=
PARITY_BIT
;
end
if
;
when
STOP_BIT
=>
when
STOP_BIT
=>
TxD
<=
'1'
;
if
baud_clk
=
'1'
then
tx_state
<=
IDLE
;
tx_state
<=
IDLE
;
else
bit_to_send
<=
'1'
;
tx_state
<=
STOP_BIT
;
end
if
;
end
case
;
end
case
;
end
if
;
end
if
;
end
if
;
end
process
;
end
process
;
-- baud_rate Generator Process
-- baud_rate Generator Process
...
...
This diff is collapsed.
Click to expand it.
Tx_tb.vhd
+
1
−
1
View file @
c2a99f6f
...
@@ -97,7 +97,7 @@ begin
...
@@ -97,7 +97,7 @@ begin
begin
begin
Wr_sig
<=
'1'
;
Wr_sig
<=
'1'
;
adresse
<=
"001"
;
-- Sender data til Tx
adresse
<=
"001"
;
-- Sender data til Tx
Data_bus
<=
"111111
1
1"
;
-- data
Data_bus
<=
"111111
0
1"
;
-- data
wait
for
CLK_PERIOD
;
wait
for
CLK_PERIOD
;
Wr_sig
<=
'0'
;
Wr_sig
<=
'0'
;
wait
for
20
*
CLK_PERIOD
;
wait
for
20
*
CLK_PERIOD
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment