Clock

The clock enable module, to slow down the core was an attempt to make this project lookable, without a big success…

clock_vhd

clock.vhd

clock_vhd module

Imports

Imports 2 elements

  • IEEE std_logic_1164 numeric_std

Parameters

Parameters 5 elements

• INPUT_FREQ Type : INTEGER Default : 200_000_000

! @brief Input frequency of the module. This value is needed to deduce the counter limits.

• OUTPUT_FREQ Type : INTEGER Default : 100_000_000

! @brief Output frequency of the module. This value is needed to deduce the counter limits. ! output frequency must be an integer factor of the input, otherwise roundings errors will be issued, ! and the output frequency may not match the requirements.

• DUTY_CYCLE Type : INTEGER Default : 50

! @brief Wanted duty cycle (only possible when division factor is >= 2)

• maxval Type : INTEGER Default : (INPUT_FREQ / OUTPUT_FREQ) - 1

! @brief constant that will be used as the upper limit of the counter.

• threshold Type : INTEGER Default : ((maxval * DUTY_CYCLE) / 100) + 1

! @brief constant that will trigger a change in the output value.

Ports

Ports list 3 elements

Name

Direction

Description

Type

Size

Kind

Polarity

Fanout

clk

Input

! @brief clock input of the core. Must match the INPUT_FREQ generics within some tolerance.

STD_LOGIC

-

Combinatorial

-

Fanout : 0

nRST

Input

! @brief reset input, active low. When held to '0', the system will remain in the reset state until set to '1'.

STD_LOGIC

-

Combinatorial

Negative

Fanout : 0

clk_en

Output

! @brief clock output, divided by the factor INPUT_FREQ / OUTPUT_FREQ and with a duty cycle of DUTY_CYCLE value.

STD_LOGIC

-

Register clk nRST

-

Fanout : 0

Processes

Process list 1 element

• P1 Clocked Clocked by clk Reset by nRST

======================================================================================== ! @brief Process to handle the clock evolution, based on a counter and comparisons.

Signals

Signals list 1 element

Name

Description

Type

Size

Kind

Fanout

count

! @brief counter value.

[maxval + 1 : INTEGER RANGE 0]

Register clk nRST

Fanout : 0

Instantiation templates

Instantiation templates 2 elements

clock_vhd <name> #(
    .INPUT_FREQ  ( 200_000_000),
    .OUTPUT_FREQ ( 100_000_000),
    .DUTY_CYCLE  ( 50),
    .maxval      ((INPUT_FREQ / OUTPUT_FREQ) - 1),
    .threshold   (((maxval * DUTY_CYCLE) / 100) + 1)

)(
    .clk    (i_clk),
    .nRST   (i_nRST),
    .clk_en (i_clk_en)
);
<name>: entity work.clock_vhd
    generic map (
        INPUT_FREQ   =>  200_000_000,
        OUTPUT_FREQ  =>  100_000_000,
        DUTY_CYCLE   =>  50,
        maxval       => (INPUT_FREQ / OUTPUT_FREQ) - 1,
        threshold    => ((maxval * DUTY_CYCLE) / 100) + 1
    )
   port map (
        clk     => i_clk,
        nRST    => i_nRST,
        clk_en  => i_clk_en
    );

Source

Raw source Full file

LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.numeric_std.ALL;

ENTITY clock_vhd IS
    GENERIC (
        --! @brief Input frequency of the module. This value is needed to deduce the counter limits.
        INPUT_FREQ : INTEGER := 200_000_000;
        --! @brief Output frequency of the module. This value is needed to deduce the counter limits.
        --! output frequency must be an integer factor of the input, otherwise roundings errors will be issued,
        --! and the output frequency may not match the requirements.
        OUTPUT_FREQ : INTEGER := 100_000_000;
        --! @brief Wanted duty cycle (only possible when division factor is >= 2)
        DUTY_CYCLE : INTEGER := 50
    );
    PORT (
        --! @brief clock input of the core. Must match the INPUT_FREQ generics within some tolerance.
        clk : IN STD_LOGIC;
        --! @brief reset input, active low. When held to '0', the system will remain in the reset state until set to '1'.
        nRST : IN STD_LOGIC;
        --! @brief clock output, divided by the factor INPUT_FREQ / OUTPUT_FREQ and with a duty cycle of DUTY_CYCLE value.
        clk_en : OUT STD_LOGIC
    );
END ENTITY;

ARCHITECTURE behavioral OF clock_vhd IS

    --! @brief constant that will be used as the upper limit of the counter.
    CONSTANT maxval : INTEGER := (INPUT_FREQ / OUTPUT_FREQ) - 1;
    --! @brief constant that will trigger a change in the output value.
    CONSTANT threshold : INTEGER := ((maxval * DUTY_CYCLE) / 100) + 1;

    --! @brief counter value.
    SIGNAL count : INTEGER RANGE 0 TO maxval + 1;

BEGIN

    --========================================================================================
    --! @brief Process to handle the clock evolution, based on a counter and comparisons.
    --========================================================================================
    P1 : PROCESS (clk, nRST)
    BEGIN

        IF (nRST = '0') THEN
            count <= 0;
            clk_en <= '0';

        ELSIF rising_edge(clk) THEN

            IF (count >= maxval) THEN
                count <= 0;
            ELSE
                count <= count + 1;
            END IF;

            IF (count < threshold) THEN
                clk_en <= '1';
            ELSE
                clk_en <= '0';
            END IF;

        END IF;

    END PROCESS;

END ARCHITECTURE;

clock_tb

clock_tb.vhd

clock_tb testbench


Imports

Imports 2 elements

  • IEEE std_logic_1164 numeric_std

Signals

Signals list 3 elements

Name

Description

Type

Size

Kind

Fanout

nRST_t

STD_LOGIC

-

Combinatorial

Fanout : 0

clk 2 elements

Name

Description

Type

Size

Kind

Fanout

clk_t

STD_LOGIC

-

Combinatorial

Fanout : 0

clk_en_t

STD_LOGIC

-

Register clk rst_n

Fanout : 0

Modules

Modules 1 element

• clock : U1

Connections :

Processes

Process list 2 elements

• P1

-

• P2

-

Source

Raw source Full file

LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.numeric_std.ALL;

ENTITY clock_tb IS
END ENTITY;

ARCHITECTURE behavioral OF clock_tb IS

    SIGNAL clk_t : STD_LOGIC := '0';
    SIGNAL nRST_t : STD_LOGIC := '0';
    SIGNAL clk_en_t : STD_LOGIC := '0';

BEGIN

    U1 : ENTITY work.clock(behavioral)
        GENERIC MAP(
            INPUT_FREQ => 200_000_000,
            OUTPUT_FREQ => 50_000_000,
            DUTY_CYCLE => 75
        )
        PORT MAP(
            clk => clk_t,
            nRST => nRST_t,
            clk_en => clk_en_t
        );

    P1 : PROCESS
    BEGIN
        WAIT FOR 2500 ps;
        clk_t <= NOT clk_t;
    END PROCESS;

    P2 : PROCESS
    BEGIN
        WAIT FOR 10 ns;
        nRST_t <= '1';
    END PROCESS;

END ARCHITECTURE;