QUAD Sine wave in Structured text

Karsten

Member
Join Date
Feb 2006
Location
Odense
Posts
158
Anyone have an examplen on how to generate a sine wave in Structured text.

Help much appreciated, thanks in advance!
 
Methinks resolution?
Option A has a resolution of 2*PI*1000.
Option B has a resolution of 1000.

Code:
   REV := REV + 0.001;
   RESULT := SIN (2*PI*(REV MOD 2.0));

For pure educational reasons, why would you not do the above?
 
I'd probably just grab the one in the Oscat library.

18.9. GEN_SIN
Type Function module Input PT: TIME (period time)
AM: REAL (signal amplitude)
OS: REAL (signal ofset)
DL: REAL (signal delay 0..1 * PT )
Output Q: BOOL (binary output) OUT: REAL (analog output)

GEN_SIN is a sine wave generator with programmable period, adjustable amplitude and signal ofset. A special feature is a adjustable delay so that with multiple generators overlapping signals can be generated. A Binary Output Q passes a logical signal, which is generated phase equal to the sine signal. The input DL is a delay for the output signal. The Delay is spe- cifed with DL * PT. A DL of 0.5 delays the signal by half a period.
 
I'd probably just grab the one in the Oscat library.
Our controller is used for testing purposes. One can change amplitude, frequency, phase and offset on-the-fly without any discontinuity in the position, velocity and acceleration because we ramp values using 5th order polynomials.

BTW, my example above is flawed too. One should never add small floating point numbers to a bigger sum especially of the small floating point numbers can't be represented exactly as a REAL. This is much better.

Code:
    K:=2*PI/1000;  (* DO ONCE *)
    ...
    ...
    N:=N+1;          (* REPEAT THIS *)
    N:=MOD(N,1000);
    RESULT:=SIN(K*N);

In CapinWinky's example setting x to 0 is a major flaw.
 
One should never add small floating point numbers to a bigger sum.

Very true, a standard 32 bit float can only go up to about 8.4 million (2^24 signed) in the mantissa before it loses resolution. For instance, 8388607 + 0.5 will result in 8388607 on most platforms.

In CapinWinky's example setting x to 0 is a major flaw.

How so? It resets the mantissa; the only problem I see is my check should be >= instead of > and that would only matter if 2*PI was 6.383 and SIN(6.383) returned 0 (resulting in two 0 outputs in a row), and I would think most systems would not incorrectly define PI as 3.1415.
 
How so? It resets the mantissa; the only problem I see is my check should be >= instead of > and that would only matter if 2*PI was 6.383 and SIN(6.383) returned 0 (resulting in two 0 outputs in a row), and I would think most systems would not incorrectly define PI as 3.1415.
2*PI=6.283185307179586476925286766559
if the angle is incremented by 0.001 then the first time it will exceed 2*PI is 6.284. When you reset x to 0 you are effectively subtracting 6.284 not 2*PI.

dlweber said:
Were you wanting a quadrature output? I seen your title said QUAD sine wave
I have no idea what the OP is asking for then. If the application is for motion there is a specification call SinCos. In that case just use
Code:
A:=SIN(K*N);  (* A phase *)
B:=COS(K*N); (* B phase *)

Now cycles can be counted and the so can the position within a cycle.
Code:
    Angle=atan(A,B); (* The sin() is the y term *)
 
karsten get yourself the oscat txt version, so you can see what happens.
it is working correct.
if needing quadrature there is also a cos function.
btw it is not very fast as every step costs 1 msecond.
 

Similar Topics

We have a quad monitor setup with FT SE and we are utilizing a header screen at the top of every display. when we open a new page we abort the...
Replies
0
Views
93
Has anyone successfullyrics communicated to an ASCO (automatic transfer switch) Type G controller w/ Emerson quad ethernet module from anow ABC...
Replies
0
Views
1,368
Hello! I have problems with two System Electronics Quad Remote Microstep Drivers. From notes added to them, I know that one don't control motors...
Replies
0
Views
1,857
Does anyone know if any companies make a module to read quadrature encoder signals and provide feedback over Ethernet/IP? I have an application...
Replies
7
Views
2,802
I am attempting to repair a Schiele 400 PLC It has 16 xistor outputs, and 4 FZL 4146 G quad drivers. Does any one have a link as to the pin-outs...
Replies
1
Views
1,891
Back
Top Bottom