|
楼主 |
发表于 2011-7-26 18:20:18
|
显示全部楼层
我没用到状态机,修改下面这段代码就不够用了,有没好办法优化下的
process(clk,cmd,kout)
variable cnt_ain:std_logic_vector(7 downto 0):="00000000";
variable cnt_bin:std_logic_vector(7 downto 0):="00000110";
begin
if cmd="00000000" then
clkout_a<=clk_a;clkout_b<=clk_b;
else
if (clk'event and clk='1') then
case kout is
when '1'=>cnt_ain:=cnt_ain+1;cnt_bin:=cnt_bin+1;
if (cnt_ain<=(cnt_a)) then clkout_a<='1';
else clkout_a<='0';
if (cnt_ain>=(cnt_b)) then cnt_ain:="00000000";
end if;
end if;
if (cnt_bin<=(cnt_a)) then clkout_b<='1';
else clkout_b<='0';
if (cnt_bin>=(cnt_b)) then cnt_bin:="00000000";
end if;
end if;
when '0'=>cnt_ain:=cnt_ain-1;cnt_bin:=cnt_bin-1;
if (cnt_ain>(cnt_b-1)) then cnt_ain:=cnt_b-1;clkout_a<='1';
else
if (cnt_ain>=(cnt_a)) then clkout_a<='1';
else clkout_a<='0';
end if;
end if;
if (cnt_bin>(cnt_b-1)) then cnt_bin:=cnt_b-1;clkout_b<='1';
else
if (cnt_bin>=(cnt_a)) then clkout_b<='1';
else clkout_b<='0';
end if;
end if;
when others=>clkout_b<='0';clkout_a<='0';
end case;
end if;
end if;
end process; |
|