Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > State encoding

Reply
Thread Tools

State encoding

 
 
Niv
Guest
Posts: n/a
 
      05-04-2007
I have a FSM with 64 states (35 used, 29 spare, or reset states, to
force known binary encoding).
I would like to bring out the 6 bit value of the encoded FSM to a port
for test purposes, so how exactly do I do that easily.

I could assign a unique 6 bit SLV to each state, but that's a bit
tedious!

TIA, Kev P.

 
Reply With Quote
 
 
 
 
Andy
Guest
Posts: n/a
 
      05-07-2007
On May 4, 5:57 am, Niv <kev.pars...@mbda.co.uk> wrote:
> I have a FSM with 64 states (35 used, 29 spare, or reset states, to
> force known binary encoding).
> I would like to bring out the 6 bit value of the encoded FSM to a port
> for test purposes, so how exactly do I do that easily.
>
> I could assign a unique 6 bit SLV to each state, but that's a bit
> tedious!
>
> TIA, Kev P.


It may be tedious, but it is the only way to do it, without creating
your FSM as an SLV to begin with. Note that the decoding logic may
affect the optimal state layout chosen by the synthesis tool.

Andy

 
Reply With Quote
 
 
 
 
Newman
Guest
Posts: n/a
 
      05-07-2007
On May 7, 8:40 am, Andy <jonesa...@comcast.net> wrote:
> On May 4, 5:57 am, Niv <kev.pars...@mbda.co.uk> wrote:
>
> > I have a FSM with 64 states (35 used, 29 spare, or reset states, to
> > force known binary encoding).
> > I would like to bring out the 6 bit value of the encoded FSM to a port
> > for test purposes, so how exactly do I do that easily.

>
> > I could assign a unique 6 bit SLV to each state, but that's a bit
> > tedious!

>
> > TIA, Kev P.

>
> It may be tedious, but it is the only way to do it, without creating
> your FSM as an SLV to begin with. Note that the decoding logic may
> affect the optimal state layout chosen by the synthesis tool.
>
> Andy


Hey Andy,
What about this if one forces the synthesis tool to do binary
encoding?
------------------------------------------------------------------------------------------------------------
type state_typ is (state_0, state_1, state_2, state_3);
signal state : state_typ := state_0;

begin -- behav

