void evgEvtClk::setFracSynFreq(epicsFloat64 freq) { epicsUInt32 controlWord, oldControlWord; epicsFloat64 error; controlWord = FracSynthControlWord (freq, MRF_FRAC_SYNTH_REF, 0, &error); if ((!controlWord) || (error > 100.0)) { char err[80]; sprintf(err, "Cannot set event clock speed to %f MHz.\n", freq); std::string strErr(err); throw std::runtime_error(strErr); } oldControlWord=READ32(m_pReg, FracSynthWord); /* Changing the control word disturbes the phase of the synthesiser which will cause a glitch. Don't change the control word unless needed.*/ if(controlWord != oldControlWord){ WRITE32(m_pReg, FracSynthWord, controlWord); epicsUInt32 uSecDivider = (epicsUInt16)freq; WRITE32(m_pReg, uSecDiv, uSecDivider); } m_fracSynFreq = FracSynthAnalyze(READ32(m_pReg, FracSynthWord), 24.0, 0); }
int main (int argc, char *argv[]) { /*--------------------- * Local Variables */ int badArgs = 1; /* True if we could not parse the argument list */ epicsUInt32 controlWord; /* SY87739L control word to analyze */ char *tailPtr; /* Pointer to tail of parsed control word string */ /*--------------------- * Make sure we were passed only one argument. * If so, see if we can parse it as a hexadecimal number. */ if (argc == 2) { controlWord = strtoul (argv[1], &tailPtr, 16); /*--------------------- * If we successfully parsed the control word, * analyze it and display the results. */ if ((errno == OK) && (tailPtr != argv[1])) { FracSynthAnalyze (controlWord, MRF_FRAC_SYNTH_REF, DP_DEBUG); badArgs = 0; }/*end if control word parse was successful*/ }/*end if we had the right number of arguments*/ /*--------------------- * Print the "Usage" message if we could not parse the argument. */ if (badArgs) { printf ("Usage:\n"); printf ("FracSynthAnalyze <ControlWord>\n"); printf (" Where <ControlWord> is a hexadecimal number representing\n"); printf (" a Micrel SY87739L control word to be analyzed.\n"); }/*end if could not parse arguments*/ /*--------------------- * Always return success. */ return OK; }/*end main()*/
int main (int argc, char *argv[]) { /*--------------------- * Local Variables */ epicsBoolean badArgs = epicsTrue; /* True if we could not parse the argument list */ epicsUInt32 controlWord = 0; /* Genearated SY87739L control word */ epicsFloat64 DesiredFreq; /* Frequency we wish to create a control word for */ epicsFloat64 EffectiveFreq; /* Freq. actually generated by the control word */ epicsFloat64 Error; /* Error between the desired and actual freqs. */ char *tailPtr; /* Pointer to tail of parsed control word string */ /*--------------------- * Make sure we were passed only one argument. * If so, see if we can parse it as a floating point value. */ if (argc == 2) { DesiredFreq = strtod (argv[1], &tailPtr); /*--------------------- * If we successfully parsed the desired frequency, * try to compute a control word that will generate it. */ if ((errno == OK) && (tailPtr != argv[1])) { controlWord = FracSynthControlWord (DesiredFreq, MRF_FRAC_SYNTH_REF, DP_NONE, &Error); badArgs = epicsFalse; /*--------------------- * Abort if we could not successfully create a control word for this frequency */ if (controlWord == 0) { printf ("Unable to create a control word for %f MHz.\n", DesiredFreq); return ERROR; }/*end if could not create control word*/ /*--------------------- * Compute the effective frequency generated by the control word we created and * check it for errors (we don't expect any errors, since we created it, but * you never know....) */ EffectiveFreq = FracSynthAnalyze (controlWord, MRF_FRAC_SYNTH_REF, DP_ERROR); /*--------------------- * Display the control word, the effective frequency, and the error. */ printf ("Control Word = 0x%08X.\n", controlWord); printf ("Desired Frequency = %f Mhz. Effective Frequency = %f MHz. ", DesiredFreq, EffectiveFreq); printf ("Error = %5.3f ppm.\n", Error); }/*end if control word parse was successful*/ }/*end if we had the right number of arguments*/ /*--------------------- * Print the "Usage" message if we could not parse the argument. */ if (badArgs) { printf ("Usage:\n"); printf ("FracSynthControlWord <DesiredFreq>\n"); printf (" Where <DesiredFreq> is the frequency (in MegaHertz)\n"); printf (" that you wish to generate an SY87739L control word for.\n"); }/*end if could not parse arguments*/ /*--------------------- * Always return success. */ return OK; }/*end main()*/
epicsFloat64 evgEvtClk::getFracSynFreq() const { return FracSynthAnalyze(READ32(m_pReg, FracSynthWord), 24.0, 0); }