Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Community Forums
- :
- Forums
- :
- Vivado RTL Development
- :
- Synthesis
- :
- VHDL CONSTANT calculations using TIME are correct ...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

sritchie

Visitor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-11-2019 08:47 AM

2,518 Views

Registered:
03-29-2018

I have some code which used to work under ISE but doesn't work under Vivado.

I use INTEGERS and TIME types to calculated the size of a Pulse Width Modulation (PWM) register. The calculations are correct when performed by the Modelsim and the Vivado simulator buy are not correct when performed during Synthesis.

CONSTANT CNTR_FREQ : NATURAL := 250E6; CONSTANT PWM_FREQ : NATURAL := 50E3; CONSTANT CNTR_PER1 : TIME := 1 SEC / CNTR_FREQ; CONSTANT PWM_PER1 : TIME := 1 SEC / PWM_FREQ; CONSTANT CNTR_PER2 : REAL := 1.0 / REAL(CNTR_FREQ); CONSTANT PWM_PER2 : REAL := 1.0 / REAL(PWM_FREQ); CONSTANT CNTR_MAX1 : NATURAL := INTEGER((PWM_PER1/(CNTR_PER1*4))*2)/2; CONSTANT CNTR_MAX2 : NATURAL := INTEGER((PWM_PER2/(CNTR_PER2*4.0))*2.0)/2;

CNTR_MAX1 and CNTR MAX2 should return the same number (1250) but when Synthesised CNTR1_MAX returns 63.

Can anyone please explain why the Simulator works correctly but Synthesis does not. Surely they should give the same answer. Both Modelsim and the Xilinx simulators agree.

I have attached a VHDL file that demonstrates this behaviour.

1 Solution

Accepted Solutions

richardhead

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-11-2019 09:04 AM

2,511 Views

Registered:
08-01-2012

Vivado has a history of struggling to synthesis type time properly:

https://forums.xilinx.com/t5/Synthesis/Vivado-incorrect-time-calculation/td-p/740073

https://www.xilinx.com/support/answers/57964.html

I also seem to recall a discussion about some assertions not working inside a function based on type time (was it started by @dpaul24 ? ) but I cant find it.

Xilinx seem to be taking some action on VHDL bugs now - maybe they'll finally fix this one too.

8 Replies

richardhead

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-11-2019 09:04 AM

2,512 Views

Registered:
08-01-2012

Vivado has a history of struggling to synthesis type time properly:

https://forums.xilinx.com/t5/Synthesis/Vivado-incorrect-time-calculation/td-p/740073

https://www.xilinx.com/support/answers/57964.html

I also seem to recall a discussion about some assertions not working inside a function based on type time (was it started by @dpaul24 ? ) but I cant find it.

Xilinx seem to be taking some action on VHDL bugs now - maybe they'll finally fix this one too.

sritchie

Visitor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-11-2019 10:08 AM

2,494 Views

Registered:
03-29-2018

Thanks Richard.

One of the previous posts pointed out that UG901 states TIME is not supported in Vivado so, as someone else said, it would have been preferrable at the very least if Vivado generated a warning to alert the user of the potential Synthesis impact rather than soldier on as if nothing is wrong.

dpaul24

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-12-2019 02:31 AM - edited 03-12-2019 02:55 AM

2,470 Views

Registered:
08-07-2014

I have only used TIME in testbench VHDL codes only. Worked correctly.

As far as I know TIME is not synth, ISE/Vivado shouldn't matter.

------------FPGA enthusiast------------

Consider giving "Kudos" if you like my answer. Please mark my post "Accept as solution" if my answer has solved your problem

drjohnsmith

Teacher

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-12-2019 02:52 AM

2,464 Views

Registered:
07-09-2009

this is correct, you cant synthesise time

<== If this was helpful, please feel free to give Kudos, and close if it answers your question ==>

richardhead

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-13-2019 07:54 AM

2,437 Views

Registered:
08-01-2012

brimdavis

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-13-2019 09:34 AM - edited 03-14-2019 10:57 AM

2,424 Views

Registered:
04-26-2012

@sritchie "UG901 states TIME is not supported in Vivado"

That information in UG901 is incorrect and outdated, as I described a couple of years ago in this post:

Both XST and Vivado support elaboration-time calculations using TIME, but Vivado uses 32 bits for time[1], vs. 64 bits for XST, which can cause various overflow problems with code that used to work in XST ( although I haven't looked to see whether that's exactly what's gone wrong in your specific example.)

**Workaround:** I would suggest using reals for time and period calculations (as done for CNTR_MAX2 ), which I've found to work in both Xilinx synthesizers.

-Brian

[1] IIRC the VHDL LRM says somewhere that ~~TIME~~ integer calculations using TIME should be the same precision as INTEGER; so, for a VHDL synthesizer using 32 bit INTEGERs, this implementation is technically correct; but practically speaking, 32 bit TIME values are rather useless for many computation purposes.

The proper response to this problem would have been for Xilinx either to implement an synthesis error/warning message, or switch over to 64 bit INTEGERs.

Given that they've known about the problem since 2013, it appears they have instead chosen to ignore the issue.

richardhead

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-14-2019 03:34 AM

2,387 Views

Registered:
08-01-2012

brimdavis

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-14-2019 10:52 AM - edited 03-14-2019 10:57 AM

2,362 Views

Registered:
04-26-2012

@richardhead "and is not linked in anyway to the integer type."

My understanding of the VHDL-93 standard is that for expressions involving TIME, a 'link' is established in the sections on type conversion and expressions of type "universal_integer", to wit:

IEEE-STD-1076-1993, Section 7.3.5, lines 534-538, allows that the division of two values of a physical type (such as TIME) is a "convertible universal operand" that can be implicitly converted from a "universal integer" to another integer type.

IEEE-STD-1076-1993, Section 7.5, lines 686-688, states that for a "universal expression" of type "universal integer", the operand and result values are limited to the widest integer range provided by the implementation.

That said, I am a VHDL language user, not a VHDL language specification expert, so my interpretation could be wrong.

I have updated my previous post to read "integer calculations using TIME"

-Brian