I'm working on some VHDL PWM code and need some guidance.
- Does the max_counter check need to be at the end so that 100% duty cycle is achieved?
- What can be done to speed up this routine (I want to run close to 300 Mhz)? Can I have the LSB drive the rest of the counter to improve performance? Is there a way to use more Boolean comparisons to speed it up?
I'm very new to FPGAs and VHDL so any help would be very much appreciated.
- Garrett
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Generic_PWM_x1 is
port(
clk: in std_logic;
pwm_var: in std_logic_vector(19 downto 0);
pwm_out: out std_logic
);
end Generic_PWM_x1;
architecture Behavioral of Generic_PWM_x1 is
signal counter: std_logic_vector(19 downto 0):= (others=>'0');
signal max_counter: std_logic_vector(19 downto 0):= (others=>'1');
begin
process(clk)
begin
if rising_edge(clk) then
counter <= std_logic_vector( unsigned(counter) + 1 );
if counter=max_counter then
counter<=(others=>'0');
else
if counter<pwm_var then
pwm_out<='1';
else
pwm_out<='0';
end if;
end if;
end if;
end process;
end Behavioral;
Question
Garrett
I'm working on some VHDL PWM code and need some guidance.
- Does the max_counter check need to be at the end so that 100% duty cycle is achieved?
- What can be done to speed up this routine (I want to run close to 300 Mhz)? Can I have the LSB drive the rest of the counter to improve performance? Is there a way to use more Boolean comparisons to speed it up?
I'm very new to FPGAs and VHDL so any help would be very much appreciated.
- Garrett
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity Generic_PWM_x1 is port( clk: in std_logic; pwm_var: in std_logic_vector(19 downto 0); pwm_out: out std_logic ); end Generic_PWM_x1; architecture Behavioral of Generic_PWM_x1 is signal counter: std_logic_vector(19 downto 0):= (others=>'0'); signal max_counter: std_logic_vector(19 downto 0):= (others=>'1'); begin process(clk) begin if rising_edge(clk) then counter <= std_logic_vector( unsigned(counter) + 1 ); if counter=max_counter then counter<=(others=>'0'); else if counter<pwm_var then pwm_out<='1'; else pwm_out<='0'; end if; end if; end if; end process; end Behavioral;
Link to comment
Share on other sites
8 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.