1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
大家好,
我正在测试一个简单的vhdl axample。 我注意到与case语句一起使用的代码(粘贴了bellow)会生成错误,但是当在if / elsif语句中使用相同的代码时,不会报告错误。 知道为什么吗? case和if / elsif之间有区别吗? signal rx_count:unsigned(15 downto 0); case rx_count是 当15 => - 这就产生了“无符号类型与整数文字不匹配”的错误。 如果rx_count = 15那么 - 没有错误 问候, Klemen 以上来自于谷歌翻译 以下为原文 Hello everybody, I am testing a simple vhdl axample. I noticed that the code (pasted bellow) used with case statement generates the error, but when the same code is used in if/elsif statement, no error is reported. Any idea why? Is there a difference between case and if/elsif? signal rx_count : unsigned (15 downto 0); case rx_count is when 15 => -- THIS generatres the "Type unsigned does not match with the integer literal" error. if rx_count = 15 then -- no error Regards, Klemen |
|
相关推荐
5个回答
|
|
你好
您必须将rx_count转换为interger类型才能在案例类型中使用它或 在case语句中使用x“000F”而不是15。 有关case和if else语句之间的差异以及类型,请参阅任何标准VHDL手册。 问候,萨蒂什----------------------------------------------- --- --------------------------------------------请注意 - 如果提供的信息有用,请将答案标记为“接受为解决方案”。给予您认为有用的帖子。感谢.-- ---------------------------- --------------------- ---------------------- 以上来自于谷歌翻译 以下为原文 Hi You have to convert the rx_count either to an interger type to use it in the case type or use when x "000F" instead of 15 in the case statements. Refer any standard VHDL manual for the differences between case and if else statements and about the types. Regards, Satish ---------------------------------------------------------------------------------------------- Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful. Give Kudos to a post which you think is helpful. --------------------------------------------------------------------------------------------- |
|
|
|
fogl写道:
大家好, 我正在测试一个简单的vhdl axample。 我注意到与case语句一起使用的代码(粘贴了bellow)会生成错误,但是当在if / elsif语句中使用相同的代码时,不会报告错误。 知道为什么吗? case和if / elsif之间有区别吗? signal rx_count:unsigned(15 downto 0); case rx_count是 当15 => - 这就产生了“无符号类型与整数文字不匹配”的错误。 如果rx_count = 15那么 - 没有错误 扩展Satish所说的内容: 在15 =>时,case语句中的文字15是一个整数。 当您编写案例时,rx_count是case表达式正在考虑unsigned类型的值。 如果没有类型转换,则无法直接将无符号与整数进行比较。 unsigned和integer不是相关类型。 unsigned是从std_logic_vectorand派生的,integer是一个基类型。 在简单的if情况下,看起来好像是在将unsigned与整数进行比较,因此您可能希望比较失败的方式与case表达式相同。 但是,numeric_std库包含了一些魔力。 “=”运算符(比较)过载。 “重载”意味着操作符或函数可以具有多个定义。 “=”运算符的变体之一是将unsigned与integer进行比较。 由于定义了这种比较,因此rx_count = 15时的比较是合法的。 顺便说一下,关于无符号和有符号类型的一个更有趣/烦人的事情是你不能做一个像rx_count那样的赋值,这也是出于同样的原因。 14这里是一个整数字面值,rx_count是一个无符号信号,在编译时会得到相同的类型不匹配错误。 所以你需要转换:rx_count,分析仪很高兴。 PS:类型转换类似于但不同于类型转换。 ----------------------------是的,我这样做是为了谋生。 以上来自于谷歌翻译 以下为原文 fogl wrote:To expand on what Satish says: The literal 15 in the case statement's when 15 => is an integer. When you write case rx_count is the case expression is considering values of type unsigned. You can't directly compare unsigned to integer without a type conversion. unsigned and integer are not related types. unsigned is derived from std_logic_vector and integer is a base type. In the simple if case, it appears as if you are comparing an unsigned to an integer, so you might expect the comparison to fail in the same way as the case expression. But, the numeric_std library includes some magic. The "=" operator (the comparison) is overloaded. "Overloading" means that an operator or a function can have multiple definitions. One of the variants of the "=" operator is comparing unsigned to integer. Since that comparison is defined, your comparison if rx_count = 15 then is legal. BTW, one of the more interesting/annoying things about the unsigned and signed types is that you can't do an assignment such as rx_count <= 14; and that's for the same reason. 14 here is an integer literal and rx_count is an unsigned signal, and you get the same type mismatch error at compile time. So again you need a conversion: rx_count <= to_integer(14); and the analyzer is happy. PS: a type conversion is similar to, but not the same as, a typecast. ----------------------------Yes, I do this for a living. |
|
|
|
因此有人可能会争辩说,不是重载比较函数,而是检查输入符号的转换函数会更好。
该案例的解决方案是case to_integer(rx_count),它应该摆脱错误。 - 如果提供的信息有用,请将答案标记为“接受为解决方案”。给予您认为有用且回复的帖子。 以上来自于谷歌翻译 以下为原文 So one might argue that instead of an overloaded comparison function a conversion function which checks for the sign of the input would be better. The solution for the case would be case to_integer(rx_count) which should get rid of the error.- Please mark the Answer as "Accept as solution" if information provided is helpful. Give Kudos to a post which you think is helpful and reply oriented. |
|
|
|
muzaffer写道:所以有人可能会争辩说,不是重载比较函数,而是检查输入符号的转换函数会更好。
我不跟随。 该案例的解决方案是case to_integer(rx_count),它应该摆脱错误。 同意,或者更好的是,只需将计数器声明为整数(或自然)并使用它完成。 ----------------------------是的,我这样做是为了谋生。 以上来自于谷歌翻译 以下为原文 muzaffer wrote:I don't follow. The solution for the case would be case to_integer(rx_count) which should get rid of the error.Agreed, or better yet, just declare the counter as an integer (or natural) and be done with it. ----------------------------Yes, I do this for a living. |
|
|
|
如果您对此帖有任何疑问,请告诉我们?
如果您找到问题的解决方案,请标记答案,以便对其他论坛用户有所帮助。 谢谢,AnirudhPS:请将此标记作为答案,以防它有助于解决您的问题。如果帖子引导您找到解决方案,请给予赞誉。 以上来自于谷歌翻译 以下为原文 Let us know if you have any more queries on this post? Please Mark the answer in case you found the solution to your question so that it can be helpful for other forum users. Thanks, Anirudh PS: Please MARK this as an answer in case it helped resolve your query.Give kudos in case the post guided you to a solution. |
|
|
|
只有小组成员才能发言,加入小组>>
2420 浏览 7 评论
2823 浏览 4 评论
Spartan 3-AN时钟和VHDL让ISE合成时出现错误该怎么办?
2294 浏览 9 评论
3374 浏览 0 评论
如何在RTL或xilinx spartan fpga的约束文件中插入1.56ns延迟缓冲区?
2461 浏览 15 评论
有输入,但是LVDS_25的FPGA内部接收不到数据,为什么?
1176浏览 1评论
请问vc707的电源线是如何连接的,我这边可能出现了缺失元件的情况导致无法供电
587浏览 1评论
求一块XILINX开发板KC705,VC707,KC105和KCU1500
451浏览 1评论
2005浏览 0评论
731浏览 0评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 21:30 , Processed in 1.465704 second(s), Total 86, Slave 70 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号