Forum Discussion
Altera_Forum
Honored Contributor
15 years agoVHDL state to entity
Hi,
I have a VHDL design with 8 states. I want to take the state "cur_state" specifically to entity output port. This is not for debug, but a specific customer requirement. Please let me know how to do this. Regards, freak22 Replies
- Altera_Forum
Honored Contributor
--- Quote Start --- You can watch the implemented encoding in the state maschine viewer. One state hot is said to be most effective for FPGA implementations. It uses more state variable registers but less LE's for the state machine logic and achieves highest speed. --- Quote End --- I think it may be more prudent to say can achieve the highest speed. E.g. if you compare a few 32 bit numbers in your state machine speed will drop considerably and then the encoding doesn't really matter that much any more. I try to pre-register the inputs to a state machine, it keeps the transition equations simple (sometimes even readable), easy to simulate (I tend to separate state machines into a separate file) and achieves highest speed. E.g. in a downcounter I set a registered IsZero flag when count is one and we see a count enable. Instead of 32 bits we then have a single IsZero input to the state machine - Altera_Forum
Honored Contributor
--- Quote Start --- You mean, by default the tool uses one-hot encoding. --- Quote End --- You can watch the implemented encoding in the state maschine viewer. One state hot is said to be most effective for FPGA implementations. It uses more state variable registers but less LE's for the state machine logic and achieves highest speed. - Altera_Forum
Honored Contributor
--- Quote Start --- You mean, by default the tool uses one-hot encoding. Regards, Jaseel --- Quote End --- If you have more than 3 states, the default is one hot. - Altera_Forum
Honored Contributor
You mean, by default the tool uses one-hot encoding.
Regards, freak - Altera_Forum
Honored Contributor
What's your motivation for state machine user encoding? You can assume, that the default one state hot encoding is optimized for FPGA synthesis.
- Altera_Forum
Honored Contributor
Thanks a lot Josyb. Its workig.
Regards, freak - Altera_Forum
Honored Contributor
also remove:
they are deprecated and (may) conflict with the numeric_std libraryuse IEEE.std_logic_unsigned.all; use IEEE.std_logic_arith.all; - Altera_Forum
Honored Contributor
swap over n and p for the two outputs. You're trying to assign an integer to the std_logic_vector and slv to the integer.
- Altera_Forum
Honored Contributor
Hi,
Please see my code below (coded as per the current thread) and the error log;
The error log is copied below; ************************************************************************ vhdlan state_machine.vhd Synopsys 1076 VHDL Analyzer Version D-2010.06-SP1-8 -- Aug 13, 2011 Copyright (c) 1991-2010 by Synopsys Inc. ALL RIGHTS RESERVED This program is proprietary and confidential information of Synopsys Inc. and may be used and disclosed only as authorized in a license agreement controlling such use and disclosure. Parsing design file 'state_machine.vhd' Error-[SEQSTMTASSIGNTYPE] Type mismatch state_machine.vhd, 31 SYNTH outn_state <= std_logic_vector(to_unsigned(state'pos(cur_state),3)); ^ The assignment statement target data type does not match the source data type. The target data type is 'Anonymous subtype of INTEGER' and is declared by 'PACKAGE STD.STANDARD'. The source data type is 'STD_LOGIC_VECTOR' and is declared by 'PACKAGE IEEE.STD_LOGIC_1164'. Error-[SEQSTMTASSIGNTYPE] Type mismatch state_machine.vhd, 32 SYNTH outp_state <= state'pos(cur_state); ^ The assignment statement target data type does not match the source data type. The target data type is 'Anonymous subtype of STD_LOGIC_VECTOR' and is declared by 'PACKAGE IEEE.STD_LOGIC_1164'. The source data type is 'UNIVERSAL INTEGER' and is declared by 'PACKAGE STD.STANDARD'. "state_machine.vhd": errors: 2; warnings: 0. ************************************************************************ Please guide me to clear the error. Regards, freaklibrary IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; use IEEE.std_logic_arith.all; use IEEE.numeric_std.all; entity statemachine is port ( clk : in std_logic; rst : in std_logic; proceed : in std_logic; data_out : out std_logic; outn_state : out natural range 0 to 7; outp_state : out std_logic_vector(2 downto 0) ); end entity; architecture SYNTH of statemachine is type state is (IDLE, ST1, ST2, ST3, ST4,ST5, ST6, ST7); attribute syn_enum_encoding: string; attribute syn_enum_encoding of state : type is "000 001 010 011 100 101 110 111"; signal cur_state, nxt_state : state; begin outn_state <= std_logic_vector(to_unsigned(state'pos(cur_state),3)); outp_state <= state'pos(cur_state); - Altera_Forum
Honored Contributor
--- Quote Start --- Is natural data type synthesizable --- Quote End --- Yes, josyb implied this by mentioning the default size of 31 bits. Something like natural range 0 to 7 would be more appropriate for synthesis. But you should consider, that a type with implicite bit definition has some disadvantages in pin assignment.