Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Fpga

Status
Not open for further replies.
It's prefectly fine. You can also use hex or decimal literals to set the value. Don't fool around with all those 'ones' and 'zeros' if you don't have to.
 
i actually made a program a while ago which converts hex<>dec<>binary... so the bits arent hard to make but hex would be way better or dec

There are ways to just use hex or dec directly. For example, use a based nurmic literal:

16#fff - 4095 decimal
10#4095 - same as above.

Or just use decimal iterals implicitly

Counter <= 4095;

Counter <= 2e12;

etc.
 
Last edited:
Thanks, i have rewrote it all but get warnings

Code:
----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date:    16:32:16 08/08/2011 
-- Design Name: 
-- Module Name:    BlinkRate - Behavioral 
-- Project Name: 
-- Target Devices: 
-- Tool versions: 
-- Description: 
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: 
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity BlinkRate is
port( Button:	in std_logic;
	   Clock:		in std_logic;
	   Reset:		in std_logic;
	   LED:		out std_logic
);
end BlinkRate;

architecture FSM of BlinkRate is
	signal Count: std_logic_vector(24 downto 0);	
	signal State: std_logic_vector(1 downto 0);
	signal NextState: std_logic_vector(1 downto 0);
begin

   SYNC_PROC:process(Clock, Reset)
   begin	
		if ( Reset='1') then
			  State <= (others => '0');
			  Count <= (others => '0');
		elsif ( Clock'event and  Clock='1') then
			  Count <=  Count + 1;
			  State <=  NextState;
		end if;
   end process;						  	
	
	STATE_PROC:process( State,  Button)
	begin
		case State is
			when "00" => 
				if( Button = '0') then
					 NextState <= "01";
				end if;
			when "01" =>
				if( Button = '0') then
					 NextState <= "10";
				end if;
			when "10" =>
				if( Button = '0') then
					 NextState <= "11";
				end if;
			when "11" =>
				if( Button = '0') then
					 NextState <= "00";
				end if;
			when others =>
			   NextState <= "00";
		end case;
	end process;	

end FSM ;

Skip the warning on LED since this code isnt completed yet...
Code:
WARNING:Xst:1306 - Output <LED> is never assigned.
WARNING:Xst:737 - Found 4-bit latch for signal <NextState>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems.
WARNING:Xst:2677 - Node <NextState_0> of sequential type is unconnected in block <BlinkRate>.
WARNING:Xst:2677 - Node <NextState_1> of sequential type is unconnected in block <BlinkRate>.
WARNING:Xst:2677 - Node <NextState_2> of sequential type is unconnected in block <BlinkRate>.
WARNING:Xst:2677 - Node <NextState_3> of sequential type is unconnected in block <BlinkRate>.
WARNING:Xst:2677 - Node <State_2> of sequential type is unconnected in block <BlinkRate>.
WARNING:Xst:2677 - Node <State_1> of sequential type is unconnected in block <BlinkRate>.
WARNING:Xst:2677 - Node <State_0> of sequential type is unconnected in block <BlinkRate>.
WARNING:Xst:2677 - Node <State_3> of sequential type is unconnected in block <BlinProcess "Synthesize - XST" completed successfully

Why is it saying it found State and NextState to be 4 bits when i create them as 2 bits?
 
Last edited:
Hmmm... not sure. It might be related to the fact that you've created latches. Latches are very bad things. Like the warning says, they are created but incomplete case or if statements. For example, you code:

Code:
when "00" => 
				if( Button = '0') then
					 NextState <= "01";

What is the value of NextState when Button = '1'??? You haven't completely specified the assignment, so you created a latch. To fix this do this

Code:
when "00" => 
				if( Button = '0') then
					 NextState <= "01";
                                                   else
                                                   NextState <= State;

Or you can use a default value for NextState:


Code:
	STATE_PROC:process( State,  Button)
	begin
                Next_State <= State;
		case State is
			when "00" =>

Maybe if you clear this up, the bits will come out right.
 
Last edited:
Thanks yet again, i used the ELSE and was left with these warnings... (these are not errors)

Code:
WARNING:Xst:1306 - Output <LED> is never assigned.
WARNING:Xst:2677 - Node <State_3> of sequential type is unconnected in block <BlinkRate>.
WARNING:Xst:2677 - Node <State_2> of sequential type is unconnected in block <BlinkRate>.
WARNING:Xst:2677 - Node <State_1> of sequential type is unconnected in block <BlinkRate>.
WARNING:Xst:2677 - Node <State_0> of sequential type is unconnected in block <BlinkRate>.

Code:
----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date:    16:32:16 08/08/2011 
-- Design Name: 
-- Module Name:    BlinkRate - Behavioral 
-- Project Name: 
-- Target Devices: 
-- Tool versions: 
-- Description: 
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: 
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity BlinkRate is
port( Button:	in std_logic;
	   Clock:		in std_logic;
	   Reset:		in std_logic;
	   LED:		out std_logic
);
end BlinkRate;

architecture FSM of BlinkRate is
	signal Count: std_logic_vector(24 downto 0);	
	signal State: std_logic_vector(1 downto 0);
	signal NextState: std_logic_vector(1 downto 0);
begin

   SYNC_PROC:process(Clock, Reset)
   begin	
		if ( Reset='1') then
			  State <= (others => '0');
			  Count <= (others => '0');
		elsif ( Clock'event and  Clock='1') then
			  Count <=  Count + 1;
			  State <=  NextState;
		end if;
   end process;						  	
	
	STATE_PROC:process( State,  Button)
	begin
		case State is
			when "00" => 
				if( Button = '0') then
					 NextState <= "01";
				else
					 NextState <= "00";
				end if;
			when "01" =>
				if( Button = '0') then
					 NextState <= "10";
				else
					 NextState <= "01";
				end if;
			when "10" =>
				if( Button = '0') then
					 NextState <= "11";
				else
					 NextState <= "10";
				end if;
			when "11" =>
				if( Button = '0') then
					 NextState <= "00";
				else
					 NextState <= "11";
				end if;
			when others =>
			   NextState <= "00";
		end case;
	end process;	

end FSM ;
 
Last edited:
I think you can ignore those warnings. They say you're not using the signal "State" but you are. Is this a synthesis? What are you using?

You'll get used to ignoring many warnings before you're done.
 
Last edited:
yeah... take a look.. my screen...
 

Attachments

  • screen.jpg
    screen.jpg
    166.3 KB · Views: 156
Just got my Papilio One board... looks so cool. I hand cut and soldered the headers, came out pretty good i think.
 

Attachments

  • paiplio1.jpg
    paiplio1.jpg
    78.6 KB · Views: 166
  • papilio.jpg
    papilio.jpg
    71.2 KB · Views: 165
  • papilio2.jpg
    papilio2.jpg
    23 KB · Views: 155
Tested Out my Blink Led code.. the first one i ever wrote...
Code:
----------------------------------------------------------------------------------
-- Company:        AtomSoftTech
-- Engineer: 	    Jason Lopez
-- 
-- Create Date:    09:41:51 08/01/2011 
-- Design Name:    
-- Module Name:    BlinkLed - Behavioral 
-- Project Name: 
-- Target Devices: 
-- Tool versions: 
-- Description:    Just blink LEDs
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: 
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;


entity BlinkLed is
    Port ( LED_01 : out  STD_LOGIC;
           OSC_IN : in  STD_LOGIC;
			  RESET : in STD_LOGIC);	  
end BlinkLed;

architecture Behavioral of BlinkLed is
	signal state : STD_LOGIC;
	signal count : STD_LOGIC_VECTOR(24 downto 0);
begin

	process(OSC_IN, RESET) is begin
	
	if(RESET = '1') then
	  state <= '0';
	  count <= (others => '0');
	elsif(rising_edge(OSC_IN)) then
		if(count=16000000) then
			state <= not state;
			count <= (others => '0');
		else
			count <= count + 1;
		end if;  
	end if; 
		
	end process;
	
	LED_01 <= state;

end Behavioral;

Video: (Note: RESET is pulled LOW then tied HIGH when i press the button)
 
Last edited by a moderator:
ok new video... blinkRate change rate of blinks :)


Code:
----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date:    16:32:16 08/08/2011 
-- Design Name: 
-- Module Name:    BlinkRate - Behavioral 
-- Project Name: 
-- Target Devices: 
-- Tool versions: 
-- Description: 
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: 
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.numeric_std.ALL;

entity BlinkRate is
port( BTNA:	in std_logic; 
	   CLOCK:	in std_logic;
	   RESET:	in std_logic;
	   LED:		out std_logic
);
end BlinkRate;

architecture FSM of BlinkRate is
	signal Count: std_logic_vector(24 downto 0);	
	signal Rate: std_logic_vector(24 downto 0);	
	signal State: std_logic_vector(1 downto 0) := "00";
	signal NXT_STATE: std_logic_vector(1 downto 0);
	signal LED_STATE : std_logic;
	--signal BTN_STATE : STD_LOGIC;
begin

   SYNC_PROC:process(CLOCK, RESET)
   begin	
		if ( RESET='1') then
			  Count <= (others => '0');
			  LED_STATE <= '0';
		elsif ( CLOCK'event and  CLOCK='1') then
			  Count <=  Count + 1;
			  if(Count = Rate) then
				 LED_STATE <= not LED_STATE;
				 Count <= (others => '0');
			  end if;
           --State <= NXT_STATE;
		end if;
		LED <= LED_STATE;
   end process;			
	
	STATE_PROC:process(State, BTNA)
	begin
		if (  BTNA'event and BTNA='1') then
			State <= NXT_STATE;
		end if;
	
		case State is
			when "00" => 
					 Rate <= std_logic_vector( to_unsigned( 32000000, 25 ));
					 NXT_STATE <= "01";
			when "01" =>
					 Rate <= std_logic_vector( to_unsigned( 16000000, 25 ));
					 NXT_STATE <= "10";
			when "10" =>
					 Rate <= std_logic_vector( to_unsigned( 8000000, 25 ));
					 NXT_STATE <= "11";
			when "11" =>
					 Rate <= std_logic_vector( to_unsigned( 4000000, 25 ));
					 NXT_STATE <= "00";
			when others =>
			   NXT_STATE <= "00";
		end case;
	end process;	

end FSM ;
 
Last edited by a moderator:
Need some help, i tried running my shift register and noticed i want the user to be able to clock the data in instead of using a external clock.. How would i go about controlling the flow with a user generated clock?

To clarify.... do i have to use a Global Clock Pin ? If not then how do i do this ?

Warnings:
WARNING:place:619 - This design is using a Side-BUFG site due to placement constraints on a BUFG, DCM, clock IOB or the
loads of these components. It is recommended that Top and Bottom BUFG sites be used instead of Side-BUFG sites
whenever possible because they can reach every clock region on the device. Side-BUFG sites can reach only clock
regions on the same side of the device and also preclude the use of certain Top and Bottom BUFGs in the same clock
region.
WARNING:par:100 - Design is not completely routed. There are 44 signals that are not
completely routed in this design. See the "shift32.unroutes" file for a list of
all unrouted signals. Check for other warnings in your PAR report that might
indicate why these nets are unroutable. These nets can also be evaluated
in FPGA Editor by selecting "Unrouted Nets" in the List Window.
WARNING:par:283 - There are 1 loadless signals in this design. This design will cause Bitgen to issue DRC warnings.
 
Last edited:
Ok got it working. Here is a 16 bit shift register with CLEAR/RESET (next will be LATCH)

Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.numeric_std.ALL;

entity shift16 is
    Port ( SI : in  STD_LOGIC;
			  SC : in  STD_LOGIC;
           SR : in  STD_LOGIC;
           DB : out  STD_LOGIC_VECTOR (15 downto 0));
end shift16;

architecture Behavioral of shift16 is
	signal tempReg : STD_LOGIC_VECTOR (15 downto 0);
begin

process (SC,SR)
begin

	if(SR = '1') then
	  tempReg <= (others => '0');	  
	elsif(SC'event and SC='1') then
		tempReg <= tempReg(14 downto 0) & SI;
	end if; 	
	
end process;

	DB <= tempReg;
end Behavioral;
 
Need some info... What would you recommend is a good protocol for getting data? Uart or spi? I like both really.

UART works well if you have a serial port on your computer. I have code for a lightweight UART that I use for recreive data only.
 
Yeah i think UART is a good choice. Would be simple to implement on a FPGA, But i dont want to make it auto baud just a simple 19200 bps heh... I have to order some PCBs for a project i want to do. But until then ill play around with this FPGA to see what i can come up with :)
 
But i dont want to make it auto baud just a simple 19200 bps heh.

That's why I made my own. You can find details in my blog.

BTW, in post #105 you asked:

Why is it saying it found State and NextState to be 4 bits when i create them as 2 bits?

It dawned on my that your software is encoding your state machine "one-hot" and that's why you're getting 4 bits instead of 2. That might be default behavior of your software.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top