如何在 Verilog 中拆分两位数
我需要将两位数分开,以便可以单独显示它们。问题是 mod 只适用于 2 的幂的数字。这怎么办?
I need to split a two-digit number up so that I can display them separately. The problem is that mod only works with numbers that are a power of 2. How can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自 http://www.edaboard.com/thread112872.html
From http://www.edaboard.com/thread112872.html
如果这是一个简单的递增值,您应该考虑二进制编码十进制计数器。每个数字需要 4 位,但这使得与 7 段显示器的连接变得更加容易。
如果您需要显示一些任意的十进制值,那么它会变得更加复杂。 GuanoLoco 的解决方案应该适用于 2 位数字输出。存在更有效的算法,但实现并不那么简单。
If this is a simple incrementing value, you should consider Binary Coded Decimal counters. You need 4 bits per digit but it makes interfacing with 7-segment displays much easier.
If you have some arbitrary decimal value you need to display, then it gets more complicated. GuanoLoco's solution should work for a 2 digit output. A more efficient algorithm exists but the implementation is not as straightforward.
一个简单的强力解决方案是使用 if-else 块将您的数字与 10 的倍数进行比较。小于您的数字的最大十倍数是“十”位,差值是“个”位。
也就是说,这是不可扩展的,并且巨大的 if-else 块通常不是好的做法。
A simple brute force solution would be to use an if-else block to compare your number to multiples of 10. The largest multiple of ten that is smaller than your number is the "tens" digit, and the difference is the "ones" digit.
That said, this isn't scalable, and giant if-else blocks are generally not good practice.
相当令人困惑的问题。当你说“显示”时,我立即想到
$display
,因此建模和模拟。出于建模目的,模数没有 2 的幂限制。但即使您指的是综合,一般而言,模数仅适用于 2 的幂也是不正确的。但是,这样做可能不是一个好主意,因为它在硬件上会非常昂贵。
Rather confusinq question. When you say "display", I immediately think
$display
, hence modeling and simulation. There are no powers of 2 restrictions on modulo for modeling purposes.But even if you mean synthesis, it is not true in general that modulo only works with powers of 2. However, doing this is probably not a very good idea, because it would be quite expensive in hardware.