The Smell of Molten Projects in the Morning

Ed Nisley's Blog: Shop notes, electronics, firmware, machinery, 3D printing, laser cuttery, and curiosities. Contents: 100% human thinking, 0% AI slop.

Author: Ed

  • LF Crystal Tester: Joystick for Oscillator Offset Adjustment

    With the joystick button and LM75 temperature sensor running, this chunk of code lets you nudge the nominal DDS oscillator frequency by 1 Hz every 100 ms:

    // Zero-beat oscillator to 10 MHz GPS-locked reference
    printf("Zero beat DDS oscillator against GPS\n");
    TempFreq.fx_64 = CALFREQ;
    u8x8.clearDisplay();
    byte ln = 0;
    u8x8.drawString(0,ln++,"10 MHz Zero Beat");
    u8x8.drawString(0,ln++,"<- Joystick ->");
    u8x8.drawString(0,ln++," Button = set ");
    int32_t OldOffset = OscOffset;
    while (analogRead(PIN_JOYBUTTTON) > 500) {
    int ai = analogRead(PIN_JOY_Y) – 512; // totally ad-hoc axes
    if (ai < -100) {
    OscOffset += 1;
    }
    else if (ai > 100) {
    OscOffset -= 1;
    }
    if (OscOffset != OldOffset) {
    ln = 4;
    sprintf(Buffer,"Offset %8ld",OscOffset);
    u8x8.drawString(0,ln++,Buffer);
    CalcOscillator(OscOffset); // recalculate constants
    TempCount.fx_64 = MultiplyFixedPt(TempFreq,CtPerHz); // recalculate delta phase count
    WriteDDS(TempCount.fx_32.high); // should be 10 MHz out!
    OldOffset = OscOffset;
    }
    Wire.requestFrom(LM75_ADDR,2);
    Temperature.fx_32.high = Wire.read();
    Temperature.fx_32.low = (uint32_t)Wire.read() << 24;
    PrintFixedPtRounded(Buffer,Temperature,3);
    ln = 7;
    u8x8.drawString(0,ln,"DDS Temp");
    u8x8.drawString(16-strlen(Buffer),ln++,Buffer);
    delay(100);
    }
    printf("Oscillator offset: %ld\n",OscOffset);
    view raw gistfile1.txt hosted with ❤ by GitHub

    While that’s happening, you compare the DDS output to a reference frequency on an oscilloscope:

    Zero-beat oscillator
    Zero-beat oscillator

    The top trace (and scope trigger) is the GPS-locked 10 MHz reference, the lower trace is the AD9850 DDS output (not through the MAX4165 buffer amp, because bandwidth). If the frequencies aren’t identical, the DDS trace will crawl left or right with respect to the reference: leftward if the DDS frequency is too high, rightward if it’s too low. If the DDS frequency is way off, then the waveform may scamper or run, with the distinct possibility of aliasing on digital scopes; you have been warned.

    The joystick acts as a bidirectional switch, rather than an analog input, with the loop determining the step increment and timing. The ad-hoc axis orientation lets you (well, me) push the joystick against the waveform crawl, which gradually slows down and stops when the offset value makes the DDS output match the reference.

    The OLED displays the current status:

    DDS Offset zero-beat display
    DDS Offset zero-beat display

    The lurid red glow along the bottom is lens flare from the amber LED showing the relay is turned on. The slightly dimmer characters across the middle of the display show how the refresh interacts with the camera shutter at 1/30 s exposure.

    N.B.: Normally, you know the DDS clock oscillator frequency with some accuracy. Dividing that value into 232 (for the AD9850) gives you the delta-phase count / frequency ratio that converts a desired DDS output frequency into the delta-phase value telling the DDS to make it happen.

    In this case, I want the output frequency to be exactly 10.000000 MHz, so I’m adjusting the oscillator frequency (nominal 125 MHz + offset), calculating the corresponding count-to-Hz ratio, multiplying the ratio by 10.000000 MHz, stuffing the ensuing count into the DDS, and eyeballing what happens. When the oscillator frequency variable matches the actual oscillator frequency, then the actual output will 10.000000 MHz and the ratio will be correct.

    Got it? Took me a while.

    Although the intent is to tune for best frequency match and move on, you (well, I) can use this to accumulate a table of frequency offset vs. temperature pairs, from which a (presumably simple) formula can be conjured to render this step unnecessary.

    The Arduino source code as a GitHub Gist:

    // 60 kHz crystal tester
    // Ed Nisley – KE4ZNU
    #include <avr/pgmspace.h>
    #include <U8g2lib.h>
    #include <U8x8lib.h>
    #include <Adafruit_MCP4725.h>
    //———————
    // Pin locations
    #define PIN_SYNC 5
    #define PIN_CX_SHORT 6
    #define PIN_DDS_RESET 7
    #define PIN_DDS_LATCH 8
    #define PIN_HEARTBEAT 9
    #define PIN_LOG_AMP A0
    #define PIN_JOYBUTTTON A1
    #define PIN_JOY_Y A2
    #define PIN_JOY_X A3
    // SPI & I2C use hardware support: these pins are predetermined
    #define PIN_SS 10
    #define PIN_MOSI 11
    #define PIN_MISO 12
    #define PIN_SCK 13
    #define PIN_IIC_SDA A4
    #define PIN_IIC_SCL A5
    // IIC Hardware addresses
    // OLED library uses its default address
    #define LM75_ADDR 0x48
    #define SH1106_ADDR 0x70
    #define MCP4725_ADDR 0x60
    // Useful constants
    #define GIGA 1000000000LL
    #define MEGA 1000000LL
    #define KILO 1000LL
    #define ONE_FX (1LL << 32)
    #define CALFREQ (10LL * MEGA * ONE_FX)
    // Structures for 64-bit fixed point numbers
    // Low word = fractional part
    // High word = integer part
    struct ll_fx {
    uint32_t low; // fractional part
    uint32_t high; // integer part
    };
    union ll_u {
    uint64_t fx_64;
    struct ll_fx fx_32;
    };
    // Define semi-constant values
    union ll_u CenterFreq = {(60000 – 4) * ONE_FX}; // center of scan
    //union ll_u CenterFreq = {(32768 – 2) * ONE_FX}; // center of scan
    #define NOMINAL_OSC ((125 * MEGA) * ONE_FX)
    union ll_u Oscillator = {NOMINAL_OSC}; // oscillator frequency
    int32_t OscOffset = -414; // measured offset from NOMINAL_OSC
    uint16_t ScanWidth = 4*2; // width must be an even integer
    uint16_t ScanSettleMS = 2000; // milliseconds of settling time per measurement
    union ll_u ScanStepSize = {ONE_FX / 10}; // 0.1 Hz is smallest practical decimal step
    //union ll_u ScanStepSize = {ONE_FX / 34}; // 0.0291 is smallest possible step
    // Global variables of interest to everyone
    union ll_u ScanFrom, ScanTo; // may be larger than unsigned ints
    union ll_u ScanFreq; // fixed-point frequency scan settings
    union ll_u PeakFreq; // records maximum response point
    union ll_u PeakdB; // and corresponding log amp output
    union ll_u SeriesPeakLow,SeriesPeakHigh; // peak with CX short and CX in circuit
    union ll_u CtPerHz; // will be 2^32 / oscillator
    union ll_u HzPerCt; // will be oscillator / 2^32
    char Buffer[10+1+10+1]; // string buffer for fixed point number conversions
    union ll_u Temperature; // read from LM75A
    // Hardware library variables
    U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE);
    //U8X8_SH1106_128X64_NONAME_4W_HW_SPI u8x8(PIN_DISP_SEL, PIN_DISP_DC , PIN_DISP_RST);
    //U8X8_SH1106_128X64_NONAME_4W_SW_SPI u8x8(PIN_SCK, PIN_MOSI, PIN_DISP_SEL, PIN_DISP_DC , PIN_DISP_RST);
    #define DAC_WR false
    #define DAC_WR_EEP true
    #define DAC_BITS 12
    #define DAC_MAX 0x0fff
    Adafruit_MCP4725 XAxisDAC; // I²C DAC for X axis output
    uint32_t XAxisValue; // DAC parameter uses 32 bits
    union ll_u LogAmpdB; // computed dB value
    #define HEARTBEAT_MS 3000
    unsigned long MillisNow,MillisThen;
    //———–
    // Useful functions
    // Pin twiddling
    void TogglePin(char bitpin) {
    digitalWrite(bitpin,!digitalRead(bitpin)); // toggle the bit based on previous output
    }
    void PulsePin(char bitpin) {
    TogglePin(bitpin);
    TogglePin(bitpin);
    }
    void WaitButtonDown() {
    word ai;
    do {
    ai = analogRead(PIN_JOYBUTTTON);
    } while (ai > 500);
    }
    void WaitButtonUp() {
    word ai;
    do {
    ai = analogRead(PIN_JOYBUTTTON);
    } while (ai < 500);
    }
    // Hardware-assisted SPI I/O
    void EnableSPI(void) {
    digitalWrite(PIN_SS,HIGH); // set SPI into Master mode
    SPCR |= 1 << SPE;
    }
    void DisableSPI(void) {
    SPCR &= ~(1 << SPE);
    }
    void WaitSPIF(void) {
    while (! (SPSR & (1 << SPIF))) {
    // TogglePin(PIN_HEARTBEAT);
    // TogglePin(PIN_HEARTBEAT);
    continue;
    }
    }
    byte SendRecSPI(byte Dbyte) { // send one byte, get another in exchange
    SPDR = Dbyte;
    WaitSPIF();
    return SPDR; // SPIF will be cleared
    }
    //————–
    // DDS module
    void EnableDDS(void) {
    digitalWrite(PIN_DDS_LATCH,LOW); // ensure proper startup
    digitalWrite(PIN_DDS_RESET,HIGH); // minimum reset pulse 40 ns, not a problem
    digitalWrite(PIN_DDS_RESET,LOW);
    delayMicroseconds(1); // max latency 100 ns, not a problem
    DisableSPI(); // allow manual control of outputs
    digitalWrite(PIN_SCK,LOW); // ensure clean SCK pulse
    PulsePin(PIN_SCK); // … to latch hardwired config bits
    PulsePin(PIN_DDS_LATCH); // load hardwired config bits = begin serial mode
    EnableSPI(); // turn on hardware SPI controls
    SendRecSPI(0x00); // shift in serial config bits
    PulsePin(PIN_DDS_LATCH); // load serial config bits
    }
    // Write delta phase count to DDS
    // This comes from the integer part of a 64-bit scaled value
    void WriteDDS(uint32_t DeltaPhase) {
    SendRecSPI((byte)DeltaPhase); // low-order byte first
    SendRecSPI((byte)(DeltaPhase >> 8));
    SendRecSPI((byte)(DeltaPhase >> 16));
    SendRecSPI((byte)(DeltaPhase >> 24));
    SendRecSPI(0x00); // 5 MSBs = phase = 0, 3 LSBs must be zero
    PulsePin(PIN_DDS_LATCH); // write data to DDS
    }
    //————–
    // Log amp module
    #define LOG_AMP_SAMPLES 10
    #define LOG_AMP_DELAYMS 10
    uint64_t ReadLogAmp() {
    union ll_u LogAmpRaw;
    LogAmpRaw.fx_64 = 0;
    for (byte i=0; i<LOG_AMP_SAMPLES; i++) {
    LogAmpRaw.fx_32.high += analogRead(PIN_LOG_AMP);
    delay(LOG_AMP_DELAYMS);
    }
    LogAmpRaw.fx_64 /= LOG_AMP_SAMPLES; // figure average from totally ad-hoc number of samples
    LogAmpRaw.fx_64 *= 5; // convert from ADC counts to voltage
    LogAmpRaw.fx_64 /= 1024;
    LogAmpRaw.fx_64 /= 24; // convert from voltage to dBV at 24 mV/dBV
    LogAmpRaw.fx_64 *= 1000;
    return LogAmpRaw.fx_64;
    }
    //———–
    // Scan DDS and record response
    void ScanCrystal() {
    byte ln;
    union ll_u Temp, TestFreq, TestCount;
    XAxisValue = 0;
    PeakdB.fx_64 = 0;
    printf("CX: %s\n",digitalRead(PIN_CX_SHORT) ? "short" : "enable");
    for (ScanFreq = ScanFrom;
    ScanFreq.fx_64 < (ScanTo.fx_64 + ScanStepSize.fx_64 / 2);
    ScanFreq.fx_64 += ScanStepSize.fx_64) {
    digitalWrite(PIN_SYNC,HIGH);
    TestCount.fx_64 = MultiplyFixedPt(ScanFreq,CtPerHz); // compute DDS delta phase
    TestCount.fx_32.low = 0; // truncate count to integer
    TestFreq.fx_64 = MultiplyFixedPt(TestCount,HzPerCt); // compute actual frequency
    Temp.fx_64 = (DAC_MAX * (ScanFreq.fx_64 – ScanFrom.fx_64)); // figure X as fraction
    Temp.fx_64 /= ScanWidth;
    XAxisValue = Temp.fx_32.high;
    digitalWrite(PIN_HEARTBEAT,HIGH);
    WriteDDS(TestCount.fx_32.high); // set DDS to new frequency
    XAxisDAC.setVoltage(XAxisValue,DAC_WR); // and set X axis to match
    digitalWrite(PIN_SYNC,LOW);
    if (ScanFreq.fx_64 == ScanFrom.fx_64) {
    delay(3*ScanSettleMS); // very long settling time
    }
    else {
    delay(ScanSettleMS); // small steps are faster
    }
    LogAmpdB.fx_64 = ReadLogAmp(); // fetch avg value
    if (LogAmpdB.fx_64 > PeakdB.fx_64) { // hit a new high?
    PeakFreq = TestFreq; // save actual frequency
    PeakdB = LogAmpdB;
    ln = digitalRead(PIN_CX_SHORT) ? 4 : 5; // CX selects row
    PrintFixedPtRounded(Buffer,TestFreq,2); // display actual peak
    u8x8.drawString(0,ln,Buffer);
    PrintFixedPtRounded(Buffer,LogAmpdB,1); // tack on response
    u8x8.drawString(16-strlen(Buffer),ln,Buffer);
    }
    ln = 0;
    PrintFixedPtRounded(Buffer,TestFreq,2); // display current frequency
    u8x8.draw2x2String(0,ln++,Buffer);
    ln++; // double-high characters
    printf("%9s ",Buffer); // log to serial port
    PrintFixedPtRounded(Buffer,LogAmpdB,1); // display response
    u8x8.drawString(0,ln,"dBV ");
    u8x8.drawString(16-strlen(Buffer),ln++,Buffer);
    printf(", %6s\n",Buffer); // and log it
    }
    }
    //———–
    // Round scaled fixed point to specific number of decimal places: 0 through 8
    // You should display the value with only Decimals characters beyond the point
    // Must calculate rounding value as separate variable to avoid mystery error
    uint64_t RoundFixedPt(union ll_u TheNumber,unsigned Decimals) {
    union ll_u Rnd;
    Rnd.fx_64 = (ONE_FX >> 1) / (pow(10LL,Decimals)); // that's 0.5 / number of places
    TheNumber.fx_64 = TheNumber.fx_64 + Rnd.fx_64;
    return TheNumber.fx_64;
    }
    //———–
    // Multiply two unsigned scaled fixed point numbers without overflowing a 64 bit value
    // Perforce, the product of the two integer parts mut be < 2^32
    uint64_t MultiplyFixedPt(union ll_u Mcand, union ll_u Mplier) {
    union ll_u Result;
    Result.fx_64 = ((uint64_t)Mcand.fx_32.high * (uint64_t)Mplier.fx_32.high) << 32; // integer parts (clear fract)
    Result.fx_64 += ((uint64_t)Mcand.fx_32.low * (uint64_t)Mplier.fx_32.low) >> 32; // fraction parts (always < 1)
    Result.fx_64 += (uint64_t)Mcand.fx_32.high * (uint64_t)Mplier.fx_32.low; // cross products
    Result.fx_64 += (uint64_t)Mcand.fx_32.low * (uint64_t)Mplier.fx_32.high;
    return Result.fx_64;
    }
    //———–
    // Long long print-to-buffer helpers
    // Assumes little-Endian layout
    void PrintHexLL(char *pBuffer,union ll_u FixedPt) {
    sprintf(pBuffer,"%08lx %08lx",FixedPt.fx_32.high,FixedPt.fx_32.low);
    }
    // converts all 9 decimal digits of fraction, which should suffice
    void PrintFractionLL(char *pBuffer,union ll_u FixedPt) {
    union ll_u Fraction;
    Fraction.fx_64 = FixedPt.fx_32.low; // copy 32 fraction bits, high order = 0
    Fraction.fx_64 *= GIGA; // times 10^9 for conversion
    Fraction.fx_64 >>= 32; // align integer part in low long
    sprintf(pBuffer,"%09lu",Fraction.fx_32.low); // convert low long to decimal
    }
    void PrintIntegerLL(char *pBuffer,union ll_u FixedPt) {
    sprintf(pBuffer,"%lu",FixedPt.fx_32.high);
    }
    void PrintFixedPt(char *pBuffer,union ll_u FixedPt) {
    PrintIntegerLL(pBuffer,FixedPt); // do the integer part
    pBuffer += strlen(pBuffer); // aim pointer beyond integer
    *pBuffer++ = '.'; // drop in the decimal point, tick pointer
    PrintFractionLL(pBuffer,FixedPt);
    }
    void PrintFixedPtRounded(char *pBuffer,union ll_u FixedPt,unsigned Decimals) {
    char *pDecPt;
    FixedPt.fx_64 = RoundFixedPt(FixedPt,Decimals);
    PrintIntegerLL(pBuffer,FixedPt); // do the integer part
    pBuffer += strlen(pBuffer); // aim pointer beyond integer
    pDecPt = pBuffer; // save the point location
    *pBuffer++ = '.'; // drop in the decimal point, tick pointer
    PrintFractionLL(pBuffer,FixedPt); // do the fraction
    if (Decimals == 0)
    *pDecPt = 0; // 0 places means discard the decimal point
    else
    *(pDecPt + Decimals + 1) = 0; // truncate string to leave . and Decimals chars
    }
    //———–
    // Calculate useful "constants" from oscillator info
    // Offset is integer Hz, because 0.1 ppm = 1 Hz at 10 MHz is as close as we can measure
    void CalcOscillator(int32_t Offset) {
    Oscillator.fx_64 = NOMINAL_OSC + ((int64_t)Offset << 32);
    HzPerCt.fx_32.low = Oscillator.fx_32.high; // divide oscillator by 2^32 with simple shifting
    HzPerCt.fx_32.high = 0;
    CtPerHz.fx_64 = -1; // Compute (2^32 – 1) / oscillator
    CtPerHz.fx_64 /= (uint64_t)Oscillator.fx_32.high; // remove 2^32 scale factor from divisor
    }
    //– Helper routine for printf()
    int s_putc(char c, FILE *t) {
    Serial.write(c);
    }
    //———–
    void setup () {
    union ll_u TempFreq,TempCount;
    pinMode(PIN_HEARTBEAT,OUTPUT);
    digitalWrite(PIN_HEARTBEAT,LOW); // show we got here
    pinMode(PIN_SYNC,OUTPUT);
    digitalWrite(PIN_SYNC,LOW);
    Serial.begin (115200);
    fdevopen(&s_putc,0); // set up serial output for printf()
    Serial.println (F("60 kHz Crystal Tester"));
    Serial.println (F("Ed Nisley – KE4ZNU – June 2017\n"));
    // DDS module controls
    pinMode(PIN_DDS_LATCH,OUTPUT);
    digitalWrite(PIN_DDS_LATCH,LOW);
    pinMode(PIN_DDS_RESET,OUTPUT);
    digitalWrite(PIN_DDS_RESET,HIGH);
    // Light up the display
    Serial.println("Initialize OLED");
    u8x8.begin();
    u8x8.setFont(u8x8_font_artossans8_r);
    // u8x8.setPowerSave(0);
    u8x8.setFont(u8x8_font_pxplusibmcga_f);
    u8x8.draw2x2String(0,0,"XtalTest");
    u8x8.drawString(0,3,"Ed Nisley");
    u8x8.drawString(0,4," KE4ZNU");
    u8x8.drawString(0,6,"June 2017");
    // configure SPI hardware
    pinMode(PIN_SS,OUTPUT); // set up manual controls
    digitalWrite(PIN_SS,HIGH);
    pinMode(PIN_SCK,OUTPUT);
    digitalWrite(PIN_SCK,LOW);
    pinMode(PIN_MOSI,OUTPUT);
    digitalWrite(PIN_MOSI,LOW);
    pinMode(PIN_MISO,INPUT_PULLUP);
    SPCR = B00110000; // Auto SPI: no int, disabled, LSB first, master, + edge, leading, f/4
    SPSR = B00000000; // not double data rate
    TogglePin(PIN_HEARTBEAT); // show we got here
    // Set up X axis DAC output
    XAxisDAC.begin(MCP4725_ADDR); // start up MCP4725 DAC at Sparkfun address
    // XAxisDAC.setVoltage(0,DAC_WR_EEP); // do this once per DAC to set power-on at 0 V
    XAxisDAC.setVoltage(0,DAC_WR); // force 0 V after a reset without a power cycle
    // LM75A temperature sensor requires no setup!
    // External capacitor in test fixture
    pinMode(PIN_CX_SHORT,OUTPUT);
    digitalWrite(PIN_CX_SHORT,HIGH); // short = remove external cap
    // Scan limits and suchlike
    ScanFrom.fx_64 = CenterFreq.fx_64 – (ONE_FX * ScanWidth/2);
    ScanTo.fx_64 = CenterFreq.fx_64 + (ONE_FX * ScanWidth/2);
    PrintFixedPtRounded(Buffer,CenterFreq,1);
    printf("Center freq: %s Hz\n",Buffer);
    printf("Settling time: %d ms\n",ScanSettleMS);
    // Wake up and load the DDS
    CalcOscillator(OscOffset); // use default oscillator frequency
    Serial.print("\nStarting DDS: ");
    TempFreq.fx_64 = CALFREQ;
    TempCount.fx_64 = MultiplyFixedPt(TempFreq,CtPerHz);
    // PrintHexLL(Buffer,TempCount);
    // printf(" Count: %s ",Buffer);
    EnableDDS();
    WriteDDS(TempCount.fx_32.high);
    Serial.println("running\n");
    // Zero-beat oscillator to 10 MHz GPS-locked reference
    printf("Zero beat DDS oscillator against GPS\n");
    TempFreq.fx_64 = CALFREQ;
    u8x8.clearDisplay();
    byte ln = 0;
    u8x8.drawString(0,ln++,"10 MHz Zero Beat");
    u8x8.drawString(0,ln++,"<- Joystick ->");
    u8x8.drawString(0,ln++," Button = set ");
    int32_t OldOffset = OscOffset;
    while (analogRead(PIN_JOYBUTTTON) > 500) {
    int ai = analogRead(PIN_JOY_Y) – 512; // totally ad-hoc axes
    if (ai < -100) {
    OscOffset += 1;
    }
    else if (ai > 100) {
    OscOffset -= 1;
    }
    if (OscOffset != OldOffset) {
    ln = 4;
    sprintf(Buffer,"Offset %8ld",OscOffset);
    u8x8.drawString(0,ln++,Buffer);
    CalcOscillator(OscOffset); // recalculate constants
    TempCount.fx_64 = MultiplyFixedPt(TempFreq,CtPerHz); // recalculate delta phase count
    WriteDDS(TempCount.fx_32.high); // should be 10 MHz out!
    OldOffset = OscOffset;
    }
    Wire.requestFrom(LM75_ADDR,2);
    Temperature.fx_32.high = Wire.read();
    Temperature.fx_32.low = (uint32_t)Wire.read() << 24;
    PrintFixedPtRounded(Buffer,Temperature,3);
    ln = 7;
    u8x8.drawString(0,ln,"DDS Temp");
    u8x8.drawString(16-strlen(Buffer),ln++,Buffer);
    delay(100);
    }
    printf("Oscillator offset: %ld\n",OscOffset);
    u8x8.clearDisplay();
    Serial.println("\nStartup done\n");
    MillisThen = millis();
    }
    //———–
    void loop () {
    byte ln;
    union ll_u Temp;
    u8x8.setPowerSave(0);
    u8x8.clearDisplay();
    ln = 0;
    u8x8.draw2x2String(0,2*ln++,"Press");
    u8x8.draw2x2String(0,2*ln++,"Button");
    u8x8.draw2x2String(0,2*ln++,"To Start");
    u8x8.draw2x2String(0,2*ln++,"Test");
    printf("Waiting for button press: ");
    WaitButtonDown();
    printf("\n");
    u8x8.clearDisplay();
    // u8x8.setPowerSave(1);
    // Report temperature
    Wire.requestFrom(LM75_ADDR,2);
    Temperature.fx_32.high = Wire.read();
    Temperature.fx_32.low = (uint32_t)Wire.read() << 24;
    PrintFixedPtRounded(Buffer,Temperature,3);
    printf("Oscillator temperature: %s C\n",Buffer);
    ln = 3;
    u8x8.drawString(0,ln,"DDS Temp");
    u8x8.drawString(16-strlen(Buffer),ln,Buffer);
    // First scan: CX shorted
    digitalWrite(PIN_CX_SHORT,HIGH);
    delay(10);
    ScanCrystal();
    SeriesPeakLow = PeakFreq;
    PrintFixedPtRounded(Buffer,PeakFreq,2); // report peak freq
    printf("\nPeak: %s Hz",Buffer);
    PrintFixedPtRounded(Buffer,PeakdB,1); // tack on response
    printf(" %s dbV\n",Buffer);
    // Second scan: CX in circuit
    digitalWrite(PIN_CX_SHORT,LOW);
    delay(10);
    ScanFrom.fx_64 = SeriesPeakLow.fx_64 – (2 * ONE_FX); // tighten scan limits
    ScanFrom.fx_32.low = 0;
    ScanTo.fx_64 = SeriesPeakLow.fx_64 + (4 * ONE_FX);
    ScanTo.fx_32.low = 0;
    ScanCrystal();
    SeriesPeakHigh = PeakFreq;
    PrintFixedPtRounded(Buffer,PeakFreq,2); // report peak freq
    printf("\nPeak: %s Hz",Buffer);
    PrintFixedPtRounded(Buffer,PeakdB,1); // tack on response
    printf(" %s dbV\n",Buffer);
    ln = 0;
    u8x8.draw2x2String(0,ln," -Done- ");
    ln +=2;
    u8x8.clearLine(ln);
    ln = 6;
    Temp.fx_64 = SeriesPeakHigh.fx_64 – SeriesPeakLow.fx_64;
    PrintFixedPtRounded(Buffer,Temp,2);
    printf("Delta frequency: %s\n",Buffer);
    u8x8.drawString(0,ln,"Delta freq");
    u8x8.drawString(16-strlen(Buffer),ln,Buffer);
    ln = 7;
    u8x8.drawString(0,ln,"Press button …");
    u8x8.setPowerSave(0);
    WaitButtonDown();
    WaitButtonUp();
    }

     

  • Giant Mushrooms!

    It’s apparently been a good year for mushrooms at Vassar Farm:

    Vassar Farm Mushrooms
    Vassar Farm Mushrooms

    My eyeblink reaction was “Wow! Those grew fast!” but they’re an Art on the Farm installation.

  • Monthly Science: Cheap WS2812 LED Failures

    The two knockoff Neopixel test fixtures went dark while their USB charger accompanied me on a trip, so they spent a few days at ambient basement conditions. When I plugged them back into the charger, pretty much the entire array lit up in pinball panic mode:

    WS2812 LED - test fixture multiple failures
    WS2812 LED – test fixture multiple failures

    Turns out three more WS2812 chips failed in quick succession. I’ve hotwired around the deaders (output disconnected, next chip input in parallel) and, as with the other zombies, they sometimes work and sometimes flicker. That’s five failures in 28 LEDs over four months, a bit under 3000 operating hours.

    For lack of a better explanation: the cool chips pulled relatively moist air through their failed silicone encapsulation, quietly rotted out in the dark, then failed when reheated. After they spend enough time flailing around, the more-or-less normal operating temperatures drives out the moisture and they (sometimes) resume working.

    Remember, all of them passed the Josh Sharpie Test, so you can’t identify weak ones ahead of time.

  • Ersatz Yellow Pages Scam

    These mailings generally carry a “trash before reading” interest level, but this one stands out:

    Biz Directory Scam - the deal
    Biz Directory Scam – the deal

    The Terms and Conditions feature some gems:

    Biz Directory Scam - Terms and Conditions
    Biz Directory Scam – Terms and Conditions

    The first few sections suggest their past behavior has required some … admissions … to avoid future issues.

    Section 9 says the laws of Florida apply and the “agreement is performable” (whatever that means) “at United Directories’ address located in Jacksonville Beach, Florida”. They’re so afraid of their customers that the only address appearing on the mailer is in Atlanta, Georgia, but a bit of poking around suggests their HQ is inside what looks like a beachfront house across from Joe’s Crab Shack or a biz building up the street.

    Section 11 says your “listing” will be renewed every six months at $396, so you pay nigh onto 800 bucks a year for a “customizable web page” nobody visits.

    Section 12 tells you “Unpaid accounts will incur a 10% late charge” and “Any credits will be applied to the next subscription period.”

    This will come as no surprise:

    http://www.cbsnews.com/news/phony-phone-directory-fla-firm-guilty-of-425-million-fraud-trading-on-yellow-pages-name-say-prosecutors/

    Searching for obvious keywords + scam won’t turn up any surprises, either.

    Sad fact: they actually have some listings.

    I wish no ill will on anyone, but if somebody’s gotta be under the next meteor strike, I have a short list of candidates …

  • Arduino Joystick: Button Pullup FAIL

    I wired a resistive joystick to the knockoff Nano controlling the crystal tester and connected the button to an analog input because I have a lot of those left over and why not. Unfortunately, the ADC returned a sequence of random-ish numbers indicating the button didn’t have a pullup to +5 V.

    One might be forgiven for assuming the pads marked R5 would hold such a pullup resistor, had the joystick not been relentlessly cost-reduced:

    Keyes resistive joystick - R5 location
    Keyes resistive joystick – R5 location

    One would, of course, be completely wrong.

    Having been around this block several times, I measured the pad-to-pin resistances and found R5 firmly affixed to the GND and +5V pins, with the SW (a.k.a. button) pin floating free. Pressing the joystick hat closes the switch next to R5, thereby connecting the SW pin to GND.

    Baffles me. Maybe a fresh intern did the PCB layout and just misplaced the resistor?

    So I soldered an ordinary resistor (*) between the +5 V and SW pins:

    Keyes resistive joystick - button pullup
    Keyes resistive joystick – button pullup

    Now it works just as it should.

    (*) For long-lost reasons, I have a zillion 12.4 kΩ 1% resistors appearing in place of simple 10 kΩ resistors.

     

  • HP 7475A Plotter: Pen Carousel Geneva Drive

    A note arrived from someone who obviously couldn’t pass up an orphaned HP 7475A plotter:

    The plotter I received works beautifully, except that the carousel doesn’t rotate. I found a YouTube video showing a 7475a running with the cover off, and there’s a little plastic piece – it looks like a teardrop – that advances the carousel, and is apparently part of the carousel motor assembly. Mine is missing that piece …

    The keyword is Geneva drive, a wonderfully simple technique to convert one rotation of the stepper motor into 1/6 turn of the pen carousel, with no need for fancy sensors.

    The (unofficial) HP Computer Museum has All The HP 7475A Documents and the Plotter Service Manual shows All The Parts. And, of course, I’ve written a bit about my adventures with an old 7475A.

    Back in the day, you could get the entire Pen Carousel Housing Assembly w/ Motor (PN 07475-60175) as a unit and the Carousel Motor Only (PN 3140-0687) as a separate thing, but not the Geneva drive wheel:

    HP7475A Carousel - Geneva drive cam
    HP7475A Carousel – Geneva drive cam

    The cam’s drive wheel end (in inches, because early 1980s):

    • 0.25 thick overall
    • 0.10 thick plate under pin end
    • 1.09 OD – rounded end

    The pin sticking up from the cam:

    • 0.154 OD (or fit to slot?)
    • 0.16 tall (above base plate)

    I have no good (i.e., easy + accurate) way to measure the distance from the motor shaft to the pin, but I doubt it’s critical. As long as the pin doesn’t quite whack the hub end of the slot, it’s all good:

    HP7475A Carousel - cam driving
    HP7475A Carousel – cam driving

    The 0.10 plate + 0.16 pin height don’t quite add up to the 0.25 overall measurement, but that’s certainly measurement error. I’d round the pin length downward and carve the drive from a 1/4 inch sheet.

    A 3D printed part would probably work, apart from the accuracy required to fit the D-shaped motor shaft. Perhaps a round hole, reamed to fit the shaft, carefully aligned / positioned, with epoxy filling the D-shaped void, would suffice. A dent in the round hole would give the epoxy something to grab.

    I’d be sorely tempted to use an actual metal / plastic rod for the pin, rather than depend on a stack of semi-fused plastic disks. The pin must withstand hitting the end of the “missing” slot during the power-on indexing rotation, because turning the carousel isn’t quite a non-contact sport. Normally, though, it enters the end of the slot without much fuss:

    HP7475A Carousel - cam engaging
    HP7475A Carousel – cam engaging

    The blocked slot sits at the bottom of that picture, with a small locating pin sticking upward just above the circular feature at the end of the arm: we’re seeing the negative of a plug inserted into the original injection mold.

    With a bit of luck, another HP 7475A plotter will fascinate everybody within hearing distance!

    [Update: It lives! ]

  • LM75A vs. SOIC Adapter: Mirror Imaging

    After hairballing an LM75A I²C temperature sensor to verify at least one of the eBay lot worked, a bag of SOIC-to-DIP space transformers arrived, so I soldered up another LM75A:

    LM75A on DIP8 adapter - top
    LM75A on DIP8 adapter – top

    The SOIC chip pattern sits at right angles to the DIP pins, which took some getting used to.

    The slightly defocused wire connecting pin 4 (on the IC) to pins 5, 6, and 7 (on the PCB) selects address 0x48.

    So I flipped it over, soldered four wires (+5 V, GND, SDA, SCL) to the numbered pins on bottom of the board, made up a little header for the other end, wired a socket strip on the crystal tester board, plugged it in, and … nothing worked.

    Turns out that the other side of the board carries a TSSOP pattern, which I’d neatly masked off with a snippet of Kapton tape, surrounded by eight numbered pins. Of course, those pin numbers correspond to the TSSOP pattern facing you, so they’re mirror-imaged for the SOIC pattern on the other side.

    Soooo, the proper wiring for the SOIC pattern as seen from the TSSOP side has the pin numbers exactly bass-ackwards:

    LM75A on DIP8 adapter - bottom
    LM75A on DIP8 adapter – bottom

    The insulation looked a lot better the first time I soldered the wires to the PCB. Honest.

    Anyhow, when correctly wired, the LM75A worked as it should:

    LM75A Temperature Sensor - installed
    LM75A Temperature Sensor – installed

    It’s snuggled chip-down against the top of the 125 MHz oscillator can, with a dab of heatsink compound improving their thermal bond and a yellow cable tie around the foam holding them together. The socket header is wired pin-for-pin to the DAC I²C socket directly above it.

    The OLED temperature display shows 28.250 °C, because the oscillator just started up in a cool basement. It’ll eventually settle around 39-ish °C, where its output should be pretty close to the 125 MHz – 344 Hz value hardcoded into the source.

    Oh, that’s a 3 mm amber LED next to the relay can: much less glaring than the white LED, no matter what it looks like here.