scfor 发表于 2011-7-22 10:53:12

状态机的状态怎么赋初值?急急

type fsm_st is(s0,s1,s2,s3,s4,s5,s6);
像这样的 我想要s0=000,s1=001,s2=010,s3=011,s4=100,s5=101,s6=110 怎么给

scfor 发表于 2011-7-22 11:33:25

没人帮一下么

whhityang 发表于 2011-7-22 12:00:45

抱歉。 以为是C语言的状态机思想呢,对CPLD不懂。

scfor 发表于 2011-7-22 12:06:29

VHDL语言一样可以宏定义么?
#define s0 000
#define s1 001
#define s2 010
#define s3 011
#define s4 100
#define s5 101
#define s6 110
#define s7 111 我需要这样写?

NJ8888 发表于 2011-7-22 12:24:53

TYPE sreg IS (ready,halfrise,maxvalue,fallhalf,halfvalue,halffall,minvalue,rise,fall,risehalf,newcmd);


if currentstate=nextstate then
                                                count<=count+1;
                                                case currentstate is
                                                        when ready=>       
                                                               
                                                               
                                                               
                                                               
                                                                --if RESET='1' then
                                                                nextstate<=halfrise;
                                                                --nextstate<=halffail;
                                                                dactemp<="01111111";
                                                                finishout<='0';
                                                                addrsel<='0';
                                                                --test0<=not test0;
                                                               
                                                        when halfrise=>
                                                                --test1<=not test1;
                                                                processflag<='0';
                                                                DACOUTQ<=dacarray2(count);
                                                                DACOUTI<=254-dacarray2(count);
                                                                if count=14 then
                                                                        dactemp<="11111110";
                                                                        nextstate<=maxvalue;
                                                                else
                                                                        nextstate<=halfrise;
                                                                        dactemp<="01111111";
                                                                end if;
                               
                                                        when halffall=>
                        片段供参考

cpfdianzi 发表于 2011-7-22 13:07:35

不知道你为什么要给状态赋初值,好像vhdl不给状态赋初值就可以直接用了。

scfor 发表于 2011-7-22 13:33:51

回复【5楼】cpfdianzi
不知道你为什么要给状态赋初值,好像vhdl不给状态赋初值就可以直接用了。
-----------------------------------------------------------------------

不赋值的话第一个状态从0开始,以后每个状态+1,但如果我想要s0=001呢?怎么办

cpfdianzi 发表于 2011-7-22 15:50:00

回复【6楼】scfor
-----------------------------------------------------------------------

对于type这种状态的赋值我也不清楚怎么实现,但是如果你实在想要给状态赋值,可以用constant定义状态,这样就可以给它赋值了。

raiden9fox 发表于 2011-9-7 10:11:29

楼主的状态机状态类型是用枚举吗?
给楼主提供一个使用枚举类型定义状态集的方法:
typedef enum sm_CommentCounter_state_type_
{
    sta_CommentCounter_CODE = 0x0000,         //CODE状态
    sta_CommentCounter_SLASH = 0x0001,          //SLASH状态
    sta_CommentCounter_COMMENT = 0x0002,   //COMMENT状态
    sta_CommentCounter_STAR = 0x0003,            //STAR状态
    sta_CommentCounter_NULL = 0xffff               //空状态 --在未定义的驱动关系时,会出现空状态,不过不能响应该状态
}SmCommentcounterState;                              //状态机状态定义
这是一个最简单的注释字符计数器的状态集,楼主可以参考一下~
页: [1]
查看完整版本: 状态机的状态怎么赋初值?急急