-- concurrent process
state_vec <= std_logic_vector(to_unsigned(((state_typ'pos(state ))),
state_vec'LENGTH));

-- Newman

 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      05-07-2007
On May 7, 1:34 pm, Newman <newman5...@yahoo.com> wrote:
> On May 7, 8:40 am, Andy <jonesa...@comcast.net> wrote:
>
>
>
> > On May 4, 5:57 am, Niv <kev.pars...@mbda.co.uk> wrote:

>
> > > I have a FSM with 64 states (35 used, 29 spare, or reset states, to
> > > force known binary encoding).
> > > I would like to bring out the 6 bit value of the encoded FSM to a port
> > > for test purposes, so how exactly do I do that easily.

>
> > > I could assign a unique 6 bit SLV to each state, but that's a bit
> > > tedious!

>
> > > TIA, Kev P.

>
> > It may be tedious, but it is the only way to do it, without creating
> > your FSM as an SLV to begin with. Note that the decoding logic may
> > affect the optimal state layout chosen by the synthesis tool.

>
> > Andy

>
> Hey Andy,
> What about this if one forces the synthesis tool to do binary
> encoding?
> ------------------------------------------------------------------------------------------------------------
> type state_typ is (state_0, state_1, state_2, state_3);
> signal state : state_typ := state_0;
>
> begin -- behav
>
> -- concurrent process
> state_vec <= std_logic_vector(to_unsigned(((state_typ'pos(state ))),
> state_vec'LENGTH));
>
> -- Newman


I don't think the 'pos attribute is synthesizable. Check your
synthesis tool documentation. Even if it does, it may affect the
optimized encoding of the states due to the efficiency of creating
state_vec.

Andy

 
Reply With Quote
 
Newman
Guest
Posts: n/a
 
      05-07-2007
On May 7, 2:51 pm, Andy <jonesa...@comcast.net> wrote:
> On May 7, 1:34 pm, Newman <newman5...@yahoo.com> wrote:
>
>
>
>
>
> > On May 7, 8:40 am, Andy <jonesa...@comcast.net> wrote:

>
> > > On May 4, 5:57 am, Niv <kev.pars...@mbda.co.uk> wrote:

>
> > > > I have a FSM with 64 states (35 used, 29 spare, or reset states, to
> > > > force known binary encoding).
> > > > I would like to bring out the 6 bit value of the encoded FSM to a port
> > > > for test purposes, so how exactly do I do that easily.

>
> > > > I could assign a unique 6 bit SLV to each state, but that's a bit
> > > > tedious!

>
> > > > TIA, Kev P.

>
> > > It may be tedious, but it is the only way to do it, without creating
> > > your FSM as an SLV to begin with. Note that the decoding logic may
> > > affect the optimal state layout chosen by the synthesis tool.

>
> > > Andy

>
> > Hey Andy,
> > What about this if one forces the synthesis tool to do binary
> > encoding?
> > ---------------------------------------------------------------------------*---------------------------------
> > type state_typ is (state_0, state_1, state_2, state_3);
> > signal state : state_typ := state_0;

>
> > begin -- behav

>
> > -- concurrent process
> > state_vec <= std_logic_vector(to_unsigned(((state_typ'pos(state ))),
> > state_vec'LENGTH));

>
> > -- Newman

>
> I don't think the 'pos attribute is synthesizable. Check your
> synthesis tool documentation. Even if it does, it may affect the
> optimized encoding of the states due to the efficiency of creating
> state_vec.
>
> Andy- Hide quoted text -
>
> - Show quoted text -


XST synthesizes it and does a post place and route sim.
Whether it is the optimal thing to do is another question.

-Newman

 
Reply With Quote
 
Mike Treseler
Guest
Posts: n/a
 
      05-07-2007
Newman wrote:

> XST synthesizes it and does a post place and route sim.


Yes 'pos and 'val synthesize ok for constrained values.
But some days, I don't like the looks of:

case my_type_t'val( to_integer(unsigned(adr))) is ...

I have run into this issue when writing code
for an interface with a predefined address slice encoding.
Let's say:

type my_type_t is (load, auto, nom, cal); -- published modes
-- 00 01 10 11 -- published values

In this case, I might write a function like
this to tidy up the mess:

function vec2mode (arg : std_logic_vector)
return my_type_t is
variable argn_v : natural := to_integer(unsigned(arg));
begin
return my_type_t'val(argn_v);
end function vec2mode;

And use it like this:

procedure update_regs is
begin
if wr = '1' then
case vec2mode(adr) is
when load => do_load;
when cal => do_cal;
when nom => do_nom;
when auto => do_auto;
when others => do_nom;
end case;
end if;
end procedure update_regs;

-- Mike Treseler
 
Reply With Quote
 
Newman
Guest
Posts: n/a
 
      05-08-2007
On May 7, 5:43 pm, Mike Treseler <mike_trese...@comcast.net> wrote:
> Newman wrote:
> > XST synthesizes it and does a post place and route sim.

>
> Yes 'pos and 'val synthesize ok for constrained values.
> But some days, I don't like the looks of:
>
> case my_type_t'val( to_integer(unsigned(adr))) is ...
>
> I have run into this issue when writing code
> for an interface with a predefined address slice encoding.
> Let's say:
>
> type my_type_t is (load, auto, nom, cal); -- published modes
> -- 00 01 10 11 -- published values
>
> In this case, I might write a function like
> this to tidy up the mess:
>
> function vec2mode (arg : std_logic_vector)
> return my_type_t is
> variable argn_v : natural := to_integer(unsigned(arg));
> begin
> return my_type_t'val(argn_v);
> end function vec2mode;
>
> And use it like this:
>
> procedure update_regs is
> begin
> if wr = '1' then
> case vec2mode(adr) is
> when load => do_load;
> when cal => do_cal;
> when nom => do_nom;
> when auto => do_auto;
> when others => do_nom;
> end case;
> end if;
> end procedure update_regs;
>
> -- Mike Treseler


Hi Mike,
It looked like Niv wanted/had a "sequential" state machine
implementation and wanted a state vector to output to testpoints. It
seemed that if his implementation looked something like below, the
test state vector could be added in about one line of VHDL. When I
looked at the simplified circuit through the technology viewer, the
state_vec was directly tapped off the output of the state machine flip
flops when the synthesizer was directed to use a sequential
implementation.
I have never before used the pos attribute in synthesizable code,
but had an idea and wanted to see if it would pan out. Mike, I enjoy
your posts, because I view you as a craftsman and in general, your
style is much different from mine.

-Newman


------------------------------------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity state_test is

port (
clk : in std_logic;
reset : in std_logic;
state_vec : out std_logic_vector(1 downto 0)
);

end state_test;

architecture behav of state_test is
type state_typ is (state_0, state_1, state_2, state_3);
signal state : state_typ := state_0;

begin -- behav

-- concurrent
state_vec <=
std_logic_vector(to_unsigned(((state_typ'pos(state ))),state_vec'LENGTH));

sync_proc : process (clk, reset)
begin -- process sync_proc
if reset = '1' then
state <= state_0;
elsif clk'event and clk = '1' then
case state is
when state_0 => state <= state_1;
when state_1 => state <= state_2;
when state_2 => state <= state_3;
when state_3 => state <= state_0;
when others => null;
end case;

end if;
end process sync_proc;
end behav;

 
Reply With Quote
 
Niv
Guest
Posts: n/a
 
      05-08-2007
On 8 May, 14:24, Newman <newman5...@yahoo.com> wrote:
> On May 7, 5:43 pm, Mike Treseler <mike_trese...@comcast.net> wrote:
>
>
>
>
>
> > Newman wrote:
> > > XST synthesizes it and does a post place and route sim.

>
> > Yes 'pos and 'val synthesize ok for constrained values.
> > But some days, I don't like the looks of:

>
> > case my_type_t'val( to_integer(unsigned(adr))) is ...

>
> > I have run into this issue when writing code
> > for an interface with a predefined address slice encoding.
> > Let's say:

>
> > type my_type_t is (load, auto, nom, cal); -- published modes
> > -- 00 01 10 11 -- published values

>
> > In this case, I might write a function like
> > this to tidy up the mess:

>
> > function vec2mode (arg : std_logic_vector)
> > return my_type_t is
> > variable argn_v : natural := to_integer(unsigned(arg));
> > begin
> > return my_type_t'val(argn_v);
> > end function vec2mode;

>
> > And use it like this:

>
> > procedure update_regs is
> > begin
> > if wr = '1' then
> > case vec2mode(adr) is
> > when load => do_load;
> > when cal => do_cal;
> > when nom => do_nom;
> > when auto => do_auto;
> > when others => do_nom;
> > end case;
> > end if;
> > end procedure update_regs;

>
> > -- Mike Treseler

>
> Hi Mike,
> It looked like Niv wanted/had a "sequential" state machine
> implementation and wanted a state vector to output to testpoints. It
> seemed that if his implementation looked something like below, the
> test state vector could be added in about one line of VHDL. When I
> looked at the simplified circuit through the technology viewer, the
> state_vec was directly tapped off the output of the state machine flip
> flops when the synthesizer was directed to use a sequential
> implementation.
> I have never before used the pos attribute in synthesizable code,
> but had an idea and wanted to see if it would pan out. Mike, I enjoy
> your posts, because I view you as a craftsman and in general, your
> style is much different from mine.
>
> -Newman
>
> ---------------------------------------------------------------------------*---------------------------------
> library ieee;
> use ieee.std_logic_1164.all;
> use ieee.numeric_std.all;
>
> entity state_test is
>
> port (
> clk : in std_logic;
> reset : in std_logic;
> state_vec : out std_logic_vector(1 downto 0)
> );
>
> end state_test;
>
> architecture behav of state_test is
> type state_typ is (state_0, state_1, state_2, state_3);
> signal state : state_typ := state_0;
>
> begin -- behav
>
> -- concurrent
> state_vec <=
> std_logic_vector(to_unsigned(((state_typ'pos(state ))),state_vec'LENGTH));
>
> sync_proc : process (clk, reset)
> begin -- process sync_proc
> if reset = '1' then
> state <= state_0;
> elsif clk'event and clk = '1' then
> case state is
> when state_0 => state <= state_1;
> when state_1 => state <= state_2;
> when state_2 => state <= state_3;
> when state_3 => state <= state_0;
> when others => null;
> end case;
>
> end if;
> end process sync_proc;
> end behav;- Hide quoted text -
>
> - Show quoted text -


I'll give that whirl; yes my FSM is that sequential type, but idles in
s0 until a trigger arrives. (Hi ho Silver).

Ta, Niv.

 
Reply With Quote
 
Mike Treseler
Guest
Posts: n/a
 
      05-09-2007
Newman wrote:

> Hi Mike,
> It looked like Niv wanted/had a "sequential" state machine
> implementation and wanted a state vector to output to testpoints.


Yes. My example was a
vector to enumeration decoder.
Niv needs to go enum to vector and you have
connected the dots for him.

> It
> seemed that if his implementation looked something like below, the
> test state vector could be added in about one line of VHDL.


Yes, and as I said in my post,
I find that "one line" a little hard to
read. I prefer to break out a
function to clarify the design intent,
and to add it to my bag of tricks.

> I have never before used the pos attribute in synthesizable code,
> but had an idea and wanted to see if it would pan out.


Good work.

> Mike, I enjoy
> your posts, because I view you as a craftsman and in general, your
> style is much different from mine.


Thanks. I have yet to see two designers
with exactly the same style.
My focus is on clear design intent
and reusable functions, subtypes and procedures.

-- Mike Treseler
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Text File Encoding and converting to Perls internal UTF-8 encoding sln@netherlands.com Perl Misc 2 04-17-2009 11:22 PM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM
changing JVM encoding; setting -Dfile.encoding doesn't work pasmol@plusnet.pl Java 1 10-08-2004 09:50 PM
Encoding.Default and Encoding.UTF8 Hardy Wang ASP .Net 5 06-09-2004 04:04 PM
State machine: how to stay in a state? David Lamb VHDL 1 09-15-2003 05:24 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57