⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picoblaze_real_time_clock.vhd

📁 PicoBlaze_Real_Time_Clock
💻 VHD
📖 第 1 页 / 共 2 页
字号:
if clk 'event and clk='1' then
	 if cnt2_5ms<"011000" then ck2_5ms<='0';---0--24/25--49
	 else
    ck2_5ms<='1';
	 end if;
end if;
  end process;


ck_1s: process(ck2_5ms)
  begin
if ck2_5ms'event and ck2_5ms='1' then
	 if cnt1s="011000111" then cnt1s<="000000000";--0--24
	else
	 cnt1s<=cnt1s+1;
	 end if;
 end if;
  end process ck_1s;

process(clk)
begin
if clk 'event and clk='1' then
	 if cnt1s<"001100011" then ck1s<='0';---0--24/25--49
	 else
    ck1s<='1';
	 end if;
end if;
  end process;

  ----------------------------------------------------------------------------------------------------------------------------------
  -- Interrupt 
  ----------------------------------------------------------------------------------------------------------------------------------
  --
  --
  -- Interrupt is used to detect rotation of the rotary encoder.
  -- It is anticipated that the processor will respond to interrupts at a far higher 
  -- rate that the rotary control can be operated and hence events will not be missed. 
  --Inerrupt flags for multi-sources detect;
  --Ignore Interrupt_Ack,clr INT by clr IFR;

  interrupt_control: process(ck1us)
  begin
    if write_strobe='1' and port_id(5)='1' and (out_port(6)='1' or out_port(7)='1') then
          interrupt <= '0';

    elsif ck1us'event and ck1us='1' then
        interrupt <= rotary_flag or ck_flag;
    end if; 
  end process interrupt_control;

interrupt_source0:process(ck1us)
  begin

    if ck1us'event and ck1us='1' then
	ck_tmp<=ck2_5ms;
	rotary_tmp<=rotary_q1;
    end if;

  end process interrupt_source0;

interrupt_flag0:process(ck1us)
  begin
if write_strobe='1' and port_id(5)='1' and out_port(7)='1' then
          ck_flag <='0';
      
    elsif ck1us'event and ck1us='1' then
		if ck_tmp='0' and ck2_5ms='1' then
     	  ck_flag <='1';
		end if;

    end if;

  end process interrupt_flag0;

interrupt_flag1:process(ck1us)
  begin
      if write_strobe='1' and port_id(5)='1' and out_port(6)='1' then
          rotary_flag <= '0';
      elsif ck1us'event and ck1us='1' then
			if rotary_q1='1' and rotary_tmp='0' then
		rotary_flag <='1';
			end if;
	 end if;

  end process interrupt_flag1;

  ----------------------------------------------------------------------------------------------------------------------------------
  -- KCPSM3 input ports 
  ----------------------------------------------------------------------------------------------------------------------------------
  --
  --
  -- The inputs connect via a pipelined multiplexer
  --

  input_ports: process(clk)
  begin
    if clk'event and clk='1' then

      case port_id(1 downto 0) is

        -- read simple toggle switches and buttons at address 00 hex
        when "00" =>    in_port <= btn_west & btn_north & btn_south & btn_east & switch;
--        when "00" =>    in_port <=  cnt1s(3 downto 0)& cnt1s(0) & cnt1s(1)& cnt1s(2)& cnt1s(3);

        -- read rotary control signals at address 01 hex
        when "01" =>    in_port <= ck_flag & rotary_flag & "XXXX" & rotary_press_in & rotary_left;

        -- read LCD data at address 02 hex
        when "10" =>    in_port <= lcd_d & "XXXX";

        -- Don't care used for all other addresses to ensure minimum logic implementation
        when others =>    in_port <= "XXXXXXXX";  

      end case;

     end if;

  end process input_ports;


  --
  ----------------------------------------------------------------------------------------------------------------------------------
  -- KCPSM3 output ports 
  ----------------------------------------------------------------------------------------------------------------------------------
  --

  -- adding the output registers to the processor
   
  output_ports: process(clk)
  begin

    if clk'event and clk='1' then
      if write_strobe='1' then

        -- Write to LEDs at address 80 hex.

        if port_id(7)='1' then
          led <= out_port;
        end if;

        -- LCD data output and controls at address 40 hex.

        if port_id(6)='1' then
          lcd_output_data <= out_port(7 downto 4);
          lcd_drive <= out_port(3);  
          lcd_rs <= out_port(2);
          lcd_rw_control <= out_port(1);
          lcd_e <= out_port(0);
        end if;

      end if;

    end if; 

  end process output_ports;

  --
  ----------------------------------------------------------------------------------------------------------------------------------
  -- LCD interface  
  ----------------------------------------------------------------------------------------------------------------------------------
  --
  -- The 4-bit data port is bidirectional.
  -- lcd_rw is '1' for read and '0' for write 
  -- lcd_drive is like a master enable signal which prevents either the 
  -- FPGA outputs or the LCD display driving the data lines.
  --
  --Control of read and write signal
  lcd_rw <= lcd_rw_control and lcd_drive;

  --use read/write control to enable output buffers.
  lcd_d <= lcd_output_data when (lcd_rw_control='0' and lcd_drive='1') else "ZZZZ";


  ----------------------------------------------------------------------------------------------------------------------------------
  -- Interface to rotary encoder.
  -- Detection of movement and direction.
  ----------------------------------------------------------------------------------------------------------------------------------
  --
  -- The rotary switch contacts are filtered using their offset (one-hot) style to  
  -- clean them. Circuit concept by Peter Alfke.
  -- Note that the clock rate is fast compared with the switch rate.



  
  rotary_filter: process(clk)
  begin
    if clk'event and clk='1' then
 
 --Synchronise inputs to clock domain using flip-flops in input/output blocks.
      rotary_a_in <= rotary_a;
      rotary_b_in <= rotary_b;
      rotary_press_in <= rotary_press;

   --concatinate rotary input signals to form vector for case construct.
      rotary_in <= rotary_b_in & rotary_a_in;
  
      case rotary_in is

        when "00" => rotary_q1 <= '0';         
                     rotary_q2 <= rotary_q2;
 
        when "01" => rotary_q1 <= rotary_q1;
                     rotary_q2 <= '0';

        when "10" => rotary_q1 <= rotary_q1;
                     rotary_q2 <= '1';

        when "11" => rotary_q1 <= '1';
                     rotary_q2 <= rotary_q2; 

        when others => rotary_q1 <= rotary_q1; 
                       rotary_q2 <= rotary_q2; 
      end case;

    end if;
  end process rotary_filter;
  --
  -- The rising edges of 'rotary_q1' indicate that a rotation has occurred and the 
  -- state of 'rotary_q2' at that time will indicate the direction. 
  --
  direction: process(clk)
  begin
    if clk'event and clk='1' then

      delay_rotary_q1 <= rotary_q1;
      if rotary_q1='1' and delay_rotary_q1='0' then
        rotary_event <= '1';
        rotary_left <= rotary_q2;
       else
        rotary_event <= '0';
        rotary_left <= rotary_left;
      end if;

    end if;
  end process direction;
  --
  ----------------------------------------------------------------------------------------------------------------------------------
  --

  --
  --
  --
end Behavioral;

------------------------------------------------------------------------------------------------------------------------------------
--
-- END OF FILE picoblaze_real_time_clock.vhd
--
------------------------------------------------------------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -