/* Copyright 1996 ** by ** The Board of Trustees of the ** Leland Stanford Junior University. ** All rights reserved. ** ** ** Work supported by the U.S. Department of Energy under contract ** DE-AC03-76SF00515. ** ** Disclaimer Notice ** ** The items furnished herewith were developed under the sponsorship ** of the U.S. Government. Neither the U.S., nor the U.S. D.O.E., nor the ** Leland Stanford Junior University, nor their employees, makes any war- ** ranty, express or implied, or assumes any liability or responsibility ** for accuracy, completeness or usefulness of any information, apparatus, ** product or process disclosed, or represents that its use will not in- ** fringe privately-owned rights. Mention of any product, its manufactur- ** er, or suppliers shall not, nor is it intended to, imply approval, dis- ** approval, or fitness for any particular use. The U.S. and the Univer- ** sity at all times retain the right to use and disseminate the furnished ** items for any purpose whatsoever. Notice 91 02 01 */ /*============================================================================= Abs: Phase and Amplitude Control (PAC) Calculations. Name: subpac.c subpacIQ - Set I and Q Waveforms from Phase and # Cycles subpacTime - Set Time Array for I and Q Waveforms Proto: not required and not used. All functions called by the subroutine record get passed one argument: psub Pointer to the subroutine record data. Use: pointer Type: struct subRecord * Acc: read/write Mech: reference All functions return a long integer. 0 = OK, -1 = ERROR. The subroutine record ignores the status returned by the Init routines. For the calculation routines, the record status (STAT) is set to SOFT_ALARM (unless it is already set to LINK_ALARM due to severity maximization) and the severity (SEVR) is set to psub->brsv (BRSV - set by the user in the database though it is expected to be invalid). Auth: 15-Feb-2009, Stephanie Allison Rev: DD-MMM-YYYY, Reviewer's Name (.NE. Author's Name) ------------------------------------------------------------------------------- Mod: =============================================================================*/ #include /* cos and sin prototypes */ #include /* for DBADDR */ #include /* for struct subRecord */ #include /* for epicsRegisterFunction */ #include /* for epicsRegisterFunction */ #define SIN_PI 3.14159265358979 #define SIN_DIM 2048 long subpacIQ(struct subRecord *psub) { /* * Set I and Q Waveforms from Phase and # Cycles: * * Inputs: * A = Phase (degree) * B = Number of Cycles * C = Max I and Q Value (2**15 - 1) * D to G = Spare * * Outputs: * I = (B*pi*2)/nelm * J = Phase (radian) * INPK = Pointer to I array * INPL = Pointer to Q array * VAL = Number of Values in the Array */ short i_a[SIN_DIM]; short q_a[SIN_DIM]; float phase; int idx; /* * Number of cycles must be positive and max value must be > 0. */ psub->j = psub->a * SIN_PI/180.0; psub->i = (2.0 * SIN_PI * psub->b)/((double)SIN_DIM); if ((psub->b < 0.0) || (psub->c <= 0.0)) return -1; for (idx = 0; idx < SIN_DIM; idx++) { phase = (float)((psub->i * (double)idx) + psub->j); i_a[idx] = (short)(psub->c * cos(phase)); q_a[idx] = (short)(psub->c * sin(phase)); } dbPutLink(&psub->inpk, DBR_SHORT, i_a, SIN_DIM); dbPutLink(&psub->inpl, DBR_SHORT, q_a, SIN_DIM); psub->val = (double)SIN_DIM; return 0; } long subpacTime(struct subRecord *psub) { /* * Fill in line used to plot time in a 2-d plot. * * Inputs: * A = Delta time between values (usec) * * Outputs: * INPL = Pointer to array of time values * VAL = Number of Values in the Array */ float time_a[SIN_DIM]; float inctime = 0.0; int idx; for (idx = 0; idx < SIN_DIM; idx++) { time_a[idx] = inctime; inctime += psub->a; } dbPutLink(&psub->inpl, DBR_FLOAT, time_a, SIN_DIM); psub->val = (double)SIN_DIM; return 0; } epicsRegisterFunction(subpacIQ); epicsRegisterFunction(subpacTime);