Hi I need to divide my frequency from 1MHz to 38kHz, will this code help me do that?
entity test is
port( clk:in bit; clkoutut bit);
end test;
architecture behavior of test is
begin
process(clk)
variable cnt : integer range 0 to 26;
begin
if(clk'event and clk='1') then
if(cnt=26)then
cnt:=0;
clkout<='1';
else
cnt := cnt+1;
clkout<='0';
end if;
end if;
end process;
end behavior;
This should give me a frequency of 38,5kHz will this work for an IR transmitter?
Look sharp, the divider factor is 27 rather than 26 in your code, but 26 would be better. Furthermore, you should provide a 50% duty cycle square wave.
Code:
begin
if(clk'event and clk='1') then
if(cnt=12)then -- divide by 13
cnt:=0;
clkout<=NOT clkout; -- divide by 2, generate square wave
else
cnt := cnt+1;
end if;
end if;
Usual RC receivers have about 10-15% relative bandwidth, 38.5 kHz would cause no relevant sensitivity drop.