cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ahmedmohamed_45
Adventurer
Adventurer
4,206 Views
Registered: ‎07-14-2010

IF condition error

HI all,

i am using spartan 3an starter kit and i had a strange response for my code it accepts an input bit , store it in 8 bit shift register and compare the values of the register value with hex AA if it is equal to hex AA it shows the 8 bit register output on leds the problem is that the leds always shows AA which is 10101010 even if there is no input from the input port to the shift register but when i make a default value equal 0  for the input it shows 00000000 so can any body please tell me why when i dont assigne default value to the input it shows hexAA even if the input is not AA , its like that:

 

if (reg_p=x"AA") then

leds<=reg_p;

end if;

 

0 Kudos
Reply
4 Replies
bassman59
Historian
Historian
4,201 Views
Registered: ‎02-25-2008


@ahmedmohamed_45 wrote:

HI all,

i am using spartan 3an starter kit and i had a strange response for my code it accepts an input bit , store it in 8 bit shift register and compare the values of the register value with hex AA if it is equal to hex AA it shows the 8 bit register output on leds the problem is that the leds always shows AA which is 10101010 even if there is no input from the input port to the shift register but when i make a default value equal 0  for the input it shows 00000000 so can any body please tell me why when i dont assigne default value to the input it shows hexAA even if the input is not AA , its like that:

 

if (reg_p=x"AA") then

leds<=reg_p;

end if;

 


Show us the rest of the code around this assignment.

----------------------------Yes, I do this for a living.
0 Kudos
Reply
gszakacs
Professor
Professor
4,198 Views
Registered: ‎08-14-2007

even if there is no input from the input port to the shift register

 

It's not clear what you mean by "no input" in the hardware.  A dangling (unconnected) pin of the FPGA?

In any case, the way your code is written it looks like if the input ever becomes x"AA" then it will transfer

that x"AA" to the LED's and after that the LED's will never change (unless you have another assignment

you didn't show).  How do you initialize reg_p? How do you initialize leds?

 

-- Gabor

-- Gabor
0 Kudos
Reply
ahmedmohamed_45
Adventurer
Adventurer
4,189 Views
Registered: ‎07-14-2010

entity SD_DRIVER is
Port ( clk : in STD_LOGIC;
CD : in STD_LOGIC;
SDO : in STD_LOGIC;
CS : out STD_LOGIC;
SDI : out STD_LOGIC;
leds:out std_logic_vector(7 downto 0):=(others=>'0');
SCK,wr_led,finish_led : out STD_LOGIC:='0');

end SD_DRIVER;

 

---------------------------------------------------

-----------------this is a part of FSM-------

 

if (count_p = 5 and reg_p=x"AA") then ---512 bytes plus 2 bytes CRC
leds<=reg_p";
count_n<=0;
counter_n<=0;
nxt_state<=readSECTOR9;
elsif count_p=5 then
reg_n<=reg_p(6 downto 0)& SDO;--READ operation
counter_n<=counter_p+1;
count_n<=0;
nxt_state<=readSECTOR7;
else
count_n<=count_p+1;
end if;

--------------------------------------------

--------------------------------------------

 

the reg_p normally doesnt reach "AA but the leds shows "AA unless i say

leds:out std_logic_vector(7 downto 0):=(others=>'0');

it shows 00000000

0 Kudos
Reply
gszakacs
Professor
Professor
4,183 Views
Registered: ‎08-14-2007

If you don't have a reset in your FSM process, and the only assignment to leds is:

 

leds<=reg_p"; -- reg_p is always x"AA" when this line is executed

 

then for simulation, leds should be 'U' until it gets assigned the first time

reg_p is x"AA".  For synthesis 'U' means that the synthesis tool can use any value

it feels like.  A smart synthesis tool can then look and see that the only time

you ever assigned a value to leds, it must be x"AA" and therefore replace any

sequential logic with a constant value.  In fact if you looked through your

synthesis messages, I'd be willing to bet that there is an "info" or warning

that says it has replaced your logic with a constant value.

 

If on the other hand you initialize leds to x"00" in the declaration, then the synthesizer

must also start leds up x"00" and thus you would get the behavior you expected.

 

-- Gabor

-- Gabor
0 Kudos
Reply