Jaiko
Newbie level 5
Hello,
I want to design 30% duty cycle using VHDL. My clock frequency is 50MHz and frequency divider is 500Hz. Here I attach code for 10% duty cycle. I want change this code from 10% duty cycle to 30% duty cycle. Please someone help me.
Thank you.
[/10% Duty Cycle]
This is for testbench:
I want to design 30% duty cycle using VHDL. My clock frequency is 50MHz and frequency divider is 500Hz. Here I attach code for 10% duty cycle. I want change this code from 10% duty cycle to 30% duty cycle. Please someone help me.
Thank you.
[/10% Duty Cycle]
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.numeric_std.ALL; entity DutyCycle500Hz is port( clock : in STD_LOGIC; clear : in std_logic;-- 50 Mhz pwmout : out STD_LOGIC); end DutyCycle500Hz ; architecture Behavioral of DutyCycle500Hz is signal cnt: integer range 0 to (50000000/500)-1 := 0; constant cmp: integer := (50000000/5000); -- PWM = 10% begin process(clock,clear) begin if (clear = '1') then cnt<=0; elsif rising_edge(clock) then if cnt<(50000000/500)-1 then cnt<=cnt+1; else cnt<=0; end if; end if; end process; pwmout <= '1' when cnt<cmp else '0'; end Behavioral;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 -- TestBench Template LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.numeric_std.ALL; ENTITY DutyCycle500Hz_tb IS END DutyCycle500Hz_tb; ARCHITECTURE behavior OF DutyCycle500Hz_tb IS -- Component Declaration COMPONENT DutyCycle500Hz port( clock : in STD_LOGIC; clear : in std_logic;-- 50 Mhz pwmout : out STD_LOGIC); END COMPONENT; SIGNAL clock : std_logic :='0'; signal clear : std_logic := '0'; SIGNAL pwmout : std_logic; constant clock_period : time:= 20 ns; BEGIN -- Component Instantiation uut: DutyCycle500Hz PORT MAP( clock => clock, clear => clear, pwmout => pwmout ); clock_process :process begin clock <= '0'; wait for clock_period/2; --wait for 10ns clock <= '1'; wait for clock_period/2; --wait for 10ns end process; stim_proc: process begin -- hold reset state for 100ms. wait for 10 ms;clear <='1'; wait for 100 ms;clear <='0'; wait; end process; END;