J
john
Guest
Hi,
I am trying to build a 19 bit parallel to serial conveter. I have one
state machine and a 5 bit counter. The problem is that its only
outputing the MSB bit from the 19 bit data. Please adivce soon ...The
code is as follows
---P2S-----
library IEEE;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
entity PISO is
port (
parallel_in : in unsigned (18 downto 0); -- Parallel Register
,holds the 19- bits
latch : in std_logic; -- When low, loads the data into the
19-bit register
ds : in bit; -- Makes the parallel register shifts right or
left
ser_out : out bit; -- Serial data output pin
CLK : in std_logic; -- Clock for the serial shift
clk_out : out std_logic; -- Clock for the Digigtal to Analog
converter
synch : out std_logic; -- Synchronize the data frame
cpld_ready : out std_logic
);
end PISO;
Architecture PISO_ARCH of PISO IS
--------------------------------------------
Component counter_b
Port (
CLK_b : in std_logic;
P_b : in std_logic;
Load : in std_logic;
compare_signal : out std_logic
);
End Component;
-------------------------------------------------
signal State : unsigned(3 downto 0);
signal nextstate : unsigned(3 downto 0);
constant E0 : unsigned(3 downto 0):="0001";
constant E1 : unsigned(3 downto 0):="0010";
constant E2 : unsigned(3 downto 0):="0100";
constant E3 : unsigned(3 downto 0):="1000";
--Signal SM_DIR : std_logic;
-------------------------------------------------
Signal incrementB : std_logic;
Signal Load_counter : std_logic;
Signal compare : std_logic;
------------------------------------------------
Signal ser_buff: bit_vector ( 18 downto 0);
BEGIN
ser_out <= ser_buff(18);
clk_out <= latch and clk;
synch<= incrementB;
cpld_ready <=compare;
CB: counter_b port map (CLK, incrementB,Load_counter,compare);
--------------------------------------------------------------------------
Process(State,nextstate)
Begin
Case State is
When E0=>
incrementB<='0';
ser_buff<="0101010101010101010";
Load_counter<='1';
nextstate<=E1;
When E1=>
If (compare ='0') Then
incrementB<='1';
Load_counter<='0';
ser_buff(0) <= ds;
ser_buff(1) <= ser_buff(0);
ser_buff(2) <= ser_buff(1);
ser_buff(3) <= ser_buff(2);
ser_buff(4) <= ser_buff(3);
ser_buff(5) <= ser_buff(4);
ser_buff(6) <= ser_buff(5);
ser_buff(7) <= ser_buff(6);
ser_buff(8) <= ser_buff(7);
ser_buff(9) <= ser_buff(8);
ser_buff(10) <= ser_buff(9);
ser_buff(11) <= ser_buff(10);
ser_buff(12) <= ser_buff(11);
ser_buff(13) <= ser_buff(12);
ser_buff(14) <= ser_buff(13);
ser_buff(15) <= ser_buff(14);
ser_buff(16) <= ser_buff(15);
ser_buff(17) <= ser_buff(16);
ser_buff(18) <= ser_buff(17);
nextstate<=E1;
Else
nextstate<=E0;
End If;
When others =>
nextstate <= E0;
End Case;
End Process;
--------------------------------------------------
Process (CLK)
Begin
If (CLK'event And CLK='1') Then
-- SM_DIR <= OE1;
State <= nextstate;
End If;
End Process;
End PISO_ARCH;
----Counter------
Library IEEE;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
------------------------------------------------------------------
Entity counter_b is
Port (
CLK_b : in std_logic;
P_b : in std_logic;
Load : in std_logic;
compare_signal : out std_logic
);
End counter_b;
Architecture count_arch_b of counter_b is
Signal Q_b : unsigned (4 downto 0);
Signal data : unsigned (4 downto 0):="10011";
Begin
Process(CLK_b,Load)
Begin
If (Load='1')Then
Q_b <= ('0', '0', '0', '0', '0');
compare_signal <='0';
Else If (CLK_b='1' and CLK_b'event) then
If (P_b='1') Then
Q_b<=Q_b+1;
compare_signal <='0';
If (Q_b=data) Then
compare_signal <='1';
Q_b <= ('0', '0', '0', '0', '0');
End If;
End If;
--End If;
End if;
End If;
End process;
End count_arch_b ;
I am trying to build a 19 bit parallel to serial conveter. I have one
state machine and a 5 bit counter. The problem is that its only
outputing the MSB bit from the 19 bit data. Please adivce soon ...The
code is as follows
---P2S-----
library IEEE;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
entity PISO is
port (
parallel_in : in unsigned (18 downto 0); -- Parallel Register
,holds the 19- bits
latch : in std_logic; -- When low, loads the data into the
19-bit register
ds : in bit; -- Makes the parallel register shifts right or
left
ser_out : out bit; -- Serial data output pin
CLK : in std_logic; -- Clock for the serial shift
clk_out : out std_logic; -- Clock for the Digigtal to Analog
converter
synch : out std_logic; -- Synchronize the data frame
cpld_ready : out std_logic
);
end PISO;
Architecture PISO_ARCH of PISO IS
--------------------------------------------
Component counter_b
Port (
CLK_b : in std_logic;
P_b : in std_logic;
Load : in std_logic;
compare_signal : out std_logic
);
End Component;
-------------------------------------------------
signal State : unsigned(3 downto 0);
signal nextstate : unsigned(3 downto 0);
constant E0 : unsigned(3 downto 0):="0001";
constant E1 : unsigned(3 downto 0):="0010";
constant E2 : unsigned(3 downto 0):="0100";
constant E3 : unsigned(3 downto 0):="1000";
--Signal SM_DIR : std_logic;
-------------------------------------------------
Signal incrementB : std_logic;
Signal Load_counter : std_logic;
Signal compare : std_logic;
------------------------------------------------
Signal ser_buff: bit_vector ( 18 downto 0);
BEGIN
ser_out <= ser_buff(18);
clk_out <= latch and clk;
synch<= incrementB;
cpld_ready <=compare;
CB: counter_b port map (CLK, incrementB,Load_counter,compare);
--------------------------------------------------------------------------
Process(State,nextstate)
Begin
Case State is
When E0=>
incrementB<='0';
ser_buff<="0101010101010101010";
Load_counter<='1';
nextstate<=E1;
When E1=>
If (compare ='0') Then
incrementB<='1';
Load_counter<='0';
ser_buff(0) <= ds;
ser_buff(1) <= ser_buff(0);
ser_buff(2) <= ser_buff(1);
ser_buff(3) <= ser_buff(2);
ser_buff(4) <= ser_buff(3);
ser_buff(5) <= ser_buff(4);
ser_buff(6) <= ser_buff(5);
ser_buff(7) <= ser_buff(6);
ser_buff(8) <= ser_buff(7);
ser_buff(9) <= ser_buff(8);
ser_buff(10) <= ser_buff(9);
ser_buff(11) <= ser_buff(10);
ser_buff(12) <= ser_buff(11);
ser_buff(13) <= ser_buff(12);
ser_buff(14) <= ser_buff(13);
ser_buff(15) <= ser_buff(14);
ser_buff(16) <= ser_buff(15);
ser_buff(17) <= ser_buff(16);
ser_buff(18) <= ser_buff(17);
nextstate<=E1;
Else
nextstate<=E0;
End If;
When others =>
nextstate <= E0;
End Case;
End Process;
--------------------------------------------------
Process (CLK)
Begin
If (CLK'event And CLK='1') Then
-- SM_DIR <= OE1;
State <= nextstate;
End If;
End Process;
End PISO_ARCH;
----Counter------
Library IEEE;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
------------------------------------------------------------------
Entity counter_b is
Port (
CLK_b : in std_logic;
P_b : in std_logic;
Load : in std_logic;
compare_signal : out std_logic
);
End counter_b;
Architecture count_arch_b of counter_b is
Signal Q_b : unsigned (4 downto 0);
Signal data : unsigned (4 downto 0):="10011";
Begin
Process(CLK_b,Load)
Begin
If (Load='1')Then
Q_b <= ('0', '0', '0', '0', '0');
compare_signal <='0';
Else If (CLK_b='1' and CLK_b'event) then
If (P_b='1') Then
Q_b<=Q_b+1;
compare_signal <='0';
If (Q_b=data) Then
compare_signal <='1';
Q_b <= ('0', '0', '0', '0', '0');
End If;
End If;
--End If;
End if;
End If;
End process;
End count_arch_b ;