Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Newb: Help with code !

Reply
Thread Tools

Newb: Help with code !

 
 
Prime
Guest
Posts: n/a
 
      01-01-2005
A happy new year to all !

Hi, I'm trying to do a simple binart count output to a bunch of leds and
running into problems. I am using the Xilinx XC2-XL board, and
programming the XC9572-XL chip. I have attached to this a group of 4 leds
(through a 74HC373). The problem is that instead of a binary output on
the leds I just get random patterns. I have verified that the latch is
correctly being held high for the 373.

I am sure that the leds are correctly wired up, because when I just
output set values to them, they light in the correct binary pattern.

- Do a binary count on the LEDS on the DIO4 Board
-- using XC9572, and a clock input.
-- This is setup for a 1.8MHz clock.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

-- Uncomment the following lines to use the declarations that are
-- provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;

entity LedCount is
Port(
Clock : in std_logic;
Latch : out std_logic;
Leds : out std_logic_vector(7 downto 0);
OBLed : out std_logic
);
end LedCount;

architecture Behavioral of LedCount is
signal Count : std_logic_vector(19 downto 0);
signal LedCount : std_logic_vector(7 downto 0) := x"00";

begin
Latch <= '1';
A: Process(Clock)
begin
if Clock='1' and clock'event then
Count <= Count+1;
end if;
end process;


B: Process(Count)
begin
OBLed <= Count(19);
if (Count = x"FFFFF") then
LedCount <= LedCount + 1;
Leds <= LedCount;
end if;
end process;
end Behavioral;


If anyone can see anything obviously wrong with this I would be most
greatfull.

Also does anyone know any newbie (new to VHDL, I've been doing
electronics and programming for several years now ), guides for VHDL,
especially ones aimed towards the Xilinx chips/toolset.

Cheers.

Phill.
 
Reply With Quote
 
 
 
 
Ralf Hildebrandt
Guest
Posts: n/a
 
      01-01-2005
Prime wrote:

> A: Process(Clock)
> begin
> if Clock='1' and clock'event then
> Count <= Count+1;
> end if;
> end process;


No reset for signal Count?


> B: Process(Count)
> begin
> OBLed <= Count(19);
> if (Count = x"FFFFF") then
> LedCount <= LedCount + 1;
> Leds <= LedCount;
> end if;
> end process;


Again: No reset for LedCount and Leds?

Furthermore you can move the line
OBLed <= Count(19);
out of this process. But this should not change the behavior.

A real problem is the fact, that LedCount and Leds are latches. New
values are assigned to them all the time if (Count = x"FFFFF").
Especially the line
LedCount <= LedCount + 1;
makes trouble, as this is an infinite loop. ("LedCount + 1" is computed
and assigned to LedCount and "LedCount + 1" is computed and assigned ...
and so on) Because of your sensitivity list this infinite loop is
invisible during simlation. During simulation the process is triggered
only once, if Count changes, but in hardware this latch is updated in
the described infinite loop and this is exactly what you see: "random
results", as propagation time of the adder and latch for LedCount decide
how many loops are done until signal Count changes and disables the latch.
Solution: LedCount has to be described as a flipflop (clocked by signal
Clock or by a bit of signal Count).

Ralf
 
Reply With Quote
 
 
 
 
Brad Smallridge
Guest
Posts: n/a
 
      01-02-2005
Hang a clock event around your B process,
put clk in your sensitivity list,
and it should run fine:

B: Process(clk)
begin
if( clk'event and clk='1') then
OBLed <= Count(19);
if (Count = x"FFFFF") then
LedCount <= LedCount + 1;
Leds <= LedCount;
end if;
end if;
end process;

b r a d @ a i v i s i o n . c o m



 
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the difference between code inside a <script> tag and code in the code-behind file? keithb ASP .Net 1 03-29-2006 01:00 AM
Re: help with repeater, how to code it in code-behind page Phil Winstanley [Microsoft MVP ASP.NET] ASP .Net 2 06-25-2004 03:38 AM
help with repeater, how to code it in code-behind page Tee ASP .Net 1 06-24-2004 12:42 PM
Fire Code behind code AND Javascript code associated to a Button Click Event =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?= ASP .Net 4 02-11-2004 07:31 AM
<code>linklist<Item,8> ItemList;</code> help! tone HTML 4 11-19-2003 02:57 PM



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