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.

Generating 2 clock pulses in VHDL

Status
Not open for further replies.

MrMuffins

Newbie level 1
Joined
Feb 14, 2017
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
16
Although I have completed a university course in digital logic, I am new to VHDL design and I am hoping if someone can help me create 2 clock signals which depend on the state of one another.

I am using a 50 MHz clock on a DE2-115 FPGA board that is used to create a 5MHz clock (named dclk) and a second clock named dload which is triggered after 8 dclk cycles. There is a pause (both clocks are 0) between the 8 dclk cycles and the rising edge of dload and another pause after the falling edge of dload and the start of a new set of 8 dclk cycles. I posted the datasheet with a picture of the two clocks and their requirements.

datasheet of the 2 clocks:



My attempt:

Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity comp_dclk is
generic(
    dclk_interval : integer := 20
);
port(
    clk :   in std_logic;           --reference clock, which is 50MHz
    start   :   in std_logic;           --dload starts dclk
    dclk    :   out std_logic;          --desired dclk, 50MHz/20 = 2.5MHz, 20 clk cycles = 1 dclk cycle
    dload :     out std_logic
);
end comp_dclk;

architecture behaviour of comp_dclk is

    signal counter          : integer range 0 to dclk_interval := 0;
    signal dclk_counter : integer range 0 to 8 := 0;
    signal start_dclk       : std_logic := '0'; 
    signal dclk_done_flg : std_logic := '1';

begin

--0.4 us per dclk cycle
--0.4*7+0.2 = 3us 
--8 dclk cycles last 3us
--
--dload period constraint:              min 1.55us 
--actual dload period:                  3us + 35ms

--dload pulse width:                    min 30ns +5 tol (*)
--dload falling edge to 1st dclk delay: min 45ns +5 tol (**)
--dload stays low and dclk cycles for : 3us
--dclk to dload delay:                  min 35ns +5 tol (***)

    dload_proc : process
    begin
        if(dclk_done_flg = '1') then                        --when 8 cycles of dclk is done in dclk_proc, dload process begins
            dclk_done_flg <= '0';                           --resets dclk flag
            wait for 40 ns;                                 --(***)pause required for ink cartridge
            dload <= '1';                                       --dload is 1
            wait for 35 ns;                                 --(*)dload is 1 for 35ns 
            dload <= '0';
            wait for 50 ns;                                 --(**)pause required for ink cartridge
            start_dclk<='1';
        end if;
    end process dload_proc;


    dclk_proc : process(clk)
    begin
        if(clk'event and clk='1' and start_dclk='1') then
            counter <= counter + 1;

            if(counter = dclk_interval) then                --if counter is 20, reset to 0. End of a single dclk cycle
                counter <= 0;
                dclk_counter  <= dclk_counter + 1;      --counts 8 dclk cycles to begin or end dload signal
            end if;

            if(counter < dclk_interval/2) then          --dclk
                dclk <= '1';                                    --if counter is between and including 0  and 9, state is high
            else                                                    --if counter is between and including 10 and 19, state is low
                dclk <= '0';    
            end if;

            if(dclk_counter = 8) then
                start_dclk    <= '0';
                dclk_done_flg <= '1';                       --dload_proc is initiated 
                counter           <= 0;
                dclk_counter  <= 0;
            end if;

        end if;
    end process dclk_proc;

end architecture behaviour;
 
Last edited by a moderator:

Unless this is supposed to be simulation only VHDL the waits are not going to synthesize to anything, e.g. wait for 40 ns;

If you need to do things after a certain amount of time you need to include a counter to count off clocks that meet the minimum required delays.

i.e. 50 MHz clock (20 ns period)
so 40 ns count from 0-1 (40 ns)
for 35 ns count from 0-1 (40 ns)
for 50 ns count from 0-2 (60 ns)

you should just make an FSM that generates the DCLK and the DLOAD control signal.
 

Is your code intended for synthesis ?
Because statements such as:
Code:
if(clk'event and clk='1' and start_dclk='1') then
and
Code:
wait for 40 ns;
Don't describe real life logic...
 

First of, all, I don't think this is going to synthesize-you can't use "wait for" statements, they're normally used in test benches.
Secondly, I didn't look at your code too closely, and there are more than way to do any task, but, personally, I'd probably do this with a state machine.
Thirdly, you didn't really ask a question, you just posted a block of code. Did you simulate this? Did it work?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top