NewANADOLOGIC Hardware Academy is live: 240 free, AI-graded FPGA & SoC questions.Start learning

FPGA & VHDL KnowHow Series1 min read

FPGA Anadologic

๐๐ฎ๐ž๐ฌ๐ญ๐ข๐จ๐ง: How can you assign integer literals (such as 24, 100, etc) to a std_logic_vector type signal in ๐•๐‡๐ƒ๐‹?

๐€๐ง๐ฌ๐ฐ๐ž๐ซ: Assigning integer literals directly to std_logic_vector or unsigned type signals is not allowed and you will get this error from Vivado:

[๐‘†๐‘ฆ๐‘›๐‘กโ„Ž 8-2774] ๐‘ก๐‘ฆ๐‘๐‘’ ๐‘ ๐‘ก๐‘‘_๐‘™๐‘œ๐‘”๐‘–๐‘_๐‘ฃ๐‘’๐‘๐‘ก๐‘œ๐‘Ÿ ๐‘‘๐‘œ๐‘’๐‘  ๐‘›๐‘œ๐‘ก ๐‘š๐‘Ž๐‘ก๐‘โ„Ž ๐‘ค๐‘–๐‘กโ„Ž ๐‘กโ„Ž๐‘’ ๐‘–๐‘›๐‘ก๐‘’๐‘”๐‘’๐‘Ÿ ๐‘™๐‘–๐‘ก๐‘’๐‘Ÿ๐‘Ž๐‘™

[๐‘†๐‘ฆ๐‘›๐‘กโ„Ž 8-2774] ๐‘ก๐‘ฆ๐‘๐‘’ ๐‘ข๐‘›๐‘ ๐‘–๐‘”๐‘›๐‘’๐‘‘ ๐‘‘๐‘œ๐‘’๐‘  ๐‘›๐‘œ๐‘ก ๐‘š๐‘Ž๐‘ก๐‘โ„Ž ๐‘ค๐‘–๐‘กโ„Ž ๐‘กโ„Ž๐‘’ ๐‘–๐‘›๐‘ก๐‘’๐‘”๐‘’๐‘Ÿ ๐‘™๐‘–๐‘ก๐‘’๐‘Ÿ๐‘Ž๐‘™

You need conversion function defined in IEEE ๐๐”๐Œ๐„๐‘๐ˆ๐‚_๐’๐“๐ƒ package. You can assign an integer literal to a ๐ฌ๐ญ๐_๐ฅ๐จ๐ ๐ข๐œ_๐ฏ๐ž๐œ๐ญ๐จ๐ซ with โ€œ๐ญ๐จ_๐ฎ๐ง๐ฌ๐ข๐ ๐ง๐ž๐โ€ function and โ€œ๐ฌ๐ญ๐_๐ฅ๐จ๐ ๐ข๐œ_๐ฏ๐ž๐œ๐ญ๐จ๐ซโ€ type conversion.

๐‘ ๐‘–๐‘”๐‘›๐‘Ž๐‘™ ๐‘›๐‘ข๐‘š_๐‘œย : ๐‘ ๐‘ก๐‘‘_๐‘™๐‘œ๐‘”๐‘–๐‘_๐‘ฃ๐‘’๐‘๐‘ก๐‘œ๐‘Ÿ (7 ๐‘‘๐‘œ๐‘ค๐‘›๐‘ก๐‘œ 0); ๐‘›๐‘ข๐‘š_๐‘œ <= ๐‘ ๐‘ก๐‘‘_๐‘™๐‘œ๐‘”๐‘–๐‘_๐‘ฃ๐‘’๐‘๐‘ก๐‘œ๐‘Ÿ(๐‘ก๐‘œ_๐‘ข๐‘›๐‘ ๐‘–๐‘”๐‘›๐‘’๐‘‘(255, ๐‘›๐‘ข๐‘š_๐‘œโ€™๐‘™๐‘’๐‘›๐‘”๐‘กโ„Ž)); โ€” ๐‘›๐‘ข๐‘š_๐‘œ ๐‘”๐‘’๐‘ก๐‘  ๐‘Ž๐‘ ๐‘ ๐‘–๐‘”๐‘›๐‘’๐‘‘ ๐‘ก๐‘œ 255

But what if you try to assign an integer literal which is more than 8-bits? Then, Vivado trims the upper bits and assign only the lower 8-bits.

๐‘ ๐‘–๐‘”๐‘›๐‘Ž๐‘™ ๐‘›๐‘ข๐‘š_๐‘œย : ๐‘ ๐‘ก๐‘‘_๐‘™๐‘œ๐‘”๐‘–๐‘_๐‘ฃ๐‘’๐‘๐‘ก๐‘œ๐‘Ÿ (7 ๐‘‘๐‘œ๐‘ค๐‘›๐‘ก๐‘œ 0); ๐‘›๐‘ข๐‘š_๐‘œ <= ๐‘ ๐‘ก๐‘‘_๐‘™๐‘œ๐‘”๐‘–๐‘_๐‘ฃ๐‘’๐‘๐‘ก๐‘œ๐‘Ÿ(๐‘ก๐‘œ_๐‘ข๐‘›๐‘ ๐‘–๐‘”๐‘›๐‘’๐‘‘(511, ๐‘›๐‘ข๐‘š_๐‘œโ€™๐‘™๐‘’๐‘›๐‘”๐‘กโ„Ž)); โ€” ๐‘›๐‘ข๐‘š_๐‘œ ๐‘”๐‘’๐‘ก๐‘  ๐‘Ž๐‘ ๐‘ ๐‘–๐‘”๐‘›๐‘’๐‘‘ ๐‘ก๐‘œ 255

What is your method to assign integer literals to ๐ฌ๐ญ๐_๐ฅ๐จ๐ ๐ข๐œ_๐ฏ๐ž๐œ๐ญ๐จ๐ซ types?

Please share your thoughts in comment section.

โ€œ๐‘บ๐’‰๐’‚๐’“๐’Š๐’๐’ˆ ๐’Œ๐’๐’๐’˜๐’๐’†๐’…๐’ˆ๐’† ๐’Š๐’” ๐’•๐’‰๐’† ๐’Ž๐’๐’”๐’• ๐’†๐’‡๐’‡๐’Š๐’„๐’Š๐’†๐’๐’• ๐’๐’†๐’‚๐’“๐’๐’Š๐’๐’ˆ ๐’Ž๐’†๐’•๐’‰๐’๐’…โ€

โ† All posts