Vmax not reached

Guest #3621107
Hi everyone,

I'm writing a code for a triangular wave generator in vhdl, and I have a 
little issue. I want a signal with Vmax =3.3V and I never reach this 
value, the max is 3.2999...
There is not a really big difference but may will be damaging for what I 
want to simulate with this signal (14 bits ADC).
Do you have any hint to get exactly the 3.3 value, if is it possible?

Thank you!

My code is below:
1
library ieee;
2
use ieee.std_logic_1164 .all;
3
use ieee.std_logic_arith.all;
4
use ieee.std_logic_unsigned.all;
5
use ieee.math_real.all;
6

7
entity test is
8

9
  generic(AMP: real;
10
    OFFSET: real;
11
    FREQ: real);
12
  
13
  port(triangle: out real);
14
  
15
end test;
16

17
architecture archi of test is
18

19
signal tmp : real := 0.0;
20

21
begin
22

23
  P1:process
24
  
25
  constant delta   : real := 1000.0e-12;
26
  constant fin   : time := 1000 ps;
27
  
28
  variable t   : real := 0.0;
29
  variable Vmax    : real := AMP/2.0;
30
  
31
  begin
32
  
33
    loop
34
      
35
      t := t + delta;
36
      tmp <= OFFSET+Vmax*(2.0/math_pi)*arcsin(sin(math_2_pi*FREQ*t));
37
      wait for fin;
38
    
39
    end loop;
40
    
41
    wait;
42
    
43
  end process P1;
44
  
45
  triangle <= tmp;
46
  
47
end archi;
Guest #3623602
angelo wrote:
> I never reach this value, the max is 3.2999
3.2999 is the same as 3.30 but its not expressible with binary digits.
It's the same as 0.5 in binary, a periodic fraction.

Duke

Reply

A question of your own? This thread is over 12 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.