Hello,
there exists a group for verilog. YOu might get some answers concerning verilog there. But the principle is the same in VHDL, so this post should still help you. BTW your topic is somehow a FAQ, Google provides several sollutions to this problem.
> module low_high_count(
> input clk,
> input pwm0_signal,
> input reset_n,
> output [31:0] frequency, //embsus GPIO outputs count
> output [31:0] duty_cycle);
> //counts, starting at the first positive edge, the hight time
> always @(posedge pwm0_signal )
It is usually the wrong way to use the signal you like to measure as clock signal in a process.
What you like to do is to oversample the pwm signal with clk and measure how many cycles of clk the signal pwm is high after a rising edge.
Therefore you use best a two rank FF to bring the signal PWM stable in clock domain of signal "clk" (avoid problems with clock domain crossing), use a third ff for edge detection and measure the number of clock cycles the signal in clk-clock domain is set high.
In VHDL this would be:
signal pwm_clk : std_ulogic_vector(1 downto 0);
signal counter : integer range 0 to .....;
process (clk, reset)
if reset=ACTIVE then
pwm_clk <= (others=>'0');
counter <= 0;
elsif rising_edge(clk)
pwm_clk <= pwm_clk(1) & pwm0_signal;
if pwm_clk(2 downto 1) = "01" then
counter <= 0;
elsif pwm_clk(2)='1' then
counter <= counter+1;
end if;
end if;