Forum: Projekte & Code sinus in VERILOG ohne cordic etc.


von Martin Maschmann (Gast)


Lesenswert?

function real Sin;
//input [63:0]  x;
//input real  x;

input x;  //  im Bogenmass
real x;


 real p,t,r,f;
 integer i;

 real condition;


begin

     p= 1.0;
     t= 1.0;
     r = 0.0;
     i = 0;
     f= 1.0;


  while( x > 2.0*3.1415926536)
  x = x -  2.0*3.1415926536;

  while( x < -2.0*3.1415926536)
  x = x +  2.0*3.1415926536;



  while ( (Abs(t) > 1e-5) || (Abs(r) > 1.0))
  begin
      t = p / (f);
      r = r + Phase4(i) * t;
      p = p * x;
      i = i + 1;
      f = f * i;
      if(i == 30)  $finish;

//  $display(" sin x %e t %e r %e p %e loop i  %d f %e  ", x,t,r,p,i,f);
  end //while
  Sin=r;

end

endfunction


////////////////////////////////

function real Real;
input x;
integer x;

begin

Real = x;

end
endfunction

////////////////////////////////

function real Phase4;
input n;
integer n;

integer themod;

begin

themod = mod(n,4);
case(themod)

0: Phase4 = 0.0;
1: Phase4 = 1.0;
2: Phase4 = 0.0;
3: Phase4 = -1.0;
endcase


end
endfunction

////////////////////////////////

function integer mod;
input n,m;
integer n,m;

begin

while(n>=m) begin

n = n-m;
//$display(" mod %d %d", n,m);
end

mod=n;

end
endfunction


/////////////////////////////////


function real Abs ;
input x;
real x;

begin

if(x > 0.0) Abs = x;
else Abs = -1.0*x;

end

endfunction



endmodule

von chris (Gast)


Lesenswert?

Sieht interessant aus. So wie ich es verstehe, ist es ein 
Iterationsalgorithmus. Wie funktioniert er?

von Johann L. (gjlayde) Benutzerseite


Lesenswert?

Ist einfach Taylor mit Entwicklungspunkt 0.

von Ale (Gast)


Lesenswert?

Hast du es versucht zu synthetizieren ?

von J. S. (engineer) Benutzerseite


Lesenswert?

Die Taylorentwicklung konvergiert für grössere Werte Richtung Pi nicht 
so gut, finde ich ich.

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
Noch kein Account? Hier anmelden.