/****************************************************************************** * Module: Llrf pad driver definitions * Filename: padLlrf.c * Author: Shantha Condamoor * Created: 1-Nov-2012 * Description: * PAD related LLRF processing ****************************************************************************** * Modification history * Mod: Shantha Condamoor 02-Oct-2013 * Removed the duplicate addPadData() for L0-B towards the end of padLlrfProc() * as it broke L0-A and L0-B BSA * Mod: Shantha Condamoor 11-Nov-2013 * Replaced LLRF_KLY21_1 by LLRF_LSRDIAG for Coherent 2 Laser Diagnostics PAD * Added lsrCalculations() and lsrDiagCalcPhase() * Mod: Shantha Condamoor 10-Jan-2014 * Added IN20 and S24 Ref PAD related code. Both of them are non-feedback PADs. * LLRF_IN20REF (slot 19) in MC group ioc-in20-rf01-padg * LLRF_S24REF (slot 19) in MC group ioc-li24-rf01-padg * Mod: Shantha Condamoor 18-Mar-2014 * Added comments per code review recommendations - done on 17-Mar-2014. * Mod: Shantha Condamoor 18-Jul-2014 * Added support for LLRF_KLY24_5 (slot 22) for ASTA Kly Diag PAD @ TS01 * Mod: Shantha Condamoor 16-Sept-2014 * Converted LCLS Coherent Laser 1 Feedback station to Diagnostics station per H.Loos/J.Frisch. *****************************************************************************/ #include #include #include #include #include #include #include /* for struct subRecord */ #include /* DBADDR */ #include /* DBADDR */ #include #include #include #include #include #include #include #include #include #include "drvLlrfPad.h" #include "padLlrf.h" #include "llrfMacros.h" #ifdef DATAPROC_BLOB #include "drvPadDataProc.h" extern int addPadData(genericPadData_p data, unsigned short chnl); #endif volatile unsigned llrfPadTimeoutMs = 5; volatile int padLlrfProcessed = 0; int llrfPadDebug = 0; PadBlobLlrfData_t padLlrfData[PAD_NUM_CHANNELS_ON_BOARD]; /* data in the "blob" */ /****************************************************************************** * Function: padLlrfInit * Description: Initialization for pad. Everything we can do ahead of the time * to prepare for pad processing. * Inputs: * Returns: *****************************************************************************/ int padLlrfInit(void) { /* We need a system clock freq >= ~1kHz so that we can have * sub-fiducial timeouts. */ if ( sysClkPeriodGet() > 1./900. ) { cantProceed("FATAL ERROR: Need a OS system clock freq >= ~1kHz -- are you using a recent GeSys (rtems)"); } return 0; } /****************************************************************************** * Function: padLlrfProc * Description: pad processing, called every beam cycle * Inputs: * Returns: *****************************************************************************/ int llrfPadTsDebug=0; /* turn this on to take a snap shot of time stamp */ int llrfPadTs[2]; void padLlrfProc(LlrfStation station) { int rc; int i,j; epicsTimeStamp epicsTs; epicsTimeStamp tsSum; /* scondam: 18-Mar-2014: sum and num are arrays of 6-values each. Depending on the ch_p->freq, we use portions of the array for calculating I/Q. For example, 119 MHz signals needs all 6 values. 2856 MHz signals need 4 values only. The other two are 0's in this case, and are not used in IQ calculations here. Similarly, 69 MHz signals need only 3 values - rest are unused. Simple waveforms need only one value. */ epicsMutexMustLock( station->mutex ); for(i=0; ichnls[i].freq) { case 119: padLlrfData[i].sum[5] = station->chnls[i].sum[5]; padLlrfData[i].num[5] = station->chnls[i].num[5]; padLlrfData[i].sum[4] = station->chnls[i].sum[4]; padLlrfData[i].num[4] = station->chnls[i].num[4]; case 2856: padLlrfData[i].sum[3] = station->chnls[i].sum[3]; padLlrfData[i].num[3] = station->chnls[i].num[3]; case 68: padLlrfData[i].sum[2] = station->chnls[i].sum[2]; padLlrfData[i].num[2] = station->chnls[i].num[2]; padLlrfData[i].sum[1] = station->chnls[i].sum[1]; padLlrfData[i].num[1] = station->chnls[i].num[1]; case 0: padLlrfData[i].sum[0] = station->chnls[i].sum[0]; padLlrfData[i].num[0] = station->chnls[i].num[0]; break; } if (station->chnls[i].Samples) { /* sample 1 ? */ switch (station->chnls[i].freq) { case 119: padLlrfData[i].Samples.sum[5] = station->chnls[i].Samples->sum[5]; padLlrfData[i].Samples.num[5] = station->chnls[i].Samples->num[5]; padLlrfData[i].Samples.sum[4] = station->chnls[i].Samples->sum[4]; padLlrfData[i].Samples.num[4] = station->chnls[i].Samples->num[4]; case 2856: padLlrfData[i].Samples.sum[3] = station->chnls[i].Samples->sum[3]; padLlrfData[i].Samples.num[3] = station->chnls[i].Samples->num[3]; case 68: padLlrfData[i].Samples.sum[2] = station->chnls[i].Samples->sum[2]; padLlrfData[i].Samples.num[2] = station->chnls[i].Samples->num[2]; padLlrfData[i].Samples.sum[1] = station->chnls[i].Samples->sum[1]; padLlrfData[i].Samples.num[1] = station->chnls[i].Samples->num[1]; case 0: padLlrfData[i].Samples.sum[0] = station->chnls[i].Samples->sum[0]; padLlrfData[i].Samples.num[0] = station->chnls[i].Samples->num[0]; break; } } padLlrfData[i].Overflow = (LlrfOutNumber) station->chnls[i].Overflow; } tsSum = station->tsSum; epicsMutexUnlock( station->mutex ); rc = evrTimeGetFromPipeline(&epicsTs, evrTimeActive, 0, 0, 0, 0, 0); if( llrfPadTsDebug) { /* take one shot of the time stamps */ llrfPadTs[0] = epicsTs.secPastEpoch; llrfPadTs[1] = epicsTs.nsec; llrfPadTsDebug=0; } /* calculate the I,Q,Phase, Amplitude and Power */ for(i=0; ichnls[i].poc; /* Phase Offset in degrees */ double avc = station->chnls[i].avc; /* Voltage Scale Factor in MV/count) */ double apc = station->chnls[i].apc; /* Power Scale Factor for channels 0,1,3 in MW/count and Beam Voltage scale factor for ch2 in (V/count) */ switch (station->chnls[i].freq) { case 68: /* I Vector = {32766, -16383, -16383} Q Vector = {0, 28376, -28376} */ if ((padLlrfData[i].num[0]) || (padLlrfData[i].num[1]) || (padLlrfData[i].num[2])) { /* some good data */ double I0 = 0.; double I120 = 0.; double I240 = 0.; double Q0 = 0.; double Q120 = 0.; double Q240 = 0.; if (padLlrfData[i].num[0]) { I0 = ((double) padLlrfData[i].sum[0]/ (double) padLlrfData[i].num[0]) * 32766.; Q0 = 0.; } if (padLlrfData[i].num[1]) { I120 = ((double) padLlrfData[i].sum[1]/(double) padLlrfData[i].num[1]) * (-16383.); Q120 = ((double) padLlrfData[i].sum[1]/(double) padLlrfData[i].num[1]) * (28376.); } if (padLlrfData[i].num[2]) { I240 = ((double) padLlrfData[i].sum[2]/(double) padLlrfData[i].num[2]) * (-16383.); Q240 = ((double) padLlrfData[i].sum[2]/(double) padLlrfData[i].num[2]) * (-28376.); } padLlrfData[i].I = (I0 + I120 + I240)/(3.*32766.); padLlrfData[i].Q = (Q0 + Q120 + Q240)/(3.*32766.); double tampl = (double) ((padLlrfData[i].I) * (padLlrfData[i].I)) + ((padLlrfData[i].Q) * (padLlrfData[i].Q)); padLlrfData[i].Power = tampl * apc; /* Actual Power IN MW = (ampl * ampl) times apc */ padLlrfData[i].Amplitude = sqrtf(tampl) * avc; /* Actual Ampl in MV = sqrtf(i*i + q*q) times apc */ padLlrfData[i].Phase = atan2f((padLlrfData[i].Q),(padLlrfData[i].I)) / (RAD) + poc; /* Actual Phas in degrees = atan2( q/i) plus poc converted from radians to degrees */ } break; case 119: /* I Vector = {0, 28377, 28377,0,-28377,-28377} Q Vector = {32767, 16384, -16384, -32767, -16384, 16384} */ if ((padLlrfData[i].num[0]) || (padLlrfData[i].num[1]) || (padLlrfData[i].num[2]) || (padLlrfData[i].num[3]) || (padLlrfData[i].num[4]) || (padLlrfData[i].num[5])) { /* some good data */ double I0 = 0.; double I60 = 0.; double I120 = 0.; double I180 = 0.; double I240 = 0.; double I300 = 0.; double Q0 = 0.; double Q60 = 0.; double Q120 = 0.; double Q180 = 0.; double Q240 = 0.; double Q300 = 0.; if (padLlrfData[i].num[0]) { I0 = 0; Q0 = ((double) padLlrfData[i].sum[0]/ (double) padLlrfData[i].num[0]) * (32767.); } if (padLlrfData[i].num[1]) { I60 = ((double) padLlrfData[i].sum[1]/(double) padLlrfData[i].num[1]) * (28377.); Q60 = ((double) padLlrfData[i].sum[1]/(double) padLlrfData[i].num[1]) * (16384.); } if (padLlrfData[i].num[2]) { I120 = ((double) padLlrfData[i].sum[2]/(double) padLlrfData[i].num[2]) * (28377.); Q120 = ((double) padLlrfData[i].sum[2]/(double) padLlrfData[i].num[2]) * (-16384.); } if (padLlrfData[i].num[3]) { I180 = 0; Q180 = ((double) padLlrfData[i].sum[3]/ (double) padLlrfData[i].num[3]) * (-32767.); } if (padLlrfData[i].num[4]) { I240 = ((double) padLlrfData[i].sum[4]/(double) padLlrfData[i].num[4]) * (-28377.); Q240 = ((double) padLlrfData[i].sum[4]/(double) padLlrfData[i].num[4]) * (-16384.); } if (padLlrfData[i].num[5]) { I300 = ((double) padLlrfData[i].sum[5]/(double) padLlrfData[i].num[5]) * (-28377.); Q300 = ((double) padLlrfData[i].sum[5]/(double) padLlrfData[i].num[5]) * (16384.); } padLlrfData[i].I = (I0 + I60 + I120 + I180 + I240 + I300)/(6.)/(32766.); padLlrfData[i].Q = (Q0 + Q60 + Q120 + Q180 + Q240 + Q300)/(6.)/(32766.); double tampl = (double) ((padLlrfData[i].I) * (padLlrfData[i].I)) + ((padLlrfData[i].Q) * (padLlrfData[i].Q)); padLlrfData[i].Power = tampl * apc; /* Actual Power IN MW = (ampl * ampl) times apc */ padLlrfData[i].Amplitude = sqrtf(tampl) * avc; /* Actual Ampl in MV = sqrtf(i*i + q*q) times apc */ padLlrfData[i].Phase = atan2f((padLlrfData[i].Q),(padLlrfData[i].I)) / (RAD) + poc; /* Actual Phas in degrees = atan2( q/i) plus poc converted from radians to degrees */ } break; case 2856: /* Scalar Vector = {32766, -32766, -32766, 32766} */ if ((padLlrfData[i].num[0]) || (padLlrfData[i].num[1]) || (padLlrfData[i].num[2]) || (padLlrfData[i].num[3])) { /* some good data */ double I0 = 0.; double I180 = 0.; double Q90 = 0.; double Q270 = 0.; if (padLlrfData[i].num[0]) { I0 = ((double) padLlrfData[i].sum[0]/ (double) padLlrfData[i].num[0]); } if (padLlrfData[i].num[1]) { Q90 = ((double) padLlrfData[i].sum[1]/ (double) padLlrfData[i].num[1]) * (-1.); } if (padLlrfData[i].num[2]) { I180 = ((double) padLlrfData[i].sum[2]/(double) padLlrfData[i].num[2])* (-1.); } if (padLlrfData[i].num[3]) { Q270 = ((double) padLlrfData[i].sum[3]/(double) padLlrfData[i].num[3]); } padLlrfData[i].I = (I0 + I180)/2.; padLlrfData[i].Q = (Q90 + Q270)/(2.); double tampl = (double) ((padLlrfData[i].I) * (padLlrfData[i].I)) + ((padLlrfData[i].Q) * (padLlrfData[i].Q)); padLlrfData[i].Power = tampl * apc; /* Actual Power IN MW = (ampl * ampl) times apc */ padLlrfData[i].Amplitude = sqrtf(tampl) * avc; /* Actual Ampl in MV = sqrtf(i*i + q*q) times apc */ padLlrfData[i].Phase = atan2f((padLlrfData[i].Q),(padLlrfData[i].I)) / (RAD) + poc; /* Actual Phas in degrees = atan2( q/i) plus poc converted from radians to degrees */ } if (station->chnls[i].Samples) { /* PCAV sample 1 ? */ if ((padLlrfData[i].Samples.num[0]) || (padLlrfData[i].Samples.num[1]) || (padLlrfData[i].Samples.num[2]) || (padLlrfData[i].Samples.num[3])) { /* some good data */ double I0 = 0.; double I180 = 0.; double Q90 = 0.; double Q270 = 0.; if (padLlrfData[i].Samples.num[0]) { I0 = ((double) padLlrfData[i].Samples.sum[0]/ (double) padLlrfData[i].Samples.num[0]); } if (padLlrfData[i].Samples.num[1]) { Q90 = ((double) padLlrfData[i].Samples.sum[1]/ (double) padLlrfData[i].Samples.num[1]) * (-1.); } if (padLlrfData[i].Samples.num[2]) { I180 = ((double) padLlrfData[i].Samples.sum[2]/(double) padLlrfData[i].Samples.num[2])* (-1.); } if (padLlrfData[i].Samples.num[3]) { Q270 = ((double) padLlrfData[i].Samples.sum[3]/(double) padLlrfData[i].Samples.num[3]); } padLlrfData[i].Samples.I = (I0 + I180)/2.; padLlrfData[i].Samples.Q = (Q90 + Q270)/(2.); double tampl = (double) ((padLlrfData[i].Samples.I) * (padLlrfData[i].Samples.I)) + ((padLlrfData[i].Samples.Q) * (padLlrfData[i].Samples.Q)); padLlrfData[i].Power = tampl * apc; /* Actual Power IN MW = (ampl * ampl) times apc */ padLlrfData[i].Amplitude = sqrtf(tampl) * avc; /* Actual Ampl in MV = sqrtf(i*i + q*q) times apc */ padLlrfData[i].Phase = atan2f((padLlrfData[i].Samples.Q),(padLlrfData[i].Samples.I)) / (RAD) + poc; /* Actual Phas in degrees = atan2( q/i) plus poc converted from radians to degrees */ } } break; default: /* simple averaging */ if (padLlrfData[i].num[0]){ /* some good data */ /* avgS is stored in I */ if (padLlrfData[i].num[0]) { /* numS */ padLlrfData[i].I = ((double) padLlrfData[i].sum[0]/ (double) padLlrfData[i].num[0]); padLlrfData[i].Q = 0; padLlrfData[i].Amplitude = (double) padLlrfData[i].I * avc; /* Actual Beam Voltage in Volts = (avgS) times avc */ padLlrfData[i].Phase = 0.; /* no phase calculations for simple waveforms */ padLlrfData[i].Power = 0.; /* no power calculations for simple waveforms */ } } break; } } for(i=0; imutex ); station->chnls[i].I = padLlrfData[i].I; /* also S */ station->chnls[i].Q = padLlrfData[i].Q; station->chnls[i].Phase = padLlrfData[i].Phase; /* 0 for simple waveforms */ station->chnls[i].Amplitude = padLlrfData[i].Amplitude; /* Also Beam Voltage */ station->chnls[i].Power = padLlrfData[i].Power; station->chnls[i].Overflow = padLlrfData[i].Overflow; if (station->chnls[i].Samples) { /* PCAV sample 1 ? */ station->chnls[i].Samples->I = padLlrfData[i].Samples.I; /* also S */ station->chnls[i].Samples->Q = padLlrfData[i].Samples.Q; station->chnls[i].Samples->Phase = padLlrfData[i].Samples.Phase; /* 0 for simple waveforms */ station->chnls[i].Samples->Amplitude = padLlrfData[i].Samples.Amplitude; /* Also Beam Voltage */ station->chnls[i].Samples->Power = padLlrfData[i].Samples.Power; } /* mark IMAX bits in timedout as 'good' */ station->timedout &= ~LLRF_TIMEDOUT_ANY_IMAX; epicsMutexUnlock( station->mutex ); } #ifndef LLRF_KLY_PAD #ifndef LLRF_KLY_PAD2 switch (station->index) { #if defined LLRF_XTCAV case LLRF_KLY_XTCAV: break; /* no Feedback/Data Processing for Klystron Diagnostics PAD */ case LLRF_XTCAVB: break; /* no Feedback/Data Processing forXTCAV PAD-2 */ case LLRF_XTCAVA: #else case LLRF_LSRDIAG: lsrCalculations(station); break; /* No Feedback for Coherent Laser 2 Diagnostics PAD - formerly Thales Laser PAD */ case LLRF_GN2: break; /* No Feedback for Gun Tune PAD - for ASTA or LCLS */ #ifdef LLRF_IN20REF_NG case LLRF_IN20REF: break; /* No Feedback for IN20 Reference PAD */ #endif #ifdef LLRF_KLY24_5_NG case LLRF_KLY24_5: break; /* No Feedback for LCLS Kly PAD 24-5 or ASTA Kly Diag PAD which shares the same pad slot 22 */ #endif case LLRF_LSR: #ifdef LLRF_LSRDIAG_PAD lsrCalculations(station); break; /* No Feedback for Coherent Laser 1 Diagnostics PAD - controlled by Vitara HW Laser controls */ #endif /* LLRF Laser Feedback Station - as in ASTA Laser ioc-as01-rf01 */ case LLRF_GUN: case LLRF_L1S: case LLRF_TCAV0: case LLRF_TCAV3: case LLRF_L0A: case LLRF_L0B: case LLRF_PCAV1: case LLRF_PCAV2: case LLRF_L1X: case LLRF_PCAV3: case LLRF_PCAV4: #endif #ifdef DATAPROC_BLOB /* All PADs send the same number of shorts, which is 24 (the size of the PCAV1&2 dataset) */ /* so package the calculated I and Q's in a format similar to what the PADs would send */ if (station->padData_p) { for (i = 0; i < LLRF_PROCESSED_DATA; i++) { station->padData_p->data[i] = (short) 0x0; } epicsMutexMustLock( station->mutex ); if ((station->index == LLRF_PCAV1) || (station->index == LLRF_PCAV2)) { station->padData_p->data[0] = (short) station->chnls[0].Q; station->padData_p->data[1] = (short) station->chnls[0].I; station->padData_p->data[2] = (short) station->chnls[0].Samples->Q; station->padData_p->data[3] = (short) station->chnls[0].Samples->I; station->padData_p->data[4] = (short) station->chnls[1].Q; station->padData_p->data[5] = (short) station->chnls[1].I; station->padData_p->data[6] = (short) station->chnls[1].Samples->Q; station->padData_p->data[7] = (short) station->chnls[1].Samples->I; station->padData_p->data[8] = (short) station->chnls[2].Q; station->padData_p->data[9] = (short) station->chnls[2].I; station->padData_p->data[10] = (short) station->chnls[2].Samples->Q; station->padData_p->data[11] = (short) station->chnls[2].Samples->I; station->padData_p->data[12] = (short) station->chnls[3].Q; station->padData_p->data[13] = (short) station->chnls[3].I; station->padData_p->data[14] = (short) station->chnls[3].Samples->Q; station->padData_p->data[15] = (short) station->chnls[3].Samples->I; station->padData_p->data[16] = station->chnls[0].x; station->padData_p->data[17] = station->chnls[0].Samples->x; station->padData_p->data[18] = station->chnls[1].x; station->padData_p->data[19] = station->chnls[1].Samples->x; station->padData_p->data[20] = station->chnls[2].x; station->padData_p->data[21] = station->chnls[2].Samples->x; station->padData_p->data[22] = station->chnls[3].x; station->padData_p->data[23] = station->chnls[3].Samples->x; } else if ((station->index == LLRF_PCAV3) || (station->index == LLRF_PCAV4)) { station->padData_p->data[0] = (short) station->chnls[3].Q; station->padData_p->data[1] = (short) station->chnls[3].I; station->padData_p->data[2] = (short) station->chnls[3].Samples->Q; station->padData_p->data[3] = (short) station->chnls[3].Samples->I; station->padData_p->data[4] = (short) station->chnls[3].x; station->padData_p->data[5] = (short) station->chnls[3].Samples->x; } else { station->padData_p->data[0] = (short) station->chnls[0].Q; station->padData_p->data[1] = (short) station->chnls[0].I; station->padData_p->data[2] = (short) station->chnls[1].Q; station->padData_p->data[3] = (short) station->chnls[1].I; if (station->index == LLRF_L1X) { station->padData_p->data[4] = (short) station->chnls[3].Q; station->padData_p->data[5] = (short) station->chnls[3].I; station->padData_p->data[6] = (short) station->chnls[2].I; /* Simple Average on Ch2 */ } else { station->padData_p->data[4] = (short) station->chnls[2].Q; station->padData_p->data[5] = (short) station->chnls[2].I; station->padData_p->data[6] = (short) station->chnls[3].Q; station->padData_p->data[7] = (short) station->chnls[3].I; } } epicsMutexUnlock( station->mutex ); addPadData(station->padData_p, (unsigned short) station->index); /* L0 PAD has padData for both L0-A and L0-B stations */ /* scondam: 02-Oct-2013: Removed the duplicate addPadData() for L0-B. All the eight shorts (4 for L0-A and 4 for L0-B) are passed eventually to stationDataProc.c processing data hook, which processes the data for both the L0-a and L0-B stations in the same function call. BSA for L0-A and L0-B was broken when the duplicate addPadData() was present. Kukhee reports that if BSA processing hook is invoked twice in succession for same data with the same time stamp, then it will not process the BSA functions. */ if (llrfPadDebug) { for(i=0; i<8; i++) { printf("station %d -> data[%d]: %d\n",station->index,i,station->padData_p->data[i]); } llrfPadDebug--; } } #endif default: break; } #endif #endif return; } /*============================================================================= Name: lsrCalcPhase Abs: use atan2 to preserve quadrant, work in degrees, offset and limit Mod: scondam: 20-Nov-2013. Coherent 2 Laser Diagnostics LLRF_LSRDIAG_NG =============================================================================*/ double lsrCalcPhase(LlrfInNumber I, LlrfInNumber Q, double phase_offset_correction, double desired_phase) { double phase; phase = atan2f((double) Q,(double) I); /* Convert radians to degrees */ phase = phase/PI*180.; phase += phase_offset_correction; /* Calculated phase = Actual raw phase + phase offset with the modulo applied as below. */ /* Phase = mod(phase - phaseRef+180,360) + phaseRef - 180 where mod(double a, double N) { return (a-N*floor(a/N));} */ phase = ((phase - desired_phase + 180.)-360.*floor((phase - desired_phase + 180.)/360.)) + desired_phase - 180.; return phase; } /*============================================================================= */ /*============================================================================= Name: lsrCalculations Abs: Calculates the phases, ampls, powers, avg phase and ampl of a PAD dataset for a station. Station is needed to figure out how many phases and in which channels TBD: So, all the data got across at once, BUT we only want to calculate the phases for BSA stuff, so how should non-BSA related channels be handled. I.e. for PCAV3 riding in klystron diag PAD... Mod: scondam: 11-Nov-2013. Coherent 2 Laser Diagnostics LLRF_LSRDIAG_NG =============================================================================*/ int lsrCalculations(LlrfStation station) { epicsMutexMustLock( station->mutex ); switch (station->index) { case LLRF_LSRDIAG: case LLRF_LSR: /* Step 1. Rotate input Is and Qs */ /* rotate ch0's I and Q by desired_phase2856 */ station->chnls[0].rotatedI = cos(station->desired_phase2856*PI/180.) * (double) station->chnls[0].I + sin(station->desired_phase2856*PI/180.) * (double) station->chnls[0].Q; station->chnls[0].rotatedQ = cos(station->desired_phase2856*PI/180.) * (double) station->chnls[0].Q - sin(station->desired_phase2856*PI/180.) * (double) station->chnls[0].I; /* ch1 does not need to be rotated */ /* rotate ch2's I and Q by desired_phase68 */ station->chnls[2].rotatedI = cos(station->desired_phase68*PI/180.) * (double) station->chnls[2].I + sin(station->desired_phase68*PI/180.) * (double) station->chnls[2].Q; station->chnls[2].rotatedQ = cos(station->desired_phase68*PI/180.) * (double) station->chnls[2].Q - sin(station->desired_phase68*PI/180.) * (double) station->chnls[2].I; /* rotate ch2's I and Q by desired_phase119 */ /*station->chnls[2].rotatedI = cos(station->desired_phase119*PI/180.) * (double) station->chnls[2].I + sin(station->desired_phase119*PI/180.) * (double) station->chnls[2].Q; station->chnls[2].rotatedQ = cos(station->desired_phase119*PI/180.) * (double) station->chnls[2].Q - sin(station->desired_phase119*PI/180.) * (double) station->chnls[2].I; */ /* ch3 does not need to be rotated */ /* Step 2. Calculate phases, both rotated and non-rotated */ /* ch0 has both */ station->chnls[0].rotatedPhase=lsrCalcPhase((LlrfInNumber) station->chnls[0].rotatedI,(LlrfInNumber) station->chnls[0].rotatedQ,station->chnls[0].poc,station->desired_phase2856); station->chnls[0].nonRotatedPhase=lsrCalcPhase(station->chnls[0].I,station->chnls[0].Q,station->chnls[0].poc,station->desired_phase2856); /* ch1 has non-rotated phase only*/ station->chnls[1].nonRotatedPhase=lsrCalcPhase(station->chnls[1].I,station->chnls[1].Q,station->chnls[1].poc,0.0); /* ch2 has both */ station->chnls[2].rotatedPhase=lsrCalcPhase((LlrfInNumber) station->chnls[2].rotatedI,(LlrfInNumber) station->chnls[2].rotatedQ,station->chnls[2].poc,station->desired_phase68); station->chnls[2].nonRotatedPhase=lsrCalcPhase(station->chnls[2].I,station->chnls[2].Q,station->chnls[2].poc,station->desired_phase68); /* station->chnls[2].rotatedPhase=lsrCalcPhase((LlrfInNumber) station->chnls[2].rotatedI,(LlrfInNumber) station->chnls[2].rotatedQ,station->chnls[2].poc,station->desired_phase119); station->chnls[2].nonRotatedPhase=lsrCalcPhase(station->chnls[2].I,station->chnls[2].Q,station->chnls[2].poc,station->desired_phase119); */ /* ch3 has non-rotated phase only */ station->chnls[3].nonRotatedPhase=lsrCalcPhase(station->chnls[3].I,station->chnls[3].Q,station->chnls[3].poc,0.0); /* Step 3. Use the amplitude for the current source */ /* Note: the rotatedI and rotatedQ are NOT used for amplitdue for any channel */ switch (station->input_source) { case 0: station->actual_ampl = station->chnls[0].Amplitude; break; case 1: station->actual_ampl = station->chnls[2].Amplitude; break; default: errlogPrintf("invalid input source\n"); break; } /* Step 4. Based on which input source is being used, calculate actual phase which used to be used originally as input for feedback, */ /* scondam: 11-Nov-2013: lsrdiag is not used for feedback - it is used for just Coherent 2 Laser Diagnostics but keep the actual phase calculations for diagnostics purposes */ switch (station->input_source) { case LSR_2856_MHZ_SOURCE: /* Use Laser PAD channel 0: 2856 MHz for input. For 476 MHz, conversion factor is 1/6 */ station->actual_phase = station->chnls[0].rotatedPhase/6.0; /* the rotated-by-PDES2856 phase */ break; #ifdef LLRF_LSR68_NG case LSR_68_MHZ_SOURCE: /* Use Laser PAD channel 2: 68 MHz for input.For 476 MHz, conversion factor is 7 */ station->actual_phase = station->chnls[2].rotatedPhase*7.0; /* the rotated-by-PDES68 phase */ break; #elif LLRF_LSR119_NG case LSR_119_MHZ_SOURCE: /* Use Laser PAD channel 2: 119 MHz for input. For 476 MHz, conversion factor is 4 */ station->actual_phase = station->chnls[2].rotatedPhase*4.0; /* the rotated-by-PDES119 phase */ break; #endif default: errlogPrintf("invalid input source\n"); break; } break; default:errlogPrintf("invalid station\n"); break; } epicsMutexUnlock( station->mutex ); return 0; }