Hallo Leute, Bräuchte mal Hilfe (dringend!) um eine Zahl vom Typ Time, vom negativen ins positive umzuwandeln.Also als signed in unsigned konvertieren(aber von typ time).Mir fällt nichts ein. Danke im voraus für eure Hilfe MFG Christian
Hi, time und signed/unsigned sind verschiedene Typen. Willst Du zwischen diesen Typen hin und herkonvertieren oder nur eine Variable vom Typ time auf positiv (time) wandeln?
Hab noch was vergessen. Mir würde auch eine Möglichkeit der Typumwandlung einer Variable vom Typ Time in Typ natural,oder Integer weiterhelfen. Muss für Simulation Bitintervalle mit einem Sollwert überprüfen. Kommen Intervalle zu kurz,erhalte ich beim Vergleich mit Sollwert negative Zeitwerte.Das wäre kein Problem wenn man die Time-Variable irgendwie verändern kann, entweder signed->unsigned,od.gleich Time->integer. Christian
unsigned int Variable1 signed int Variable2 . . . Variable1 = (unsigned int)Variable2 // Variable2 = (signed int)Variable1
Danke für die schnelle Hilfe. Wenns keine Umstände macht hätte ich noch was: Welche Möglichkeit gäbe es denn Typ Time in Typ Integer zu wandeln? MFG Christian
Type Time habe ich noch nicht von gehört, welche Sprache is dass denn?
"Type Time habe ich noch nicht von gehört, welche Sprache is dass denn?" ;-))))))))) das ist VHDL, Time ist ein 'predefined physical type' Bsp für die Konvertierung: architecture convert of test is signal a, c : integer := 20; signal b : time := 1 ns; begin process begin wait for 1 fs; a <= a + 1; b <= a * 1 fs; wait for 1 fs; c <= b / 1 fs; end process; end;
PS: sowas muss man nicht wissen, man findet es bei GOOGLE: Time conversions When writing testbenches, VHDL users may be forced to convert between time and abstract numeric types (integer and real). The simplest conversion is from integer to time: -- Time_value := Int_value * Time_unit; timeout := intmax * 1 ns; Conversion from real to time requires additional typecast (type conversion): -- Time_value := integer(Real_value) * Time_unit; timeout := integer(realmax) * 1 ns; (Please note that if the real value has fractional part that we want to preserve, we have to rescale the value and adjust time unit appropriately.) Conversions in the opposite direction are more difficult because they require division operation. In many cases this operation can be executed without any problems, but quite unexpectedly it can trigger division by zero or overflow problems. The first stage of converting time value to abstract value is unit stripping, which requires division of time value by time unit. This operation yields integer value that can be typecasted to real and rescaled if needed: Int_pico := curr_time / 1 ns * 1000; Real_pico := real(curr_time / 1 ns) * 1000.0; What happens if we have simulation resolution set to a value larger than the divisor used in the conversion? Of course the divisor will be rounded down to zero, which will trigger ‘division by zero’ error and termination of simulation. What happens if the time value (in the divisor units) is greater than 231-1 (e.g. curr_time = 3 sec in our sample code above)? Since the division result is out of range that integers can handle, we will experience overflow. It does not necessarily mean termination of simulation, but incorrect conversion (most significant bit of the division result treated as the sign bit of the integer value).
Hat mich schon gewundert.Das es von der Syntax her falsch war hat ich schon gemerkt.Trotzdem danke. Christian
An Mark Danke für die Antwort. Das sich die Zeittypen bei Division quasi kürzen wußt ich schon.Dacht es gibt irgendwas einfacheres,ähnlich to_integer, halt für Time. Christian
Hi Christian, warum schreibst Du nicht was Du schon weißt, dann muss man nichts posten was schon bekannt ist ?! ;-)
Was ist Dir denn an der Division, wie von Mark beschrieben, zu kompliziert ? Du hast die Zeitbasis entfernt und dafür gerade mal 4 Zeichen etxra schreiben müssen .... naja, "einfach" ist relativ
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.