Skip to content

Commit

Permalink
p_01 update v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarLilic committed Dec 2, 2020
1 parent 4801f56 commit 3f5ac30
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
41 changes: 21 additions & 20 deletions p_01/flashing_led_hw.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ entity flashing_led_hw is

-- data input
pi_switch : IN STD_LOGIC_VECTOR(9 DOWNTO 0); -- blinking speed
pi_btn : IN STD_LOGIC; -- play/pause
pi_btn : IN STD_LOGIC; -- play/pause

-- OUTPUTS
-- data output
po_led_1 : OUT STD_LOGIC;
po_led_2 : OUT STD_LOGIC
po_led_2 : OUT STD_LOGIC
);
end flashing_led_hw;

Expand All @@ -28,61 +28,62 @@ constant counter_ms : INTEGER := 50000; -- clock cycles for 1 ms
signal w_switch_val_ms : STD_LOGIC_VECTOR(13 DOWNTO 0) := (others => '0');
signal reg_counter : STD_LOGIC_VECTOR(15 DOWNTO 0) := (others => '0');
signal reg_counter_ms : STD_LOGIC_VECTOR(13 DOWNTO 0) := (others => '0');
signal w_equality : STD_LOGIC := '0';
signal w_equality_led : STD_LOGIC := '0';
signal w_1_ms_elapsed : STD_LOGIC := '0';
signal w_sw_ms_elapsed : STD_LOGIC := '0';
signal w_error_period : STD_LOGIC := '0';
signal reg_status_led : STD_LOGIC := '0';


begin

-- multiply switch value by 5 to get half of period of ms value
w_switch_val_ms <= STD_LOGIC_VECTOR(shift_left(UNSIGNED("0000" & pi_switch),2)+(UNSIGNED("0000" & pi_switch)));
w_switch_val_ms <= STD_LOGIC_VECTOR(shift_left(UNSIGNED("0000" & pi_switch),2)+(UNSIGNED("0000" & pi_switch))) when rst = '1' else
(w_switch_val_ms'range => '0');

-- error, every switch is at zero
w_error_period <= '1' when w_switch_val_ms = (w_switch_val_ms'range => '0') else
'0';
'0';

-- 1 ms passed
w_equality <= '1' when to_integer(UNSIGNED(reg_counter)) = counter_ms else
'0';
-- 1 ms elapsed
w_1_ms_elapsed <= '1' when to_integer(UNSIGNED(reg_counter)) >= counter_ms else
'0';

counter_1ms_process: process(clk)
begin
if(rising_edge(clk)) then
if(rst = '1') then
if(rst = '0') then
reg_counter <= (others => '0');
elsif(w_equality = '1') then
elsif(w_1_ms_elapsed = '1') then
reg_counter <= (others => '0');
elsif(pi_btn = '0' and w_error_period = '0') then
elsif(pi_btn = '1' and w_error_period = '0') then
reg_counter <= STD_LOGIC_VECTOR(UNSIGNED(reg_counter) + 1);
end if;
end if;
end process;

-- # of ms passed (set from switch)
w_equality_led <= '1' when reg_counter_ms = w_switch_val_ms else
w_sw_ms_elapsed <= '1' when reg_counter_ms >= w_switch_val_ms else
'0';

counter_switch_ms_process: process(clk)
begin
if(rising_edge(clk)) then
if(rst = '1') then
if(rst = '0') then
reg_counter_ms <= (others => '0');
elsif(w_equality = '1') then
reg_counter_ms <= STD_LOGIC_VECTOR(UNSIGNED(reg_counter_ms) + 1);
elsif(w_equality_led = '1') then
reg_counter_ms <= (others => '0');
elsif(w_sw_ms_elapsed = '1') then
reg_counter_ms <= (others => '0');
elsif(w_1_ms_elapsed = '1') then
reg_counter_ms <= STD_LOGIC_VECTOR(UNSIGNED(reg_counter_ms) + 1);
end if;
end if;
end process;

status_led_process: process(clk)
begin
if(rising_edge(clk)) then
if(rst = '1') then
if(rst = '0') then
reg_status_led <= '0';
elsif(w_equality_led = '1') then
elsif(w_sw_ms_elapsed = '1') then
reg_status_led <= not reg_status_led;
end if;
end if;
Expand Down
14 changes: 7 additions & 7 deletions p_01/flashing_led_hw_tb.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ begin
pi_switch => reg_pi_switch,
pi_btn => reg_pi_btn,
po_led_1 => reg_po_led_1,
po_led_2 => reg_po_led_2
);
po_led_2 => reg_po_led_2
);

clk_process :process
begin
Expand All @@ -59,19 +59,19 @@ begin
begin
wait for 5 ns;
wait for clk_period*10;
rst <= '1';
wait for clk_period*5;
rst <= '0';
reg_pi_btn <= '0';
wait for clk_period*5;
rst <= '1';
reg_pi_btn <= '1';
reg_pi_switch <= "0000000001";

wait for clk_period;
wait for 30 ms;
reg_pi_btn <= '1';
reg_pi_btn <= '0';
wait for clk_period;

wait for 20 ms;
reg_pi_btn <= '0';
reg_pi_btn <= '1';
wait for 20 ms;

reg_pi_switch <= "0000001001";
Expand Down

0 comments on commit 3f5ac30

Please sign in to comment.