- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm getting weird results when I do integer division.
Frequency is being read in as 60 but the result being stored in var_1b /= 1e9/60 (~1.6E7). Instead the result reported by temp2 is 20522. The division for var_1a is performed correctly. The offending code: shared variable frequency: integer range 0 to 25000 :=0; shared variable var_1a, var_1b, var_1c, var_1d: integer; ... frequency := (to_integer(unsigned(Fin))); var_1a := (1E9/pi_2); var_1b := (1E9/(frequency)); temp <= std_logic_vector(to_unsigned(frequency, 16)); temp2 <= std_logic_vector(to_unsigned(var_1b, 16));Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Instead the result reported by temp2 is 20522 --- Quote End --- Yes, that's expectable when you cast the divison result to 16 Bit unsigned. :( At least 24 Bits are needed to hold the result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That was the issue. Rookie mistake.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
another apparent rookie mistake - the use of shared variables - why?

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