A liittle help with this code, please

Status
Not open for further replies.

MamadJun

Junior Member level 2
Joined
Jan 11, 2011
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Belgium
Activity points
1,612
Dear all

I am not too professional with VHDL and am writing a code.

I write the code also and make it so much readable for u to follow the code.



I made a process which first check if reset is 0 then initial value will be assigned.

If not then check the value " Direction " is right or left or down or up

My question ::sad:
in every these condition I should check that if number is 2 then some thing happens.
the problem is that in line :?: (the line symbol is :? If i dont assign number in the beginning then its not synthesizable
but also when program is running number is changing in another process.

So as u see this is not useful because in the beginning of the process number will be 1 again!!
what should i do to have synthezable code and also not assigning the number in the beginning ?????

:-? : I used reset condition it doesn not affect the synthezibale error

please help




control:
PROCESS( myclk , rst , direction , headH , HeadV )
BEGIN
IF ( rst = '0' or
(
( headH(0) < 4 and headH(1) < 4 )
or
( headH(0) > 636 and headH(1) > 636 )
or
( headV(0) < 4 and headV(1) < 4 )
or
( headV(0) > 476 and headV(1) > 476 )
)
)
THEN
-------------------------initial value
headV <= ( 230 , 233 );
headH <= ( 320 , 323 );
tail1V <= ( 238 , 241 );
tail1H <= ( 314 , 217 );
number <= 1;

ELSIF ( myclk'EVENT AND myclk = '1' ) THEN
-- number <= 1; :?:
CASE direction IS
WHEN right =>
headH(0) <= headH(0) + 4;
headH(1) <= headH(1) + 4;
tail1V <= headv;
tail1H <= headH;
IF ( number = 2 ) THEN
tail2V <= tail1v;
tail2H <= tail1H;
END IF;

WHEN left =>
headH(0) <= headH(0) - 4;
headH(1) <= headH(1) - 4;
tail1V <= headv;
tail1H <= headH;
IF ( number = 2 ) THEN
tail2V <= tail1v;
tail2H <= tail1H;
END IF
;
WHEN up =>
headV(0) <= headV(0) - 4;
headV(1) <= headV(1) - 4;
tail1V <= headv;
tail1H <= headH;
IF ( number = 2 ) THEN
tail2V <= tail1v;
tail2H <= tail1H;
END IF;

WHEN down =>
headV(0) <= headV(0) + 4;
headV(1) <= headV(1) + 4;
tail1V <= headv;
tail1H <= headH;
IF ( number = 2 ) THEN
tail2V <= tail1v;
tail2H <= tail1H;
END IF;

WHEN OTHERS =>
NULL;
END CASE;
END IF;
END PROCESS;
 

looking at the code, the number signal is not set anywhere, only to the constant value 1, are you setting it in another process? You can only set a signal in 1 process (otherwise it is a multiple driver error).
 

No I forgot to copy that:
To be more clear I am trying to write a very simple snake

in one process I am trying to show it on screen and another process try to control the bounders and the length of the snake:

show:
PROCESS ( tempV , tempH , headH , headV , number , tail1V , tail1H , Vactive , Hactive , tail2V , tail2H )
BEGIN

CASE number IS :idea: as u see here I check the length of the snake and based on the length I will check the pixels to show it on
WHEN 1 => :| lenght is 1
IF (
(
-- head of snake
( tempV >= headV(0) AND tempV <= headV(1) AND tempH >= headH(0) AND tempH <= headH(1))
OR
-- tail 1
( tempV >= tail1V(0) AND tempV <= tail1V(1) AND tempH >= tail1H(0) AND tempH <= tail1H(1))
OR
-- one spot e.g. food 1
( 225 >= tempv and tempV >= 222 and tempH <= 323 and tempH >= 320 )

OR
-- borders
(( tempV=479 or tempV=478 or tempV= 477 or tempV =476 or tempV=0 or tempV=1 or tempV=2 or tempV=3) or (tempH=0 or tempH=1 or tempH=2 or tempH=3) or ( tempH=636 or tempH= 637 or tempH=638 or tempH=639))
)
AND
( Hactive='1' and Vactive='1' )
)
THEN
R<=(others=>'1');
G<=(others=>'1');
b<=(others=>'1');
ELSE
R<=(others=>'0');
G<=(others=>'0');
b<=(others=>'0');
END IF;

WHEN 2 => :| length is 2
IF (
(
-- head of snake
( tempV >= headV(0) AND tempV <= headV(1) AND tempH >= headH(0) AND tempH <= headH(1))
OR
-- tail 1
( tempV >= tail1V(0) AND tempV <= tail1V(1) AND tempH >= tail1H(0) AND tempH <= tail1H(1))
OR
-- tail 2
( tempV >= tail2V(0) AND tempV <= tail2V(1) AND tempH >= tail2H(0) AND tempH <= tail2H(1))
OR
-- one spot e.g. food 2
( 27 >= tempv and tempV >= 24 and tempH <= 99 and tempH >= 96 )
OR
-- borders
(( tempV=479 or tempV=478 or tempV= 477 or tempV =476 or tempV=0 or tempV=1 or tempV=2 or tempV=3) or (tempH=0 or tempH=1 or tempH=2 or tempH=3) or ( tempH=636 or tempH= 637 or tempH=638 or tempH=639))
)
AND
( Hactive='1' and Vactive='1' )
)
THEN
R<=(others=>'1');
G<=(others=>'1');
b<=(others=>'0');
ELSE
R<=(others=>'0');
G<=(others=>'0');
b<=(others=>'0');
END IF;

WHEN OTHERS =>
NULL;
END CASE;

END PROCESS;


control:
PROCESS( myclk , rst , direction , headH , HeadV )
BEGIN
IF ( rst = '0' or
(
( headH(0) < 4 or headH(1) < 4 )
or
( headH(0) > 636 and headH(1) > 636 )
or
( headV(0) < 4 or headV(1) < 4 )
or
( headV(0) > 476 and headV(1) > 476 )
)
)
THEN
headV <= ( 230 , 233 );
headH <= ( 320 , 323 );
tail1V <= ( 238 , 241 );
tail1H <= ( 314 , 217 );
number <= 1;

ELSIF ( myclk'EVENT AND myclk = '1' ) THEN

CASE direction IS
WHEN right =>
headH(0) <= headH(0) + 4;
headH(1) <= headH(1) + 4;
tail1V <= headv;
tail1H <= headH;
IF ( number = 2 ) THEN
tail2V <= tail1v;
tail2H <= tail1H;
END IF;
WHEN left =>
headH(0) <= headH(0) - 4;
headH(1) <= headH(1) - 4;
tail1V <= headv;
tail1H <= headH;
IF ( number = 2 ) THEN
tail2V <= tail1v;
tail2H <= tail1H;
END IF;
WHEN up =>
headV(0) <= headV(0) - 4;
headV(1) <= headV(1) - 4;
tail1V <= headv;
tail1H <= headH;
IF ( number = 2 ) THEN
tail2V <= tail1v;
tail2H <= tail1H;
END IF;
WHEN down =>
headV(0) <= headV(0) + 4;
headV(1) <= headV(1) + 4;
tail1V <= headv;
tail1H <= headH;
IF ( number = 2 ) THEN
tail2V <= tail1v;
tail2H <= tail1H;
END IF;
WHEN OTHERS =>
NULL;
END CASE;
END IF;

IF ( 233 = headv(1) and headV(0) = 230 and 323 = headH (1) and headH(0) = 320 ) THEN

number <= 2; :idea: in here i reached the new food for snake so length of snake will be increased
END IF;
END PROCESS;
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…