--cpld training swin-counter --19/5/31 8/22 -- library IEEE; use IEEE.STD_LOGIC_1164.ALL; library ARITHMETIC; use ARITHMETIC.std_logic_arith.all; entity trngswcntr1c is PORT ( SEGOUT:out std_logic_vector(7 downto 0); LEDOUT:out std_logic_vector(3 downto 0); CK1:in std_logic; SWA:in std_logic; SWB:in std_logic; SWC:in std_logic ); end trngswcntr1c; architecture rtl of trngswcntr1c is signal cntr1:std_logic_vector(11 downto 0);--1khz 4096=2**12 signal tm1:std_logic_vector(3 downto 0);--1/1000 sec signal cntrss0:std_logic_vector(3 downto 0);--1/100 sec signal cntrss1:std_logic_vector(3 downto 0);--1/10 sec signal leddatabf0:std_logic_vector(3 downto 0); signal leddatabf1:std_logic_vector(3 downto 0); signal leddatabf2:std_logic_vector(3 downto 0); signal leddatabf3:std_logic_vector(3 downto 0); signal leddatawk:std_logic_vector(3 downto 0); signal segdata:std_logic_vector(7 downto 0); signal ledoutbf:std_logic_vector(3 downto 0); signal ledcntr:std_logic_vector(2 downto 0); signal ledadrs:std_logic_vector(2 downto 0); signal swcntrb0:std_logic_vector(3 downto 0); signal swcntrb1:std_logic_vector(3 downto 0); signal swcntrc0:std_logic_vector(3 downto 0); signal swcntrc1:std_logic_vector(3 downto 0); signal swbon:std_logic; signal swcon:std_logic; -- begin -- 7seg drive clock 1KHz from 4096KHz process(CK1) begin if CK1'event and CK1='1' then cntr1<=cntr1+"000000000001"; end if; end process; -- led drive,LEDOUT process(cntr1) begin if cntr1(11)'event and cntr1(11)='0' then ledcntr<=ledcntr+"001"; ledoutbf<=ledoutbf(2 downto 0) & '0'; end if; if ledcntr(2)='1' then ledcntr<="000"; ledoutbf<="0001"; end if; end process; -- LEDOUT<=ledoutbf; SEGOUT<=segdata; -- -- led data out process(ledcntr) begin if ledcntr(1 downto 0)="00" then leddatawk<=leddatabf0; elsif ledcntr(1 downto 0)="01" then leddatawk<=leddatabf1; elsif ledcntr(1 downto 0)="10" then leddatawk<=leddatabf2; elsif ledcntr(1 downto 0)="11" then leddatawk<=leddatabf3; end if; end process; --segment change process(leddatawk) begin if leddatawk="0000" then segdata<="01011100"; elsif leddatawk="0001" then segdata<="00000110"; elsif leddatawk="0010" then segdata<="01011011"; elsif leddatawk="0011" then segdata<="01001111"; elsif leddatawk="0100" then segdata<="01100110"; elsif leddatawk="0101" then segdata<="01101101"; elsif leddatawk="0110" then segdata<="01111101"; elsif leddatawk="0111" then segdata<="00000111"; elsif leddatawk="1000" then segdata<="01111111"; elsif leddatawk="1001" then segdata<="01101111"; end if; end process; -- --1/1000 process(cntr1(11)) begin if cntr1(11)'event and cntr1(11)='0' then tm1<=tm1+"0001"; end if; if tm1="1010" then tm1<="0000"; end if; end process; -- 1/100sec process(tm1(3)) begin if tm1(3)'event and tm1(3)='0' then cntrss0<=cntrss0+"0001"; end if; if cntrss0="1010" then cntrss0<="0000"; end if; end process; -- --1/10sec process(cntrss0(3)) begin if cntrss0(3)'event and cntrss0(3)='0' then cntrss1<=cntrss1+"001"; end if; if cntrss1="1010" then cntrss1<="0000"; end if; end process; -- -- ******* sw in counter ****** --sw on check process(cntrss0(3))--10ms begin if cntrss0(3)'event and cntrss0(3)='1' then swbon<=SWB; swcon<=SWC; end if; end process; --cntrb -- process(SWA,swbon) begin if swbon'event and swbon='0' then swcntrb0<=swcntrb0+"0001"; end if; if swcntrb0="1010" or SWA='0' then swcntrb0<="0000"; end if; end process; -- process(swcntrb0(3)) begin if swcntrb0(3)'event and swcntrb0(3)='0' then swcntrb1<=swcntrb1+"0001"; end if; if swcntrb1="1010" or SWA='0' then swcntrb1<="0000"; end if; end process; --cntrc -- process(SWA,swcon) begin if swcon'event and swcon='0' then swcntrc0<=swcntrc0+"0001"; end if; if swcntrc0="1010" or SWA='0' then swcntrc0<="0000"; end if; end process; -- process(swcntrc0(3)) begin if swcntrc0(3)'event and swcntrc0(3)='0' then swcntrc1<=swcntrc1+"0001"; end if; if swcntrc1="1010" or SWA='0' then swcntrc1<="0000"; end if; end process; -- --7seg disp -- leddatabf3<=swcntrc0; leddatabf2<=swcntrc1; leddatabf1<=swcntrb0; leddatabf0<=swcntrb1; -- end rtl;