计数器溢出问题
时间:10-02
整理:3721RD
点击:
小弟想做一8位计数器,能够在正负溢出时给出中断,现在对计数器溢出十分不解,如何才能找出正负溢出的那个标志?如果计数器在0时,再减1则变为FF,则一直减计数的话,到什么情况是溢出?希望大哥们帮忙下,小弟不胜感激!
signal cnt : integer range -127 to 127;
signal direction : integer range -1 to 1;
begin
direction <= 1 when dr = '0' else -1;
process(cnt_clr,clk)
begin
if cnt_clr = '0' then
cnt <= 0;
elsif clk'event and clk ='0' then
cnt <= cnt + direction;
end if;
end process;
signal cnt : integer range -127 to 127;
signal direction : integer range -1 to 1;
begin
direction <= 1 when dr = '0' else -1;
process(cnt_clr,clk)
begin
if cnt_clr = '0' then
cnt <= 0;
elsif clk'event and clk ='0' then
cnt <= cnt + direction;
end if;
end process;
升计数时FF为溢出标志,降计数时00为溢出标志
看看
有道理
多设一位呗,
高两位为00,11正常,为01上溢,为10下溢。
