KJ said:
Daniel,
You're still leaving much to the imagination by not describing what you're
really after, but at least now you've added some detail. You can simply
count high time and low time of the PWM signal and you'll have all the
information you'll need about the signal, so why do you think you need to
know duty cycle?
If you have a microprocessor in your system anywhere it could easily take
the easily measurable high time and low time numbers and from that compute
the duty cycle. If not and you have an actual need for duty cycle then it
will be of the form:
DC = High time / (High time + Low time)
This 'can' be implemented in VHDL if you want, you'll likely want to scale
the numbers by some factor so that DC is in some integer range instead of 0
to 1.
Kevin Jennings
Thanks. Yes, we have a microcontroller connected to the system, so we
will probably send the high and low time to it and do all calculations.
BUT, I'm just trying to find out if it is easy to do the calculations in
the FPGA.
Question:
If I have two signals of std_logic_vector, is there a way to divide them
without writing my own division routine?
I was experimenting with the code below, but as I expected the synthesis
tool (synplify, Actel, Proasic+) did not like this...
entity testDiv is
port(reset_n, clk: in std_logic;
t,ttot: in std_logic_vector(15 downto 0);
res: out std_logic_vector(31 downto 0)
);
end;
architecture rtl of testDiv is
constant i220: std_logic_vector(15 downto 0):=X"00DC";
signal temp1,temp2: integer range -32768 to 32768;
begin
process(clk, reset_n)
begin
if reset_n='0' then
res<=(others=>'0');
temp1<=0;
temp2<=0;
elsif rising_edge(clk) then
temp1<=conv_integer(i220*t);
temp2<=temp1/conv_integer(ttot)-110;
end if;
end process;
res<=conv_std_logic_vector(temp2,32);
end;