Internal Prak Ramp Module

Joined
Nov 22, 2010
Messages
1
Reaction score
0
Hi everybody,

I'm Modeling an Internal Prak Ramp, that verifies when a car goes from 'X' to 'Y' floor (forward way) or from 'Y' to 'X' floor (backward way, with "EMERgency" output ON because it is a one way ramp). The Ramp has two sensors and the distance between them are always minor that the car lenght, so no car is lost between the sensors (first floor 'X' then sensor 'a' then sensor 'b' and finally floor 'Y')

here is my code:

Code:
LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY RAMPA2 IS
	PORT (CLK,a,b,RESET: IN std_logic;
		emer,inX,inY: OUT std_logic;
		sent: out integer range 0 to 8);
END;

ARCHITECTURE BEHAVIOR OF RAMPA2 IS
--	State variables for machine sreg
	SIGNAL estado1, next_estado1, estado2, next_estado2, estado3, next_estado3, 
		estado4, next_estado4 : std_logic;
	SIGNAL next_emer,next_inX,next_inY : std_logic;
	signal sentido: integer range 0 to 8 :=4;   --sentido = 0 => backward
									    --sentido = 8 => forward
BEGIN
	PROCESS (CLK, RESET, next_estado1, next_estado2, next_estado3, next_estado4,
		 next_emer, next_inX, next_inY)
	BEGIN
		IF ( RESET='1' ) THEN
			estado1 <= '1';
			estado2 <= '0';
			estado3 <= '0';
			estado4 <= '0';
			emer <= '0';
			inX <= '0';
			inY <= '0';
		ELSIF CLK='1' AND CLK'event THEN
			estado1 <= next_estado1;
			estado2 <= next_estado2;
			estado3 <= next_estado3;
			estado4 <= next_estado4;
			emer <= next_emer;
			inX <= next_inX;
			inY <= next_inY;
			sent <= sentido;
		END IF;
	END PROCESS;

	PROCESS (a,b,estado1,estado2,estado3,estado4,sentido)
	BEGIN

		IF (( a='1' AND b='1' AND  (estado1='1')) OR
		( a='0' AND b='0' AND  (estado1='1')) OR
		( a='0' AND b='0' AND  (estado2='1')) OR
		( a='0' AND b='0' AND  (estado4='1'))) THEN
			next_estado1<='1';
			if ((sentido >0 and sentido< 4) or (sentido >4 and sentido< 8) ) then
				if (a='0' AND b='0' AND  (estado2='1')) then
					sentido<=sentido-1;				
				elsif ( a='0' AND b='0' AND  (estado4='1')) then
					sentido<=sentido+1;
				else
					sentido<=4;
				end if;
			end if;			
		ELSE next_estado1<='0';
		END IF;

		IF (( a='1' AND b='0' AND  (estado1='1')) OR
		( b='1' AND a='0' AND  (estado2='1')) OR
		( a='1' AND b='0' AND  (estado2='1')) OR
		( a='1' AND b='0' AND  (estado3='1'))) THEN
			next_estado2<='1';
			if (sentido= 0 or (sentido >1 and sentido <5) or (sentido >5 and sentido <=8)) then
				if ( a='1' AND b='0' AND  (estado3='1')) then
					sentido<=sentido-1;
				elsif ( a='1' AND b='0' AND  (estado1='1')) then
					sentido<=sentido+1;
				end if;
			end if;	
		ELSE next_estado2<='0';
		END IF;

		IF (( a='1' AND b='1' AND  (estado2='1')) OR
		( a='0' AND b='0' AND  (estado3='1')) OR
		( a='1' AND b='1' AND  (estado3='1')) OR
		( a='1' AND b='1' AND  (estado4='1'))) THEN
			next_estado3<='1';
			if ((sentido >=0 and sentido <2) or (sentido >2 and sentido <6) or (sentido >6 and sentido <=8)) then
				if ( a='1' AND b='1' AND  (estado4='1')) then
					sentido<=sentido-1;
				elsif ( a='1' AND b='1' AND  (estado2='1')) then
					sentido<=sentido+1;
				end if;
			end if;
		ELSE next_estado3<='0';
		END IF;

		IF (( a='0' AND b='1' AND  (estado1='1')) OR
		( a='0' AND b='1' AND  (estado3='1')) OR
		( b='0' AND a='1' AND  (estado4='1')) OR
		( a='0' AND b='1' AND  (estado4='1'))) THEN
			next_estado4<='1';
			if ((sentido >=0 and sentido <3) or (sentido >3 and sentido <7) or (sentido =8)) then
				if ( a='0' AND b='1' AND  (estado1='1')) then
					sentido<=sentido-1;
				elsif ( a='0' AND b='1' AND  (estado3='1')) then
					sentido<=sentido+1;
				end if;
			end if;
		ELSE next_estado4<='0';
		END IF;


		IF (( a='0' AND b='1' AND  (estado1='1')) OR
		( a='0' AND b='0' AND  (estado2='1')) OR
		( a='1' AND b='0' AND  (estado3='1')) OR
		( a='1' AND b='1' AND  (estado4='1'))) THEN
			next_emer<='1';
		ELSE next_emer<='0';
		END IF;

	END PROCESS;

next_inX <= '1' when (a='0' AND b='0' AND  (estado2='1') and sentido = 0) else '0';
next_inY <= '1' when (a='0' AND b='0' AND  (estado4='1') and sentido = 8) else '0';

END BEHAVIOR;

"estado1" means "state1" ("estado2" means "state2" and so on...) because there are some code from state diagram but I am modifiyng that code with the respective tests on ModelSim.

and in the last simulation i got this:

(I'm not able to show the image of the result of the simulation)

and the following error on ModelSim:

# ** Fatal: (vsim-3421) Value 9 is out of range 0 to 8.

and I can't figure it out why... it is suposed 'sentido' just goes from 0 to 8 where 8 means that the car did the right way and 0 means that it was wrong way.

please somebody help me?

Best regards,
RicardoNeves.

PS-I'm sorry about my bad english, but i guess you will understand.
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top