Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem with my code: frequency divider

Status
Not open for further replies.

bob2987

Junior Member level 1
Junior Member level 1
Joined
Feb 20, 2014
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
192
Hi all!

I would like to create a ferquency_divider i write this code but it doesn't work, if anyone find a error.

Thank you.

-----------------------------------------------------------------------


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
23
24
25
26
27
28
29
library ieee;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
 
 
entity diviseur is
    Port ( reset : in STD_LOGIC;
           clk : in STD_LOGIC;
           s : out STD_LOGIC);
end diviseur;
 
architecture Behavioral of diviseur is
signal s1:  std_logic;
signal CPT: std_logic_vector (2 downto 0); 
begin
process(clk,reset)
begin
if reset = '0' then CPT<="000";
    elsif (clk'event and clk='1') then
        if CPT="110" then 
        CPT<="000";
        s1 <= not s1;
        s <= s1;
        else CPT<=CPT+1;
        end if;
end if;
end process;
end Behavioral;



-----------------------------------------------------------------------
 
Last edited by a moderator:

Re: problem with my code

Initialize the signals s and s1 on reset.
Code:
if reset = '0' then CPT<="000";
s1<='0';
s<='0';
 

Mmmh, I was going over that code to test my vhdl reading skills (verilog user here), but I couldn't really find anything. As in, I would expect it to work if you used that on real hardware. All registers initialized to 0 by default and off you go.

On simulation I would expect it to show big red X's, due to a bunch of uninitialized registers ... as pointed out by kommu4946. Hint to the OP: if you simulated it, next time post a screenshot of that simulation. Makes it a lot easier. :)

About the only thing I think I would change is to move that "s <= s1;" outside of that "if CPT="110" then" clause. That way it shows that you are clocking that output signal on every positive edge of the clock signal, not just when the counter rolls over. Which one is considered better vhdl style?
 

About the only thing I think I would change is to move that "s <= s1;" outside of that "if CPT="110" then" clause. That way it shows that you are clocking that output signal on every positive edge of the clock signal, not just when the counter rolls over. Which one is considered better vhdl style?

I would move the "s <= s1;" outside the process, to make it unclocked. The extra register (and delay) when having it inside the process is probably not wanted. The reason for "s1" is that "s" can't be inverted directly, since outputs can't be read.

I also suggest that the OP starts using numeric_std instead of the old non-standard libraries, and changes the type for CPT to "unsigned(2 downto 0)".
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top