//------------------------------------------------------------------------------ // serialize() -- print the value of this object to the output stream sout. //------------------------------------------------------------------------------ std::ostream& Sz1::serialize(std::ostream& sout, const int i, const bool slotsOnly) const { int j = 0; if ( !slotsOnly ) { sout << "( " << getFactoryName() << std::endl; j = 4; } BaseClass::serialize(sout,i+j,true); indent(sout,i+j); sout << "N1: " << getN1() << std::endl; indent(sout,i+j); sout << "N2: " << getN2() << std::endl; indent(sout,i+j); sout << "D1: " << getD1() << std::endl; indent(sout,i+j); sout << "D2: " << getD2() << std::endl; if ( !slotsOnly ) { indent(sout,i); sout << ")" << std::endl; } return sout; }
Si570::Si570(uint8_t si570_address, uint32_t calibration_frequency) { i2c_address = si570_address; Wire.begin(); // Disable internal pullups - You will need external 3.3v pullups. digitalWrite(SDA, 0); digitalWrite(SCL, 0); f_center = 0; frequency = 0; // Force Si570 to reset to initial freq i2c_write(135,0x01); delay(20); if (read_si570()) { debug("Successfully initialized Si570"); freq_xtal = (uint64_t)calibration_frequency * getHsDiv() * getN1() / getRfReqDouble(); status = SI570_READY; //debugSi570(); } else { debug("Unable to properly initialize Si570"); status = SI570_ERROR; // Use the factory default if we were unable to talk to the chip freq_xtal = 114285000l; } }
void Si570::debugSi570() { debug(" --- Si570 Debug Info ---"); debug("Crystal frequency calibrated at: %lu", freq_xtal); debug("Status: %i", status); for (int i = 7; i < 15; i++) { debug("Register[%i] = %02x", i, dco_reg[i]); } debug("HsDivider = %i N1 = %i", getHsDiv(), getN1()); debug("Reference Frequency (hex) : %04lx%04lx", (uint32_t)(getRfReq() >> 32), (uint32_t)(getRfReq() & 0xffffffff)); char freq_string[10]; dtostrf(getRfReqDouble(), -8, 3, freq_string); debug("Reference Frequency (double): %s", freq_string); }
// Debug routine for examination of Si570 state void Si570::debugSi570() { DEBUG(P(" --- Si570 Debug Info ---")); DEBUG(P("Status: %i"), status); for (int i = 7; i < 15; i++) { DEBUG(P("Register[%i] = %02x"), i, dco_reg[i]); } DEBUG(P("HSDIV = %i, N1 = %i"), getHSDIV(), getN1()); DEBUG(P("RFREQ (hex): %04lx%04lx"), (uint32_t)(getRFREQ() >> 32), (uint32_t)(getRFREQ() & 0xffffffff)); }
fftplan *planIFFT(int N) { int *factors = factor(N); optimizeFactors(factors); fftplan *plan = new fftplan; plan->dir = -1; plan->n = getNFactors(factors); plan->N2 = factors; plan->N1 = getN1(factors,N); plan->order = getOrder(plan->n,plan->N1,plan->N2); plan->reorder = (t_fft*)malloc(N*sizeof(t_fft)); plan->t = calcTwiddles(plan->n,plan->N1,plan->N2,plan->order,-1); plan->f = getFuncs(factors); plan->N = N; plan->norm = 1.0f/(real)N; return plan; }
// Initialize the Si570 and determine its internal crystal frequency given the default output frequency Si570::Si570(uint8_t si570_address, uint32_t calibration_frequency) { i2c_address = si570_address; DEBUG(P("Si570 init, calibration frequency = %lu"), calibration_frequency); Wire.begin(); // Disable internal pullups - You will need external 3.3v pullups. digitalWrite(SDA, 0); digitalWrite(SCL, 0); // We are about the reset the Si570, so set the current and center frequency to the calibration frequency. f_center = frequency = calibration_frequency; max_delta = ((uint64_t) f_center * 10035LL / 10000LL) - f_center; // Force Si570 to reset to initial freq DEBUG(P("Resetting Si570")); i2c_write(135,0x01); delay(20); if (read_si570()) { debug(P("Successfully initialized Si570")); freq_xtal = (unsigned long) ((uint64_t) calibration_frequency * getHSDIV() * getN1() * (1L << 28) / getRFREQ()); status = SI570_READY; } else { // Use the factory default if we were unable to talk to the chip freq_xtal = 114285000L; DEBUG(P("Unable to properly initialize Si570")); status = SI570_ERROR; } debug(P("freq_xtal = %04lu"), freq_xtal); }