在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 3015|回复: 4

奇怪的问题,高人救命啊

[复制链接]
发表于 2004-3-25 14:48:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
将输入的数据用SPI口输出,address和datain都是从上一级ram模块过来的数据,都已经稳定,full为1指示ram满可以开始从spi口输出数据
现在的问题是用maxplus编译时它总是将datain作为无用的信号去掉,请问我的程序错在那里啊
谢谢!!
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity spi is
port(clk:in std_logic;--输入时钟
datain:in std_logic_vector(15 downto 0);--输入数据
address:in std_logic_vector(3 downto 0);--输入地址
reset:in std_logic;--复位信号
full:in std_logic;--指示数据满
emptyut std_logic;--指示数据开始输出
spi_DA12_clkut std_logic;--输出的SPI时钟
spi_DA12_dinut std_logic;--spi输入数据
spi_DA12_cs_n:out std_logic;--spi器件片选信号
spi_DA34_clk:out std_logic;--输出的SPI时钟
spi_DA34_din:out std_logic;--spi输入数据
spi_DA34_cs_n:out std_logic;--spi器件片选信号
ldac_DA12_n:out std_logic; --指示启动ad转换
ldac_DA34_n:out std_logic; --指示启动ad转换        --_n表示低有效
int_n:out std_logic  --向控制器产生中断
);
end spi;
architecture a of spi is
type m_structure is (Idle,Start_spi,DA12_spi,DA34_spi,Start_DA12,START_DA34,DAint);
signal main_machine:m_structure;
signal next_machine:m_structure;
signal data_out:std_logic;--指示数据出
signal main_counter:integer range 18 downto 0;--主计数器
signal temp_data:std_logic_vector(17 downto 0);--SPI输出数据
begin


process(clk)
begin
if rising_edge(clk) then
main_machine<=next_machine;
end if;
end process;--状态机运行
spi_DA34_clk<=not clk;--spi口时钟
spi_DA12_clk<=not clk;
process(reset,clk)
begin
if reset='1' then
next_machine<=Idle;
main_counter<=0;
empty<='1';
data_out<='1';
spi_DA12_din<='1';--spi输入数据
spi_DA12_cs_n<='1';--spi器件片选信号
int_n<='1';
spi_DA34_din<='1';--spi输入数据
spi_DA34_cs_n<='1';--spi器件片选信号
ldac_DA12_n<='1'; --指示启动ad转换
ldac_DA34_n<='1'; --指示启动ad转换
elsif rising_edge(clk) then
case main_machine is
when idle=>
if full='1' then
next_machine<=Start_spi;
data_out<=not data_out;
else
next_machine<=Idle;--next_machine<=Idle;
end if;
when Start_spi=>
empty<=data_out;
case address is
when "0001"=>
main_counter<=0;
temp_data<="01"&datain;
next_machine<=DA12_spi;
when "0011"=>
main_counter<=0;
temp_data<="10"&datain;
next_machine<=DA12_spi;
when "0101"=>
main_counter<=0;
temp_data<="0000"&datain(15 downto 2);
next_machine<=DA34_spi;
when "0111"=>
main_counter<=0;
temp_data<="1000"&datain(15 downto 2);
next_machine<=DA34_spi;
when others=>
next_machine<=Idle;
end case;
when DA12_spi=>
if main_counter<18 then
spi_DA12_cs_n<='0';
spi_DA12_din<=temp_data(17);
temp_data<=temp_data(17 downto 1)&'0';
main_counter<=main_counter+1;
else
spi_DA12_cs_n<='1';
spi_DA12_din<='Z';
main_counter<=0;
next_machine<=Start_DA12;
end if;
when DA34_spi=>
if main_counter<16 then
spi_DA34_cs_n<='0';
spi_DA34_din<=temp_data(17);
temp_data<=temp_data(17 downto 1)&'0';
main_counter<=main_counter+1;
else
spi_DA34_cs_n<='1';
spi_DA34_din<='Z';
main_counter<=0;
next_machine<=Start_DA34;
   end if;
when Start_DA12=>
if main_counter<1 then
ldac_DA12_n<='0';
main_counter<=main_counter+1;
else
ldac_DA12_n<='1';
main_counter<=0;
next_machine<=DAint;
end if;
when Start_DA34=>
if main_counter<1 then
ldac_DA34_n<='0';
main_counter<=main_counter+1;
else
ldac_DA34_n<='1';
main_counter<=0;
next_machine<=DAint;
end if;
when DAint=>
if main_counter<2 then
int_n<='0';
main_counter<=main_counter+1;
else
int_n<='1';
main_counter<=0;
next_machine<=Idle;
end if;
when others=>
next_machine<=Idle;
end case;
end if;
end process;
end a;
发表于 2004-3-25 16:07:09 | 显示全部楼层

奇怪的问题,高人救命啊

俺的感觉:
你的datain只赋给了temp_data,
而temp_data的值好像永远都是0,
所以如此。
你仔细查查,是不是这样
如果是,就是问题所在
如果不是,就再找吧
 楼主| 发表于 2004-3-25 16:34:55 | 显示全部楼层

奇怪的问题,高人救命啊

谢谢版主回复
可是既然datain的值赋给了temp_data
temp_data的值就不应该时零了阿
发表于 2004-3-25 17:10:34 | 显示全部楼层

奇怪的问题,高人救命啊

俺看到的是 temp_data是固定到0啦
你可以仔细看看
好像你把datain和0“与”了一下给temp_data的
 楼主| 发表于 2004-3-25 17:26:09 | 显示全部楼层

奇怪的问题,高人救命啊

谢谢版主
经过仔细检查原来犯了一个极低级的错误
spi_DA12_din<=temp_data(17);
temp_data<=temp_data(17 downto 1)&'0';
应该为
spi_DA12_din<=temp_data(17);
temp_data<=temp_data(16 downto 0)&'0';
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-12 01:43 , Processed in 0.025851 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表