Creating one FSM in VHDL with slow CLK

Status
Not open for further replies.

kkdelabaca

Full Member level 2
Joined
Apr 18, 2003
Messages
140
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
1,105
hello,

I'm designing my first code in VHDL to create one UART.
The principal CLK works at 60MHz, and I need divide the principal CLK for decrease the speed of the UART.
It's normal create one process with one divided clk (signal COUNT(1))? or exist other designs more efficients?


architecture fsm_sencilla of UART_TX is
type estado is (S0,S1,S2,S3,D0,D1,D2); -- 7 states
signal estado_pr, sig_estado: estado; -- Present and future State
signal COUNT: unsigned(7 downto 0):= "00000000"; -- Counter to divide the clk
signal Aint, Bint, Cint: std_logic; -- Save inputs in State S3 ('0' sync)

begin
process(clk, rst) begin
if rst='1' then
COUNT <= "00000000";
elsif (clk'event and clk='1') then
COUNT <= COUNT + 1;
end if;
end process;

process(rst, Aint, Bint, Cint, COUNT(1)) begin
if rst='1' then
estado_pr <= S0; elsif (COUNT(1)'event and COUNT(1)='1') then
estado_pr <= sig_estado;
if estado_pr= S2 then Aint <= A;
Bint <= B;
Cint <= C;
end if;
end if;
end process;
 

This is good enough for this speed.
 

you should not divide a clock this way. You should generate a clock enable instead.
 
Both are same. I do not see any issue Only power will differ.
 
you should not divide a clock this way. You should generate a clock enable instead.

Hello!

thank you both!!
How I can generate a clock enable? Because using my code appears some glitches in the serial Output. I can solve them using one clk enable?

Thanks!
 

Both are same. I do not see any issue Only power will differ.

Maybe in an ASIC, but NOT in an FPGA.
A logic driven clock can have all sorts of timing issues and glitches that make the design very vulnrable to temperature. So they are NOT the same.

- - - Updated - - -

Hello!

thank you both!!
How I can generate a clock enable? Because using my code appears some glitches in the serial Output. I can solve them using one clk enable?

Thanks!


Very probably. A clock enable is generated very much the same as you have done for the clock, but you just make it high for 1 clock cycle in the sequence:


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
signal count : unsigned(9 downto 0);
signal en : std_logic;
 
process(clk, rst)
begin
  if rst = '1' then
    en <= '0';
    count <= "0000000000";
  elsif rising_edge(clk) then
    count <= count + 1;
 
    if count = 1023 then
      en <= '1';
    else
      en <= '0';
    end if;
 
    if en = '1' then
      --do something once every 1024 clocks
    end if;
  end if;
end process;

 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…