完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
[C] 纯文本查看 复制代码
LIBRARY ieee;USE ieee.std_logic_1164.all;USE ieee.std_logic_unsigned.all;ENtiTY huxideng2 ISPORT(RESET :IN STD_LOGIC;CLK :IN STD_LOGIC;led:OUT STD_LOGIC);END huxideng2;ARCHITECTURE PWM OF huxideng2 ISSIGNAL Period_us,Period1uS, Period1mS, Period1S: STD_LOGIC;--the period of the calculatersignal counter:integer range 0 to 300;signal pwm:integer range 0 to 64;BEGIN-- ClockPROCESS( RESET, CLK, Period_us, Period1uS, Period1mS )VARIABLE Count : STD_LOGIC_VECTOR(5 DOWNTO 0);VARIABLE Count1 : STD_LOGIC_VECTOR(9 DOWNTO 0);VARIABLE Count2 : STD_LOGIC_VECTOR(9 DOWNTO 0);VARIABLE Count3 : STD_LOGIC_VECTOR(2 DOWNTO 0);VARIABLE pwm: STD_LOGIC_VECTOR(7 DOWNTO 0);BEGIN --Period: 1uS IF( RESET = '1' ) THEN Count := "000000";ELSIF( CLK'EVENT AND CLK='1' ) THENIF( Count>"110000" ) THEN Count := "000000";-- 110000:48 50/50M = 1us count from 0 to 48ELSE Count := Count + 1;END IF;Period1uS <= Count(5);END IF;--Period:0.1us IF(CLK'EVENT AND CLK='1') THEN IF(Count3>"101") THEN Count3 :="000"; ELSE Count3 :=Count3+1; END IF; Period_us <=Count(2); END IF;--Period: 1mS IF( Period1uS'EVENT AND Period1uS='1' ) THEN IF( Count1>"1111100110" ) THEN Count1 := "0000000000"; -- 1111100110:998 1000*1us = 1ms count from 0 to 998ELSE Count1 := Count1 + 1;END IF;Period1mS <= Count1(9);END IF; --Period: 1S IF( Period1mS'EVENT AND Period1mS='1' ) THEN IF( Count2>"1111100110" ) THEN Count2 := "0000000000"; --like aboveELSE Count2 := Count2 + 1;END IF;Period1S <= Count2(9); END IF; END PROCESS;PROCESS(Period_us) --The Period of the pwmBEGIN if rising_edge(Period_us) then if counter=300 then counter<=0; pwm<=pwm+1; if pwm=64 then pwm<=0; end if; else counter<=counter+1; end if; end if;END PROCESS; process(Counter,pwm)begin if counter |
|
相关推荐
1个回答
|
|
帮顶。。。。。
|
|
|
|
只有小组成员才能发言,加入小组>>
2884 浏览 3 评论
27672 浏览 2 评论
3460 浏览 2 评论
3975 浏览 4 评论
基于采用FPGA控制MV-D1024E系列相机的图像采集系统设计
2323 浏览 3 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-5 09:57 , Processed in 0.578465 second(s), Total 80, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号