signal cnt :integer 0 to 39:=0;
可以设置两种状态:'0','1',
type state_type is('0','1',idle);
state :state_type;
你得先设定input_line 上的状态,假设为idle;
case state is
when idle=> cnt<=0;
if input_line='0' then
state<='0';
else
state<='1';
when '0'=> if input_line='1' then
cnt<=cnt+1;
tap<='1';
state<='1';
else
tap<='0';
state<=idle;
when '1'=> if input_line='0' then
cnt<=cnt+1;
tap<='1';
state<='0';
else
tap<='0';
state<=idle;
意思就是在‘0’ 和‘1’ 之间交替,只要有变,标志tap就为‘1’ 你可以检测标志来改变数,然后记到40次就控制一下cnt ,到39 变0就可以了,