集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 2453|回复: 6

计数器?有个输出y,怎么使y在0到32为1 ,在32到64为1,64到100又为0?

[复制链接]
interi 发表于 2010-6-28 00:38:38 | 显示全部楼层 |阅读模式
计数器计数(假如可以计数0到100),有个输出y,怎么使y在0到32为1 ,在32到64为1,64到100又为0?
encounter 发表于 2010-6-28 02:23:44 | 显示全部楼层
你已经说了很清楚了,看看书就可以写了<br>
<br>
good luck !
ATA 发表于 2010-6-28 04:04:25 | 显示全部楼层
??????????if
encounter 发表于 2010-6-28 05:43:34 | 显示全部楼层
我也是感觉楼主讲的很明白了,呵呵
usb 发表于 2010-6-28 05:52:17 | 显示全部楼层
各位见谅:<br>
可不可以看看这个程序,我还是修改不对,总是在q+2等地方出错。谢谢了!<br>
library ieee;<br>
use ieee.std_logic_1164.all;<br>
use ieee.std_logic_arith.all;<br>
use ieee.std_logic_unsigned.all;<br>
entity shiyan36 is<br>
port(cp:in std_logic;<br>
&nbsp; &nbsp;&nbsp;&nbsp;res:in std_logic;<br>
&nbsp; &nbsp;&nbsp;&nbsp;d:in std_logic_vector(2 downto 0);<br>
&nbsp; &nbsp;&nbsp;&nbsp;vt_one,vt_two
       
ut std_logic);<br>
end shiyan36;<br>
architecture a of shiyan36 is<br>
signal wave1,wave2:std_logic;<br>
signal q:integer;<br>
begin<br>
u1:process(d)<br>
begin<br>
q&lt;=conv_integer(d);<br>
end process;<br>
u2:process(cp,res,q)<br>
variable temp:integer range 0 to 7;<br>
begin<br>
&nbsp; &nbsp; if res='0' then<br>
&nbsp; &nbsp; temp:=0;<br>
&nbsp; &nbsp; elsif rising_edge(cp) then&nbsp; &nbsp; <br>
&nbsp; &nbsp;&nbsp;&nbsp;temp:=temp+1;<br>
&nbsp; &nbsp;&nbsp;&nbsp;case temp is<br>
&nbsp; &nbsp;&nbsp; &nbsp;when 0 to q=&gt; wave1&lt;='0';wave2&lt;='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;when q to q+2=&gt; wave1&lt;='1';wave2&lt;='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;when q+2 to q+4 =&gt; wave1&lt;='0';wave2&lt;='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;when&nbsp;&nbsp;q+4 to q+6=&gt; wave1&lt;='0';wave2&lt;='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;when others=&gt; wave1&lt;='0';wave2&lt;='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;end case;<br>
end if;<br>
end process;<br>
vt_one&lt;=wave1;<br>
vt_two&lt;=wave2;<br>
end a;
ups 发表于 2010-6-28 07:15:36 | 显示全部楼层
有这么复杂吗,我帮你做一个吧!
CHAN 发表于 2010-6-28 08:36:33 | 显示全部楼层
--------------------------------------------------------------<br>
-- library<br>
--------------------------------------------------------------<br>
library ieee;<br>
use ieee.std_logic_1164.all;<br>
use ieee.std_logic_unsigned.all;<br>
use ieee.std_logic_arith.all;<br>
<br>
--------------------------------------------------------------<br>
-- entity<br>
--------------------------------------------------------------<br>
entity cnter is<br>
&nbsp;&nbsp;port (<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;RST&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; : in&nbsp;&nbsp;std_logic;&nbsp;&nbsp;----reset signal<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;CLK&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; : in&nbsp;&nbsp;std_logic;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Y&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;: out&nbsp;&nbsp;std_logic;<br>
&nbsp; &nbsp;);<br>
end cnter;<br>
<br>
--------------------------------------------------------------<br>
-- architecture<br>
--------------------------------------------------------------<br>
architecture RTL of cnter is<br>
<br>
signal n_counter&nbsp;&nbsp;: integer range 0 to 100 := 0;<br>
signal n_y&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;: std_logic;<br>
<br>
begin<br>
<br>
p_n_counter : process(CLK, RST)<br>
begin<br>
&nbsp;&nbsp;if(RST = '0') then<br>
&nbsp; &nbsp; n_counter &lt;= 0;<br>
&nbsp; &nbsp; n_y &lt;= '0';<br>
<br>
&nbsp;&nbsp;elsif(CLK'event and CLK = '1') then<br>
&nbsp; &nbsp; if(n_counter &lt; 100) then<br>
&nbsp; &nbsp;&nbsp; &nbsp;n_counter &lt;= n_counter + 1;<br>
&nbsp; &nbsp; else <br>
&nbsp; &nbsp;&nbsp; &nbsp;n_counter &lt;= 0;<br>
&nbsp; &nbsp; end if;<br>
end process;<br>
<br>
p_n_y : process(n_counter,RST)<br>
begin<br>
&nbsp;&nbsp;if(RST = '0') then<br>
&nbsp; &nbsp; n_y &lt;= '0';<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;elsif((n_counter &gt;= 0) and<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(n_counter &lt;= 31)) then<br>
&nbsp; &nbsp; n_y &lt;= '1';<br>
&nbsp;&nbsp;elsif((n_counter &gt;= 32) and<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;(n_counter &lt;= 63)) then<br>
&nbsp; &nbsp; n_y &lt;= '0';<br>
&nbsp;&nbsp;else <br>
&nbsp; &nbsp; n_y &lt;= '1';<br>
&nbsp;&nbsp;end if;<br>
end process;<br>
<br>
&nbsp;&nbsp;Y &lt;= n_y;<br>
<br>
end RTL;<br>
<br>
我写的也是乱糟糟的,要下班了,你看看吧!!<br>
<br>
计数器最好用integer型来写比较容易!
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2024-12-24 11:23 , Processed in 0.060246 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表