Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Signal Generator code

 
Thread Tools Search this Thread
Old 11-13-2008, 07:07 PM   #1
Default Signal Generator code


I've written a vhdl code in xilinx that generates an output waveform
based on the input clock. The problem i'm getting is that the code is
running only for the positive edge of the clock pulse whereas i've
coded it (i hope) to work for both positive as well as negative edges
of the clock pulse.

What i mean is that only that portion of the code is executing when
clock is = 1.

Code:
entity sig_gen is Port ( clk : in STD_LOGIC; outp : out STD_LOGIC); end sig_gen; architecture Behavioral of sig_gen is begin process (clk) variable temp1, temp2, temp3, temp4: integer:= 0; begin if (clk = '1') then temp1 := temp1 + 1; temp2 := temp2 + 1; if (temp1 = 1 and temp2 = 1) then outp <= '1'; elsif (temp2 = 3) then temp1 := 0; temp2 := 0; temp3 := 0; temp4 := 0; outp <= '0'; else outp <= '0'; end if; else temp3 := temp3 + 1; temp4 := temp4 + 1; if (temp3 = 2 and temp4 = 2) then outp <= '1'; else outp <= '0'; end if; end if; end process; end Behavioral;

Any help would be appreciated...


coderyogi
  Reply With Quote
Old 11-14-2008, 12:07 AM   #2
kennheinrich@sympatico.ca
 
Posts: n/a
Default Re: Signal Generator code
On Nov 13, 2:07*pm, coderyogi <zape...@gmail.com> wrote:
> I've written a vhdl code in xilinx that generates an output waveform
> based on the input clock. The problem i'm getting is that the code is
> running only for the positive edge of the clock pulse whereas i've
> coded it (i hope) to work for both positive as well as negative edges
> of the clock pulse.
>
> What i mean is that only that portion of the code is executing when
> clock is = 1.
>
>
Code:
> > entity sig_gen is > * * Port ( clk : in *STD_LOGIC; > * * * * * * * * * * * * * outp : out *STD_LOGIC); > end sig_gen; > > architecture Behavioral of sig_gen is > begin > * * * * process (clk) > * * * * variable temp1, temp2, temp3, temp4: integer:= 0; > * * * * begin > * * * * * * * * if (clk = '1') then > * * * * * * * * * * * * temp1 := temp1 + 1; > * * * * * * * * * * * * temp2 := temp2 + 1; > * * * * * * * * * * * * if (temp1 = 1 and temp2 = 1) then > * * * * * * * * * * * * * * * * outp <= '1'; > * * * * * * * * * * * * elsif (temp2 = 3) then > * * * * * * * * * * * * * * * * temp1 := 0; > * * * * * * * * * * * * * * * * temp2 := 0; > * * * * * * * * * * * * * * * * temp3 := 0; > * * * * * * * * * * * * * * * * temp4 := 0; > * * * * * * * * * * * * * * * * outp <= '0'; > * * * * * * * * * * * * else > * * * * * * * * * * * * * * * * outp <= '0'; > * * * * * * * * * * * * end if; > * * * * * * * * else > * * * * * * * * * * * * temp3 := temp3 + 1; > * * * * * * * * * * * * temp4 := temp4 + 1; > * * * * * * * * * * * * if (temp3 = 2 and temp4 = 2) then > * * * * * * * * * * * * * * * * outp <= '1'; > * * * * * * * * * * * * else > * * * * * * * * * * * * * * * * outp <= '0'; > * * * * * * * * * * * * end if; > * * * * * * * * end if; > * * * * end process; > end Behavioral; > >
>
> Any help would be appreciated...


In VHDL, you're allowed to write almost any crazy thing you want and
it will simulate. But only a small subset of the things you can
possibly write actually make sense to get mapped into hardware. A
counter (or other flopped logic) that runs on both clock edges is one
of those describable but not buildable things.

The other mistake you've made is that (for simulation only: do NOT try
to build this for real) you should be using a template like this:

process (clk)
begin
if rising_edge(clk) then
... insert rising edge stuff here
end if;
if falling_edge(clk) then
.. insert falling edge here
end if;
end process;

where rising edge is more or less a shorthand for (clk'event and clk =
'1').

But again, this is for illustration only. Do not get into the habit of
writing double-edge processes at all. Expunge all references to them
in your mind now. Only do this to show a professor that you "get" some
nuance of how the language works, or if you're writing a testbench
that you know is intended only to run in a simulator.

- Kenn


kennheinrich@sympatico.ca
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
I am having trouble editing a signal in a sub program. Haai Hardware 0 08-28-2007 02:58 PM
Need help on Modelsim VHDL syntax? ASAP:) kaji General Help Related Topics 0 03-14-2007 10:43 PM
Need help on a Modelsim VHDL Syntax? ASAP:) kaji Software 0 03-14-2007 10:43 PM
IMHO, Digital SECAM video is better than Analog NTSC video Radium DVD Video 167 10-25-2006 04:16 AM
Convert S-video to RF signal Monkey Monkey DVD Video 10 01-14-2004 08:17 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

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