CLK_HZ : REAL := 33.554432E6 -- 2^25
.
.
.
constant MS_MAX_Cnt : integer := integer(ROUND(CLK_HZ/1000.0)) - 1;
What should be the value of MS_MAX_Cnt, 33,555, 33,554 or 33,553?
I say 33,553, the Aldec simulator says 33,554. Who's right?
What am I missing about the operation of ROUND ?
The definition says it adds 0.5 before taking the FLOOR of positive values. Even with the 0.5 added the FLOOR should make the value 33,554.0 then with the integer conversion 33,554 then minus 1 to give 33,553.
On Friday, September 18, 2020 at 1:25:09 PM UTC-4, Rick C wrote:right.
CLK_HZ : REAL := 33.554432E6 -- 2^25
.
.
.
constant MS_MAX_Cnt : integer := integer(ROUND(CLK_HZ/1000.0)) - 1;
What should be the value of MS_MAX_Cnt, 33,555, 33,554 or 33,553?
I say 33,553, the Aldec simulator says 33,554. Who's right?
What am I missing about the operation of ROUND ?
The definition says it adds 0.5 before taking the FLOOR of positive values. Even with the 0.5 added the FLOOR should make the value 33,554.0 then with the integer conversion 33,554 then minus 1 to give 33,553.
I'm not sure what I was doing wrong, but I added statements to do the above calculation one step at a time and it's getting the right number correctly now with the original statement. So the count is right, but the time value in the simulation is not
CLK_HZ : REAL := 33.554432E6That 2 ps is about two clock cycles out of the 1 ms time period. I was trying to set limits for an assert to automatically check this time. If I can't get the clock rate right, I won't be able to check any timings to full resolution... although I
constant Clock_Half_Period : time := 500 ms / CLK_HZ;
Clk_gen: Clk <= not Clk after Clock_Half_Period;
The clock period measured in the simulator is always 29.8 ns no matter what resolution I set for the simulation time value. With the resolution set to 10 fs I just measured the time of a clock and it is 29,800 ps. It should be 29,802 ps if rounded.
On Friday, September 18, 2020 at 1:25:09 PM UTC-4, Rick C wrote:
CLK_HZ : REAL := 33.554432E6 -- 2^25 . . .
constant MS_MAX_Cnt : integer := integer(ROUND(CLK_HZ/1000.0)) - 1;
What should be the value of MS_MAX_Cnt, 33,555, 33,554 or 33,553?
I say 33,553, the Aldec simulator says 33,554. Who's right?
What am I missing about the operation of ROUND ?
The definition says it adds 0.5 before taking the FLOOR of positive
values. Even with the 0.5 added the FLOOR should make the value 33,554.0 then with the integer conversion 33,554 then minus 1 to give 33,553.
I'm not sure what I was doing wrong, but I added statements to do the above calculation one step at a time and it's getting the right number correctly now with the original statement. So the count is right, but the time value in the simulation is not right.
CLK_HZ : REAL := 33.554432E6
constant Clock_Half_Period : time := 500 ms / CLK_HZ;
Clk_gen: Clk <= not Clk after Clock_Half_Period;
The clock period measured in the simulator is always 29.8 ns no matter what resolution I set for the simulation time value. With the resolution set to 10 fs I just measured the time of a clock and it is 29,800 ps. It should
be 29,802 ps if rounded. That 2 ps is about two clock cycles out of the 1
ms time period. I was trying to set limits for an assert to automatically check this time. If I can't get the clock rate right, I won't be able to check any timings to full resolution... although I suppose the xtal isn't much more accurate than this, slightly lower than 1 clock cycle per ms.
In message <7c23ede7-48f0-48db-bd48-756c93c31d03o@googlegroups.com>
Rick C <gnuarm.deletethisbit@gmail.com> wrote:
On Friday, September 18, 2020 at 1:25:09 PM UTC-4, Rick C wrote:
CLK_HZ : REAL := 33.554432E6 -- 2^25 . . .
constant MS_MAX_Cnt : integer := integer(ROUND(CLK_HZ/1000.0)) - 1;
What should be the value of MS_MAX_Cnt, 33,555, 33,554 or 33,553?
I say 33,553, the Aldec simulator says 33,554. Who's right?
What am I missing about the operation of ROUND ?
The definition says it adds 0.5 before taking the FLOOR of positive values. Even with the 0.5 added the FLOOR should make the value 33,554.0 then with the integer conversion 33,554 then minus 1 to give 33,553.
I'm not sure what I was doing wrong, but I added statements to do the above calculation one step at a time and it's getting the right number correctly now with the original statement. So the count is right, but the time value in the simulation is not right.
CLK_HZ : REAL := 33.554432E6
constant Clock_Half_Period : time := 500 ms / CLK_HZ;
Clk_gen: Clk <= not Clk after Clock_Half_Period;
The clock period measured in the simulator is always 29.8 ns no matter what resolution I set for the simulation time value. With the resolution set to 10 fs I just measured the time of a clock and it is 29,800 ps. It should be 29,802 ps if rounded. That 2 ps is about two clock cycles out of the 1 ms time period. I was trying to set limits for an assert to automatically check this time. If I can't get the clock rate right, I won't be able to check any timings to full resolution... although I suppose the xtal isn't much more accurate than this, slightly lower than 1 clock cycle per ms.
Since VHDL fundamentally works in time, not frequency, why not define
the clock period (or half period) rather than the frequency?
David
You could do your clock as:
ClkProc : process
begin
Clk <= '0', '1' after Clock_Half_Period;
wait for Clock_Period;
end process ClkProc ;
Divide by 2 issues will manifest WRT the placement of the rising edge, however, the time period between rising edges is Clock_Period.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 70:09:08 |
Calls: | 6,656 |
Calls today: | 2 |
Files: | 12,200 |
Messages: | 5,332,148 |
Posted today: | 1 |