Endymion
Junior Member level 3
Hello,
I am attempting to use VHDL to implement a SPI based shift register. However, instead of using SPI for loading or reading the shift register I would like to use a command based approach. The shift register will never be required to have more than one '1' loaded into it (it will always have a walking one vector). So I've come up with the following commands that I'd like to implement:
CMD: 0x01 -- Load shift register with '1' at the least significant position.
CMD: 0x0F -- Set all bits to 0.
CMD: 0xAA -- Shift the contents of the shift register by one bit.
I am a newbie in VHDL and digital design so I might have made some really basic mistakes in the following program and thats why I'm submitting it. Please note, I am not done yet. Notably, I don't have the shift register output being set anywhere. I am hoping someone here could take a look and let me know if there is something I'm doing wrong (i.e. how does my design look?). The simulation works well. All 3 commands that I mentioned above seem to work well.
The "sync" component is a component I wrote to sync. external signals like Chip Select and SCK.
The first process handles an internal 8-bit shift register which holds the incoming command (cmd). This command is then compared with in a Case statement in the 2nd process. If it matches a known command, the appropriate action is executed. I am wondering weather I should set the contents of the cmd register to 0 whenever an action is executed and done.
I am attempting to use VHDL to implement a SPI based shift register. However, instead of using SPI for loading or reading the shift register I would like to use a command based approach. The shift register will never be required to have more than one '1' loaded into it (it will always have a walking one vector). So I've come up with the following commands that I'd like to implement:
CMD: 0x01 -- Load shift register with '1' at the least significant position.
CMD: 0x0F -- Set all bits to 0.
CMD: 0xAA -- Shift the contents of the shift register by one bit.
I am a newbie in VHDL and digital design so I might have made some really basic mistakes in the following program and thats why I'm submitting it. Please note, I am not done yet. Notably, I don't have the shift register output being set anywhere. I am hoping someone here could take a look and let me know if there is something I'm doing wrong (i.e. how does my design look?). The simulation works well. All 3 commands that I mentioned above seem to work well.
The "sync" component is a component I wrote to sync. external signals like Chip Select and SCK.
Code:
library ieee;
use ieee.std_logic_1164.all;
entity RotatingOne is
port(nRESET, CLK, SCK, SI, nCS : in std_logic;
POut : out std_logic_vector(7 downto 0));
end RotatingOne;
architecture shift of RotatingOne is
constant WIDTH : integer := 8;
signal cmd : std_logic_vector(7 downto 0);
signal temp : std_logic_vector(WIDTH - 1 downto 0);
signal rise_SCK, fall_SCK : std_logic;
signal CS_rising, CS_falling : std_logic;
component sync
port(
SCK : in std_logic;
CLK : in std_logic;
rise, fall : out std_logic
);
end component;
begin
sync1 : sync port map(SCK, CLK, rise_SCK, fall_SCK);
sync2 : sync port map(nCS, CLK, CS_rising, CS_falling);
process(CLK, nRESET)
begin
if (nRESET = '0') then
cmd <= (others => '0');
elsif rising_edge(CLK) then
if nCS = '0' then
if rise_SCK = '1' then
cmd <= cmd(WIDTH - 2 downto 0) & SI;
end if;
end if;
end if;
end process;
process(CLK, nRESET)
begin
if (nRESET = '0') then
temp <= (others => '0');
elsif rising_edge(CLK) then
if CS_rising = '1' then
case cmd is
when "00000001" =>
temp <= "00000001";
when "00001111" =>
temp <= "00000000";
when "10101010" =>
temp <= temp(WIDTH - 2 downto 0) & '0';
when others =>
null;
end case;
end if;
end if;
end process;
end shift;
The first process handles an internal 8-bit shift register which holds the incoming command (cmd). This command is then compared with in a Case statement in the 2nd process. If it matches a known command, the appropriate action is executed. I am wondering weather I should set the contents of the cmd register to 0 whenever an action is executed and done.