Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > D-Flip-flop

Reply
Thread Tools

D-Flip-flop

 
 
Ash12
Guest
Posts: n/a
 
      03-21-2005
Hi,

Im looking for bit of help / advice!!!

Im desining a counter for a device and I am using flip flops to do so. Im
using a d-type flip flop then using that flip flop as a component for
other modules. The problem I am getting is when I use the flip flop as a
module I am not getting the output waveforms I am expecting. In fact Im
getting no waveforms!!

Here is the code for my flip flop:

entity dflipflop is
Port ( D : in std_logic;
Clk : in std_logic;
Q : out std_logic;
Q_bar : out std_logic);
end dflipflop;

architecture Behavioral of dflipflop is
begin
process(Clk)
begin
if (Clk'event and Clk = '1') then
Q <= D;
Q_bar <= not(D);

end if;

end process;
end Behavioral;

I then use that code as a component to generate a counter that will divide
by 2, 4, 8, and 16.

For example here is the code for my divide by 2 counter using the above
code as a component:

entity divide_by_two is
Port (Clk : in std_logic;
Clk_out : out std_logic);
end divide_by_two;

architecture Behavioral of divide_by_two is

component dflipflop is
Port ( D : in std_logic;
Clk : in std_logic;
Q : out std_logic;
Q_bar : out std_logic);
end component;

signal D : std_logic;
--signal F : std_logic;
begin

uuu: dflipflop port map(D,Clk,Clk_Out,D);

end Behavioral;

The code is compiling fine. After debuging the code I think the problem
is that my Q_bar is being equal to my D instead of the other way around
but I cannot seem to set D equal to Q_bar.

I am hoping that after looking at this for so long that it is in fact a
simple error on my part and any help would be greatly appreciated.

Please contact me at

 
Reply With Quote
 
 
 
 
antonio bergnoli
Guest
Posts: n/a
 
      03-21-2005
I think if you drive D (port in) with delay it could be work. If you
have to go down to synthesys (FPGA,CPLD) you have to change strategy.


Ash12 ha scritto:
> Hi,
>
> Im looking for bit of help / advice!!!
>
> Im desining a counter for a device and I am using flip flops to do so. Im
> using a d-type flip flop then using that flip flop as a component for
> other modules. The problem I am getting is when I use the flip flop as a
> module I am not getting the output waveforms I am expecting. In fact Im
> getting no waveforms!!
>
> Here is the code for my flip flop:
>
> entity dflipflop is
> Port ( D : in std_logic;
> Clk : in std_logic;
> Q : out std_logic;
> Q_bar : out std_logic);
> end dflipflop;
>
> architecture Behavioral of dflipflop is
> begin
> process(Clk)
> begin
> if (Clk'event and Clk = '1') then
> Q <= D;
> Q_bar <= not(D);
>
> end if;
>
> end process;
> end Behavioral;
>
> I then use that code as a component to generate a counter that will divide
> by 2, 4, 8, and 16.
>
> For example here is the code for my divide by 2 counter using the above
> code as a component:
>
> entity divide_by_two is
> Port (Clk : in std_logic;
> Clk_out : out std_logic);
> end divide_by_two;
>
> architecture Behavioral of divide_by_two is
>
> component dflipflop is
> Port ( D : in std_logic;
> Clk : in std_logic;
> Q : out std_logic;
> Q_bar : out std_logic);
> end component;
>
> signal D : std_logic;
> --signal F : std_logic;
> begin
>
> uuu: dflipflop port map(D,Clk,Clk_Out,D);
>
> end Behavioral;
>
> The code is compiling fine. After debuging the code I think the problem
> is that my Q_bar is being equal to my D instead of the other way around
> but I cannot seem to set D equal to Q_bar.
>
> I am hoping that after looking at this for so long that it is in fact a
> simple error on my part and any help would be greatly appreciated.
>
> Please contact me at
>

 
Reply With Quote
 
 
 
 
Mohammed A khader
Guest
Posts: n/a
 
      03-21-2005

Hi,

Default value of std_logic is 'U' means uninitialize .when simulation
starts value of signal D is 'U' .And feedback logic to your divide by
2 counter is not D_Bar . So not D_Bar again gives 'U'. Hope you
understand this.

Every sequential element must have Reset / Preset. When you power on
your Filp Flop you dont know what is your output . So first Reset it
before you start any computation. Here is the code with the Reset logic
added. Simulate this code you will get the expected output...

entity dflipflop is
Port ( D : in std_logic;
Clk : in std_logic;
Reset : in std_logic;
Q : out std_logic;
Q_bar : out std_logic);
end dflipflop;


architecture Behavioral of dflipflop is
begin
process(Clk,Reset)
begin
if(Reset = '0')then
Q <= '0';
Q_bar <= '1';
elsif (Clk'event and Clk = '1') then
Q <= D;
Q_bar <= not(D);
end if;
end process;
end Behavioral;

entity divide_by_two is
Port (Clk : in std_logic;
Reset : in std_logic;
Clk_out : out std_logic);
end divide_by_two;


architecture Behavioral of divide_by_two is


component dflipflop is
Port ( D : in std_logic;
Clk : in std_logic;
Reset : in std_logic;
Q : out std_logic;
Q_bar : out std_logic);
end component;
signal D : std_logic;
--signal F : std_logic;
begin
uuu: dflipflop port map(D,Clk,Reset,Clk_Out,D);
end Behavioral;

 
Reply With Quote
 
Peter Hermansson
Guest
Posts: n/a
 
      03-22-2005
"Ash12" <> wrote in message news:< alkaboutelectronicequipment.com>...
> Hi,
>
> Im looking for bit of help / advice!!!
>
> Im desining a counter for a device and I am using flip flops to do so. Im
> using a d-type flip flop then using that flip flop as a component for
> other modules. The problem I am getting is when I use the flip flop as a
> module I am not getting the output waveforms I am expecting. In fact Im
> getting no waveforms!!
>
> Here is the code for my flip flop:
>
> entity dflipflop is
> Port ( D : in std_logic;
> Clk : in std_logic;
> Q : out std_logic;
> Q_bar : out std_logic);
> end dflipflop;
>
> architecture Behavioral of dflipflop is
> begin
> process(Clk)
> begin
> if (Clk'event and Clk = '1') then
> Q <= D;
> Q_bar <= not(D);
>
> end if;
>
> end process;
> end Behavioral;
>
> I then use that code as a component to generate a counter that will divide
> by 2, 4, 8, and 16.
>


Hi,

As already suggested, your design needs a reset to be initialized, or
your simulation will never show anything but "X" coming out from the
flip-flop.

Another thought: You seem to have fallen in the same trap as I did
when I started with VHDL i.e. working on a to low abstraction level.
Describing a simple element as a D flip-flop as an entity, does not
utilize the power of VHDL.
Your complete counter may be described in a couple of lines in the
entity where it is needed. That saves you the inconvenience of
declaring a component, instantiate a number of components, mapping the
ports etc etc.

Regards, Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57