完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
modelsim底下出现以下问题,网上说是case语句问题,需要将case语句的可能值规定只有0或者1才行,想问问大家这个怎么定义,让case只有01两种值
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity SPI_SLAVE is port ( --RST : in std_logic; --FIN2: in std_logic; CLK: in std_logic; CS : in std_logic; SCLK : in std_logic; MOSI : in std_logic; MISO : out std_logic:='0'; --DATA_OUT : out std_logic_vector(7 downto 0); --DATA_IN : in std_logic_vector(7 downto 0) IGBT_CS : out std_logic:='1'; wave_select : out std_logic_vector(3 downto 0); GPS_SYN_A : out std_logic:='1'; GPS_SYN_OK_A : in std_logic; GPS_SYN_B : out std_logic:='1'; GPS_SYN_OK_B : in std_logic; data_in : in std_logic_vector(31 downto 0); ready : in std_logic; waveout : out std_logic; stop_temp : out std_logic:='1'; state_temp : out std_logic:='1' --时域与频域状态标志 ); end SPI_SLAVE; architecture content of SPI_SLAVE is signal DATA_TEMP_IN : std_logic_vector(15 downto 0):="0000000000000000"; -- -- DATA_TEMP_IN bit15~bit14 bit13 bit12~bit11 bit10 bit7~bit0 -- 00 波形 0 写 数据位 -- 01 対钟 1 读 -- 10 IGBT_CS -- 11 自动发射 00 周期 0 高8位 -- 01 占空比 1 低8位 -- 10 个数 signal DATA_TEMP_OUT : std_logic_vector(15 downto 0):="1001100100000000"; signal wave_temp : std_logic_vector(15 downto 0):="0000000000000000"; -- wave_temp bit3~bit0 -- 0000 GND -- 0001 VCC -- 0010 16Hz -- 0011 8Hz -- 0100 4Hz -- 0101 2Hz -- 0110 1Hz -- 0111 0.5Hz -- 1000 0.25Hz -- 1001 0.125Hz -- 1010 0.0625Hz -- 1011 WM_16Hz -- 1100 WM_8Hz -- 1101 EMGS -- 1110 TM_0.25Hz -- 1111 TM_0.125Hz -- signal igbt_temp : std_logic_vector(15 downto 0):="1000000000000000"; -- igbt_temp bit1 -- 0 停止发射 -- 1 开始发射 -- signal syn_temp : std_logic_vector(15 downto 0):="0100100000000000"; --对钟完成标志 signal syn_temp_0 : std_logic_vector(15 downto 0):="1000100000000000";--对钟偏差高16位 signal syn_temp_1 : std_logic_vector(15 downto 0):="1000100000000000";--对钟偏差低16位 --signal syn_temp_2 : std_logic_vector(15 downto 0):="1000100000000000"; --signal syn_temp_3 : std_logic_vector(15 downto 0):="1000100000000000"; signal auto_temp : std_logic_vector(15 downto 0):="0000000000000000"; signal period : std_logic_vector(15 downto 0):="0000000000000000"; signal duty : std_logic_vector(15 downto 0):="0000000000000000"; --signal auto_count : std_logic_vector(15 downto 0):="0000000000000000"; signal wave : std_logic; signal stop_flag : std_logic; begin p1:process (CS,SCLK) --RESCIVE variable to_01data_temp : std_logic_vector(15 downto 0); variable count: integer range 0 to 17:=0; begin if CS='0' then if SCLK='1'and SCLK'event then --上升沿接受 data_temp(15-count):=MOSI;--mosi为接收端口,输入的数据先进的放入高位 count:=count+1; if count=16 then count:=0; end if; end if; else count:=0; DATA_TEMP_IN <= data_temp; end if; end process p1; p2:process (CS,SCLK) --SEND variable data_temp : std_logic_vector(15 downto 0); variable count: integer range 0 to 17:=0; begin if CS='0' then if SCLK='0'and SCLK'event then--下降沿发送 count:=count+1; if count=16 then count:=0; end if; end if; MISO <=DATA_TEMP_OUT(15-count);--先发送高位,MISO为输出端口,初始发送10011001. else count:=0; end if; end process p2; p3:process(CS,DATA_TEMP_IN,GPS_SYN_OK_A,GPS_SYN_OK_B)--DATA_TEMP_IN <= data_temp=MOSI;输入有zhi variable GPS_SYN_TEMP_A : std_logic:='0'; variable GPS_SYN_TEMP_B : std_logic:='0'; begin if CS'event and (CS='0') and (CS'LAST_VALUE='1') then--CS出现了下降沿,SPI片选信号出现下降 case DATA_TEMP_IN(15 downto 14) is when "00" => case DATA_TEMP_IN(13) is when '1' => --0x20 wave_select <= DATA_TEMP_IN(11 downto 8);--波形选择写入,wave_select=MOSI(3 downto 0) wave_temp(3 downto 0) <= DATA_TEMP_IN(11 downto 8); when '0' => --0x00 DATA_TEMP_OUT <= wave_temp;--发送波形选择 end case; when "01" =>--对钟 case DATA_TEMP_IN(13) is when '1' => --对钟 case DATA_TEMP_IN(9) is when '0' => --spi_senf(0x61)对钟A GPS_SYN_A <= '0'; GPS_SYN_TEMP_A := '1'; syn_temp(12) <= '0';--未完成对钟,当syn_temp(12)=1则对钟完成 when '1' => --spi_senf(0x62)对钟B GPS_SYN_B <= '0'; GPS_SYN_TEMP_B := '1'; syn_temp(13) <= '0';--未完成对钟,当syn_temp(12)=1则对钟完成 end case; when '0' => --对钟偏差 case DATA_TEMP_IN(12) is --spi_senf(0x50)查询syn_temp(4),查询 when '1' => DATA_TEMP_OUT <= syn_temp; when others => case DATA_TEMP_IN(9 downto 8) is --向单片机发送PPS偏差值 when "00" => DATA_TEMP_OUT <= syn_temp_0; -- when "01" => DATA_TEMP_OUT <= syn_temp_1; -- when "10" => -- DATA_TEMP_OUT <= syn_temp_2; -- when "11" => -- DATA_TEMP_OUT <= syn_temp_3; when others => end case; end case; end case; when "10" => case DATA_TEMP_IN(13) is when '1' => case DATA_TEMP_IN(9) is when '1' => --0xA2 igbt_temp(9) <='1'; --发射时,igbt_temp为0x82,并通过SPI向单片机发送 IGBT_CS <='0'; --cs标志位为0的时候发射 when '0' => --0xA0 igbt_temp(9) <='0'; --不发射时,igbt_temp为0x80,并通过SPI向单片机发送 IGBT_CS <='1'; --cs标志位为1的时候停止发射 --stop_temp<='1';--停止自动发射 end case; when '0' => --0x80 发送发射标志 DATA_TEMP_OUT <= igbt_temp; --通过SPI向单片机发送发射状态 end case; when "11" => case DATA_TEMP_IN(13) is when'1'=> case DATA_TEMP_IN(12 downto 11) is when "00" => --取出周期,0xe0xx case DATA_TEMP_IN(10) is when '0' => period(15 downto 8) <=DATA_TEMP_IN(7 downto 0);--周期高8位 auto_temp(15) <='1'; when '1' => --0xe4xx period(7 downto 0) <=DATA_TEMP_IN(7 downto 0);--周期中8位 auto_temp(14) <='1';--周期设置完成标志 end case; when "01" => --周期,0xe8xx case DATA_TEMP_IN(10) is when '0' => duty(15 downto 8) <=DATA_TEMP_IN(7 downto 0);--周期低8位 auto_temp(13) <='1'; when '1' => --0xecxx duty(7 downto 0) <=DATA_TEMP_IN(7 downto 0);--占空比高8位 auto_temp(12) <='1';--占空比设置完成标志 end case; -- when "10" => --占空比0xf0xx -- case DATA_TEMP_IN(10) is -- when '0' => -- duty(15 downto 8) <=DATA_TEMP_IN(7 downto 0);--占空比中间8位 -- auto_temp(11) <='1'; -- when '1' =>--0xf4 -- duty(7 downto 0) <=DATA_TEMP_IN(7 downto 0);--占空比低8位 -- auto_temp(10) <='1';--发射个数设置标志置1 -- -- end case; when "11" => case DATA_TEMP_IN(10) is when '1' => case DATA_TEMP_IN(9) is when '1' =>--fE stop_temp<='0';--启动自动发射 auto_temp(11) <='1'; --自动发射开启标志 state_temp<='0';--时域 when '0' =>--fc stop_temp<='0';--启动自动发射 auto_temp(11) <='1'; --自动发射开启标志 state_temp<='1';--频域 end case; when '0'=> --f8 stop_temp<='1';--关闭自动发射 auto_temp<="0000000000000000"; duty<="0000000000000000"; period<="0000000000000000"; end case; when others=> end case; when'0'=> --auto_temp(9) <='1'发射成功 0xc200 case DATA_TEMP_IN(12 downto 11) is when"00"=> DATA_TEMP_OUT <= duty;--返回占空比值 when"01" => DATA_TEMP_OUT <= period;--返回占空比值 -- when '1'=>--cc -- DATA_TEMP_OUT <= period(15 downto 0);--返占空比低16位值 -- end case; -- when"10" => --d0 DATA_TEMP_OUT <= auto_temp; --返回自动发射标志值 when others => end case; end case; end case; end if; if GPS_SYN_OK_A='0' then--PPS对钟命令已接收到,未完成清零, GPS_SYN_TEMP_A := '0'; syn_temp(12) <= '0';--未完成对钟标志 GPS_SYN_A <= '1'; elsif GPS_SYN_OK_A='1' and GPS_SYN_TEMP_A='0' then--分频器已清零 syn_temp(12) <='1';--分频器已准备好,对钟完成 end if; if GPS_SYN_OK_B='0' then--PPS对钟命令已接收到,未完成清零, GPS_SYN_TEMP_B := '0'; syn_temp(13) <= '0';--未完成对钟标志 GPS_SYN_B <= '1'; elsif GPS_SYN_OK_B='1' and GPS_SYN_TEMP_B='0' then--分频器已清零 syn_temp(13) <='1';--分频器已准备好,对钟完成 end if; end process p3; p4:process(ready) begin if ready='0'and ready'event then--下降沿 syn_temp_0 <= data_in(15 downto 0); syn_temp_1 <= data_in(31 downto 16); end if; end process p4; p5:process(auto_temp,CLK)--利用传下的周期与占空比产生波形 variable counter : std_logic_vector(15 downto 0):=X"0000"; begin if(CLK'event and CLK= '1') then if(counter<="0000000000000000") then counter:=period;--将周期设为计数器周期 else counter:=counter- 1; end if; if(counter>=duty)then--大于占空比计数器翻转 waveout<='0'; else waveout<='1'; end if; --end if; end if; end process p5; --p6:process (wave,auto_temp) --variable cout : std_logic_vector(15 downto 0):=X"0000"; --begin --if(wave'event and wave= '1') then -- if(auto_temp<=x"Fe00") then -- if(cout<=auto_count) then--计自动发射的波形个数,到达预定值,停止。 -- cout := X"0000"; -- --stop_temp<='1';--停止 -- stop_flag<='1'; -- else -- cout := cout + 1; -- stop_flag<='0';--开启 -- end if; -- end if; --end if; --end process p6; end content; |
|
相关推荐
1个回答
|
|
经过自己的瞎搞,问题已经解决
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1404 浏览 1 评论
1198 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
1407 浏览 0 评论
912 浏览 0 评论
2214 浏览 0 评论
1424 浏览 34 评论
5610 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-21 18:54 , Processed in 0.601448 second(s), Total 73, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号