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.

Month: May 2017

  • Arduino vs. Significant Figures: Preliminary 64-bit Fixed Point Exercise

    Although it’s not advertised, the Arduino / AVR compiler mostly does the right thing with long long = uint64_t variables: add & subtract work fine, but multiplication & division discard anything that doesn’t fit into 64 bits. Fitting a 32 bit integer and a 32 bit fraction into such a thing should eliminate (most) problems with significant figures.

    The general idea is to set up a struct giving access to the two 32 bit halves for direct manipulation, then overlay / union them with a single 64 bit integer for arithmetic purposes:

    struct ll_s {
      uint32_t low;
      uint32_t high;
    };
    
    union ll_u {
      uint64_t ll_64;
      struct ll_s ll_32;
    };
    

    Of course, the integer part still falls one bit shy of holding 2³². At the cost of one bit’s worth of resolution, you can still compute 2³² / 125×10⁶ by pre-dividing each quantity by 2:

    2^63 = [80000000 00000000]
    2^63 / 125/2 M = [00000022 5c17d04d]
    

    The low-order digit should be 0xe, not 0xd, but I think that’s survivable.

    Unfortunately, printf doesn’t handle 64 bit quantities, necessitating some awkward conversion routines. “Printing” to a string seems the least awful method, as I’ll eventually squirt the strings to a display, not send them to the serial port:

    void PrintFractionLL(char *pBuffer,uint64_t *pLL) {
      uint64_t Fraction;
    
      Fraction = (uint32_t)*pLL;                      // copy 32 fraction bits, high order = 0
      Fraction *= ONEGIG;                             // times 10^9 for conversion
      Fraction >>= 32;                                // align integer part in low long
      sprintf(pBuffer,"%09lu",(uint32_t)Fraction);    // convert low long to decimal
    }
    
    void PrintIntegerLL(char *pBuffer,uint64_t *pLL) {
      sprintf(pBuffer,"%lu",*((uint32_t *)pLL+1));
    }
    
    void PrintDecimalLL(char *pBuffer,uint64_t *pLL) {
      PrintIntegerLL(pBuffer,pLL);
      pBuffer += strlen(pBuffer);       // pointer to end of integer part
      *pBuffer++ = '.';                 // drop in the decimal point, tick pointer
      PrintFractionLL(pBuffer,pLL);
    }
    

    The result seems nearly indistinguishable from the Right Answer:

    Integer:  34
    Fraction: 359738367
    Decimal: 34.359738367
    

    This whole mess has a bunch of rough edges, but it looks promising. The code coalesced while fiddling around, so the union notation didn’t get much love at first.

    The Arduino source code as a GitHub Gist:

    Long long integer exercise
    Ed Nisley – KE4ZNU – May 2017
    Long long size = 8 bytes
    .. value = [12345678 9abcdef0]
    divided result = [01234567 89abcdef]
    2^32 = [00000001 00000000]
    125M = [00000000 07735940]
    2^32 / 125M = [00000000 00000022]
    Scaled fixed point tests
    2^63 = [80000000 00000000]
    2^63 / 125/2 M = [00000022 5c17d04d]
    Integer: 34
    Fraction: 359738367
    Decimal: 34.359738367
    Hz Per Ct: 0.029103830
    60000: 60000.000000000
    60 kHz as count: 2061584.302070550
    0.1 Hz as count: 3.435973836
    60000.1 Hz as count: 2061587.738044387
    60000.1 Hz from count: 60000.078519806
    60000.2 Hz as count: 2061591.174018223
    60000.2 Hz from count: 60000.194935128
    60000.2 Hz rnd count: 60000.224038958
    Union size: 8
    TestFreq: [0000ea60 395a9e00]
    Union ll: [0000ea60 395a9e00]
    From union: 60000.224038958
    Buffer length: 15
    Trunc dec: 60000.224
    view raw LongLong.txt hosted with ❤ by GitHub
    // Long long integer exercise for 60 kHz crystal tester
    //– Helper routine for printf()
    int s_putc(char c, FILE *t) {
    Serial.write(c);
    }
    char Buffer[10+1+10]; // string buffer for long long conversions
    #define ONEGIG 1000000000LL
    uint64_t CtPerHz; // will be 2^32 / 125 MHz
    uint64_t HzPerCt; // will be 125 MHz / 2^32
    uint64_t TenthHzCt; // 0.1 Hz in counts
    struct ll_s {
    uint32_t low;
    uint32_t high;
    };
    union ll_u {
    uint64_t ll_64;
    struct ll_s ll_32;
    };
    //———–
    // Long long print-to-buffer helpers
    // Assumes little-Endian layout
    void PrintHexLL(char *pBuffer,uint64_t *pLL) {
    sprintf(pBuffer,"%08lx %08lx",*((uint32_t *)pLL+1),(uint32_t)*pLL);
    }
    // converts 9 decimal digits
    void PrintFractionLL(char *pBuffer,uint64_t *pLL) {
    uint64_t Fraction;
    Fraction = (uint32_t)*pLL; // copy 32 fraction bits, high order = 0
    Fraction *= ONEGIG; // times 10^9 for conversion
    Fraction >>= 32; // align integer part in low long
    sprintf(pBuffer,"%09lu",(uint32_t)Fraction); // convert low long to decimal
    }
    void PrintIntegerLL(char *pBuffer,uint64_t *pLL) {
    sprintf(pBuffer,"%lu",*((uint32_t *)pLL+1));
    }
    void PrintDecimalLL(char *pBuffer,uint64_t *pLL) {
    PrintIntegerLL(pBuffer,pLL);
    pBuffer += strlen(pBuffer); // pointer to end of integer part
    *pBuffer++ = '.'; // drop in the decimal point, tick pointer
    PrintFractionLL(pBuffer,pLL);
    }
    //———–
    void setup ()
    {
    Serial.begin (115200);
    fdevopen(&s_putc,0); // set up serial output for printf()
    Serial.println ("Long long integer exercise");
    Serial.println ("Ed Nisley – KE4ZNU – May 2017");
    unsigned long long LongLong;
    uint64_t LongLong2;
    LongLong = 0x123456789abcdef0LL;
    printf("Long long size = %d bytes\n",sizeof(LongLong));
    printf(" .. value = [%08lx %08lx]\n",(long)(LongLong >> 32),(long)(LongLong & 0x00000000ffffffffLL));
    LongLong /= 16;
    printf(" divided result = [%08lx %08lx]\n",(long)(LongLong >> 32),(long)LongLong);
    LongLong = 1LL << 32;
    printf(" 2^32 = [%08lx %08lx]\n",(long)(LongLong >> 32),(long)LongLong);
    LongLong2 = 125000000LL;
    printf(" 125M = [%08lx %08lx]\n",(long)(LongLong2 >> 32),(long)LongLong2);
    LongLong /= LongLong2;
    printf("2^32 / 125M = [%08lx %08lx]\n",(long)(LongLong >> 32),(long)LongLong);
    Serial.println("Scaled fixed point tests");
    uint64_t TestFreq,TestCount;
    CtPerHz = 1LL << 63; // start with 2^31 to avoid overflow
    PrintHexLL(Buffer,&CtPerHz);
    printf("2^63 = [%s]\n",Buffer);
    CtPerHz /= 125000000LL / 2; // divided by 2 to to match 2^31
    PrintHexLL(Buffer,&CtPerHz);
    printf("2^63 / 125/2 M = [%s]\n",Buffer);
    PrintIntegerLL(Buffer,&CtPerHz);
    printf("Integer: %s\n",Buffer);
    PrintFractionLL(Buffer,&CtPerHz);
    printf("Fraction: %s\n",Buffer);
    PrintDecimalLL(Buffer,&CtPerHz);
    printf("Decimal: %s\n",Buffer);
    HzPerCt = 125000000LL; // 125 MHz / 2^32, directly to fraction part
    PrintDecimalLL(Buffer,&HzPerCt);
    printf("Hz Per Ct: %s\n",Buffer);
    TestFreq = 60000LL << 32;
    PrintDecimalLL(Buffer,&TestFreq);
    printf("60000: %s\n",Buffer);
    TestCount = 60000LL * CtPerHz;
    PrintDecimalLL(Buffer,&TestCount);
    printf("60 kHz as count: %s\n",Buffer);
    TenthHzCt = CtPerHz / 10; // 0.1 Hz as counts
    PrintDecimalLL(Buffer,&TenthHzCt);
    printf("0.1 Hz as count: %s\n",Buffer);
    TestCount += TenthHzCt;
    PrintDecimalLL(Buffer,&TestCount);
    printf("60000.1 Hz as count: %s\n",Buffer);
    TestFreq = (TestCount >> 32) * HzPerCt;
    PrintDecimalLL(Buffer,&TestFreq);
    printf("60000.1 Hz from count: %s\n",Buffer);
    TestCount = (60000LL * CtPerHz) + (2 * TenthHzCt);
    PrintDecimalLL(Buffer,&TestCount);
    printf("60000.2 Hz as count: %s\n",Buffer);
    TestFreq = (TestCount >> 32) * HzPerCt;
    PrintDecimalLL(Buffer,&TestFreq);
    printf("60000.2 Hz from count: %s\n",Buffer);
    TestFreq = ((TestCount + (TenthHzCt / 2)) >> 32) * HzPerCt;
    PrintDecimalLL(Buffer,&TestFreq);
    printf("60000.2 Hz rnd count: %s\n",Buffer);
    union ll_u LongLongUnion, TempLLU;
    printf("Union size: %d\n",sizeof(LongLongUnion));
    LongLongUnion.ll_64 = TestFreq;
    PrintHexLL(Buffer,&TestFreq);
    printf("TestFreq: [%s]\n",Buffer);
    PrintHexLL(Buffer,&LongLongUnion.ll_64);
    printf("Union ll: [%s]\n",Buffer);
    TempLLU.ll_64 = LongLongUnion.ll_32.low;
    TempLLU.ll_64 *= ONEGIG; // times 10^9 for conversion
    TempLLU.ll_64 >>= 32; // align integer part in low long
    sprintf(Buffer,"%lu.%09lu",LongLongUnion.ll_32.high,TempLLU.ll_32.low);
    printf("From union: %s\n",Buffer);
    sprintf(Buffer,"%lu.%09lu",LongLongUnion.ll_32.high,TempLLU.ll_32.low);
    printf("Buffer length: %d\n",strlen(Buffer));
    Buffer[strlen(Buffer) – 9 + 3] = 0;
    printf(" Trunc dec: %s\n",Buffer);
    }
    //———–
    void loop () {
    }
  • Arduino vs Significant Figures: Floating Point Calculations

    Herewith, to nail down the reasons why you can’t (or, perhaps, shouldn’t) use Arduino float variables, a small collection of DDS-oid calculations.

    Remember that float and double variable are both IEEE 754 single-precision floating point numbers:

    Size of float: 4
           double: 4
    

    The Arduino floating-point formatter gags on some values, although they calculate correctly:

    2^24: 16777216.000
    printf:        ?
    2^32: ovf or ovf
    2^32: ovf
    2^32 / 256: 16777216.000
    

    Don’t add values differing by more than seven orders of magnitude and suspect any results beyond the first half-dozen significant figures:

    Oscillator steps: HzPerCt
     Oscillator: 125000000.00
     -25 -> 0.02910382461
     -24 -> 0.02910382461
     -23 -> 0.02910382461
     -22 -> 0.02910382461
     -21 -> 0.02910382461
     -20 -> 0.02910382747
     -19 -> 0.02910382747
     -18 -> 0.02910382747
     -17 -> 0.02910382747
     -16 -> 0.02910382747
     -15 -> 0.02910382747
     -14 -> 0.02910382747
     -13 -> 0.02910382747
     -12 -> 0.02910382747
     -11 -> 0.02910382747
     -10 -> 0.02910382747
      -9 -> 0.02910382747
      -8 -> 0.02910382747
      -7 -> 0.02910382747
      -6 -> 0.02910382747
      -5 -> 0.02910382747
      -4 -> 0.02910383033
      -3 -> 0.02910383033
      -2 -> 0.02910383033
      -1 -> 0.02910383033
      +0 -> 0.02910383033
    

    The Arduino source code as a GitHub Gist:

    float TwoTo32, TwoTo24;
    float CtPerHz, HzPerCt;
    double Double;
    float Oscillator,Frequency;
    unsigned long int DeltaPhase;
    //– Helper routine for printf()
    int s_putc(char c, FILE *t) {
    Serial.write(c);
    }
    //– Calculate delta phase from output & oscillator
    uint32_t CalculateDP(float Freq, float Osc) {
    uint32_t DP;
    Serial.print("Freq: ");
    Serial.print(Freq,3);
    Serial.print(" Osc: ");
    Serial.print(Osc,3);
    DP = Freq * TwoTo32 / Osc;
    printf(" -> DP: %lu = 0x%08lx\n",DP,DP);
    return DP;
    }
    //– Calculate frequency from delta phase & oscillator
    float CalculateFreq(uint32_t DP, float Osc) {
    float Freq;
    Freq = DP * Osc / TwoTo32;
    printf("DP: %lu = 0x%08lx ",DP,DP);
    Serial.print(" Osc: ");
    Serial.print(Osc,3);
    Serial.print(" -> Freq: ");
    Serial.println(Freq,3);
    return Freq;
    }
    //——————
    void setup() {
    Serial.begin(115200);
    fdevopen(&s_putc,0); // set up serial output for printf()
    Serial.println (F("DDS Numeric Values"));
    Serial.println (F("Ed Nisley – KE4ZNU – May 2017\n"));
    printf("Size of float: %u\n",sizeof(TwoTo32));
    printf(" double: %u\n",sizeof(Double));
    TwoTo24 = pow(2.0,24);
    Serial.print("2^24: ");
    Serial.println(TwoTo24,3);
    printf("printf: %8.8f\n",TwoTo24);
    TwoTo32 = pow(2,32);
    Serial.print("2^32: ");
    Serial.print(TwoTo32,3);
    Serial.print(" or ");
    Serial.println(TwoTo32,3);
    TwoTo32 = 4294967296.0;
    Serial.print("2^32: ");
    Serial.println(TwoTo32,0);
    Serial.print("2^32 / 256: ");
    Serial.println(TwoTo32 / 256.0,3);
    Oscillator = 125e6;
    Serial.print("Oscillator: ");
    Serial.println(Oscillator,3);
    Frequency = 10e6;
    Serial.print("Frequency: ");
    Serial.println(Frequency,3);
    HzPerCt = Oscillator / TwoTo32;
    Serial.print("HzPerCt: ");
    Serial.println(HzPerCt,9);
    CtPerHz = TwoTo32 / Oscillator;
    Serial.print("CtPerHz: ");
    Serial.println(CtPerHz,9);
    Frequency = 10e6 + 0.0;
    DeltaPhase = Frequency * CtPerHz;
    Serial.print(Frequency,3);
    printf(": Delta Phase: %lu = %08lx\n",DeltaPhase,DeltaPhase);
    Frequency = 10e6 + 0.5;
    DeltaPhase = Frequency * CtPerHz;
    Serial.print(Frequency,3);
    printf(": Delta Phase: %lu = %08lx\n",DeltaPhase,DeltaPhase);
    Frequency = 10e6 + 0.8;
    DeltaPhase = Frequency * CtPerHz;
    Serial.print(Frequency,3);
    printf(": Delta Phase: %lu = %08lx\n",DeltaPhase,DeltaPhase);
    Frequency = 10e6 + 1.0;
    DeltaPhase = Frequency * CtPerHz;
    Serial.print(Frequency,3);
    printf(": Delta Phase: %lu = %08lx\n",DeltaPhase,DeltaPhase);
    Serial.println("Oscillator steps: HzPerCt");
    Serial.print(" Oscillator: ");
    Serial.println(Oscillator,2);
    for (int i=-25; i<=25; i++) {
    HzPerCt = (Oscillator + i) / TwoTo32;
    printf(" %+3d -> ",i);
    Serial.println(HzPerCt,11);
    }
    Serial.println("Oscillator tune: CtPerHz ");
    Serial.print(" Oscillator: ");
    Serial.println(Oscillator,2);
    for (int i=-25; i<=25; i++) {
    CtPerHz = TwoTo32 / (Oscillator + i);
    printf(" %+3d -> ",i);
    Serial.println(CtPerHz,11);
    }
    // printf("CtPerHz int: %lu = %08lx\n",long(CtPerHz),long(CtPerHz));
    }
    //——————
    void loop() {}
    view raw FloatTest.ino hosted with ❤ by GitHub
    DDS Numeric Values
    Ed Nisley – KE4ZNU – May 2017
    Size of float: 4
    double: 4
    2^24: 16777216.000
    printf: ?
    2^32: ovf or ovf
    2^32: ovf
    2^32 / 256: 16777216.000
    Oscillator: 125000000.000
    Frequency: 10000000.000
    HzPerCt: 0.029103830
    CtPerHz: 34.359737396
    10000000.000: Delta Phase: 343597376 = 147ae140
    10000000.000: Delta Phase: 343597376 = 147ae140
    10000001.000: Delta Phase: 343597408 = 147ae160
    10000001.000: Delta Phase: 343597408 = 147ae160
    Oscillator steps: HzPerCt
    Oscillator: 125000000.00
    -25 -> 0.02910382461
    -24 -> 0.02910382461
    -23 -> 0.02910382461
    -22 -> 0.02910382461
    -21 -> 0.02910382461
    -20 -> 0.02910382747
    -19 -> 0.02910382747
    -18 -> 0.02910382747
    -17 -> 0.02910382747
    -16 -> 0.02910382747
    -15 -> 0.02910382747
    -14 -> 0.02910382747
    -13 -> 0.02910382747
    -12 -> 0.02910382747
    -11 -> 0.02910382747
    -10 -> 0.02910382747
    -9 -> 0.02910382747
    -8 -> 0.02910382747
    -7 -> 0.02910382747
    -6 -> 0.02910382747
    -5 -> 0.02910382747
    -4 -> 0.02910383033
    -3 -> 0.02910383033
    -2 -> 0.02910383033
    -1 -> 0.02910383033
    +0 -> 0.02910383033
    +1 -> 0.02910383033
    +2 -> 0.02910383033
    +3 -> 0.02910383033
    +4 -> 0.02910383033
    +5 -> 0.02910383224
    +6 -> 0.02910383224
    +7 -> 0.02910383224
    +8 -> 0.02910383224
    +9 -> 0.02910383224
    +10 -> 0.02910383224
    +11 -> 0.02910383224
    +12 -> 0.02910383224
    +13 -> 0.02910383224
    +14 -> 0.02910383224
    +15 -> 0.02910383224
    +16 -> 0.02910383224
    +17 -> 0.02910383224
    +18 -> 0.02910383224
    +19 -> 0.02910383224
    +20 -> 0.02910383224
    +21 -> 0.02910383701
    +22 -> 0.02910383701
    +23 -> 0.02910383701
    +24 -> 0.02910383701
    +25 -> 0.02910383701
    Oscillator tune: CtPerHz
    Oscillator: 125000000.00
    -25 -> 34.35974502563
    -24 -> 34.35974502563
    -23 -> 34.35974502563
    -22 -> 34.35974502563
    -21 -> 34.35974502563
    -20 -> 34.35974121093
    -19 -> 34.35974121093
    -18 -> 34.35974121093
    -17 -> 34.35974121093
    -16 -> 34.35974121093
    -15 -> 34.35974121093
    -14 -> 34.35974121093
    -13 -> 34.35974121093
    -12 -> 34.35974121093
    -11 -> 34.35974121093
    -10 -> 34.35974121093
    -9 -> 34.35974121093
    -8 -> 34.35974121093
    -7 -> 34.35974121093
    -6 -> 34.35974121093
    -5 -> 34.35974121093
    -4 -> 34.35973739624
    -3 -> 34.35973739624
    -2 -> 34.35973739624
    -1 -> 34.35973739624
    +0 -> 34.35973739624
    +1 -> 34.35973739624
    +2 -> 34.35973739624
    +3 -> 34.35973739624
    +4 -> 34.35973739624
    +5 -> 34.35973739624
    +6 -> 34.35973739624
    +7 -> 34.35973739624
    +8 -> 34.35973739624
    +9 -> 34.35973739624
    +10 -> 34.35973739624
    +11 -> 34.35973739624
    +12 -> 34.35973358154
    +13 -> 34.35973358154
    +14 -> 34.35973358154
    +15 -> 34.35973358154
    +16 -> 34.35973358154
    +17 -> 34.35973358154
    +18 -> 34.35973358154
    +19 -> 34.35973358154
    +20 -> 34.35973358154
    +21 -> 34.35973358154
    +22 -> 34.35973358154
    +23 -> 34.35973358154
    +24 -> 34.35973358154
    +25 -> 34.35973358154
    view raw FloatTest.txt hosted with ❤ by GitHub
  • DDS Musings: Arithmetic with 32-bit Fixed Point Numbers

    Spoiler alert: having spent a while trying to fit the DDS calculations into fixed-point numbers stuffed into a single 32 bit unsigned long value, it’s just a whole bunch of nope.

    The basic problem, as alluded to earlier, comes from calculations on numbers near 32768.0 and 60000.0 Hz, which require at least 6 significant digits. Indeed, 0.1 Hz at 60 kHz works out to 1.7 ppm, so anything around 0.05 Hz requires seven digits.

    The motivation for fixed-point arithmetic, as alluded to earlier, comes from the amount of program memory and RAM blotted up by the BigNumber arbitrary precision arithmetic library, which seems like a much bigger hammer than necessary for this problem.

    So, we begin.

    Because the basic tuning increment works out to 0.0291 Hz, you can’t adjust the output frequency in nice, clean 0.01 Hz clicks. That doesn’t matter, as long as you know the actual frequency with some accuracy.

    Setting up the DDS requires calculations involving numbers near 125.000000 MHz and 2³², both of which sport nine or ten significant figures, depending on how fussy you are about calibrating the actual oscillator frequency and how you go about doing it. Based on a sample of one AD8950 DDS board, the 125 MHz oscillator runs 300 to 400 Hz below its nominal 125 MHz: about 3 ppm low, with a -2.3 Hz/°C tempco responding to a breath. It’s obviously not stable enough for precise calibration, but even 1 ppm = 125 Hz chunks seem awkwardly large.

    Many of the doodles below explore various ways to fit integer values up to 125 MHz and fractions down to 0.0291 Hz/count into fixed point numbers with 24 integer bits + 8 fraction bits, perhaps squeezed a few bits either way. Fairly obviously, at least in retrospect, it can’t possibly work: 125×10⁶ requires 28 bits. Worse, 8 fraction bits yield steps of 0.0039, so you start with crappy resolution.

    The DDS tuning word is about 2×10⁶ for outputs around 60 kHz, barely covered by 21 bits. You really need at least seven significant figures = 0.1 ppm for those computations, which means the 125 MHz / 2³² ratio must carry seven significant figures, which means eight decimal places: 0.02910383 and not a digit less.

    En passant, it’s disturbing how many Arduino DDS libraries declare all their variables as double and move on as if the quantities were thereby encoded in 64 bit floating point numbers. Were that the case, I’d agree 125e6 / pow(2.0,32) actually meant something, but it ain’t so.

    The original non-linear doodles, which, despite containing some values useful in later computations, probably aren’t worth your scrutiny:

    AD9850 DDS Fixed-point Number Doodles - 1
    AD9850 DDS Fixed-point Number Doodles – 1
    AD9850 DDS Fixed-point Number Doodles - 2
    AD9850 DDS Fixed-point Number Doodles – 2
    AD9850 DDS Fixed-point Number Doodles - 3
    AD9850 DDS Fixed-point Number Doodles – 3
    AD9850 DDS Fixed-point Number Doodles - 4
    AD9850 DDS Fixed-point Number Doodles – 4
    AD9850 DDS Fixed-point Number Doodles - 5
    AD9850 DDS Fixed-point Number Doodles – 5
    AD9850 DDS Fixed-point Number Doodles - 6
    AD9850 DDS Fixed-point Number Doodles – 6
    AD9850 DDS Fixed-point Number Doodles - 7
    AD9850 DDS Fixed-point Number Doodles – 7
    AD9850 DDS Fixed-point Number Doodles - 8
    AD9850 DDS Fixed-point Number Doodles – 8
  • Beckman DM73 Circuitmate: RIP

    I’d added Mad Phil’s trusty Circuitmate to the tool kit I carry along to Squidwrench:

    Beckman DM73 - new ground clip
    Beckman DM73 – new ground clip

    Over the last few months it became increasingly erratic, eventually got to the point where slight pressure on the case would blank the display, and finally didn’t turn on at all. Yes, I replaced the batteries.

    So I took it apart:

    Beckman DM73 Circuitmate - case open
    Beckman DM73 Circuitmate – case open

    Nothing seemed particularly broken and, even after resoldering all the joints, it continued to not work at all:

    Beckman DM73 Circuitmate - PCB
    Beckman DM73 Circuitmate – PCB

    If you want to try your hand at instrument rehabilitation, let me know.

    [Update:It’s back from the dead !]

  • Mystery Pigeon

    Mary spotted this critter atop the roof and, much to my surprise, it waited courteously until I deployed the camera:

    Mystery Pigeon - on roof ridge
    Mystery Pigeon – on roof ridge

    It looks, walks, and acts just like a pigeon:

    Mystery Pigeon - walking on roof ridge
    Mystery Pigeon – walking on roof ridge

    … but we’ve never seen one with those feather patterns & colors. It’s not in any of our books, so it may be an escaped domestic pigeon.

    Those feathers require plenty of body maintenance:

    Mystery Pigeon - body maintenance
    Mystery Pigeon – body maintenance

    As nearly as we can tell, it’s wearing a green leg band with three digits that might be 904:

    Mystery Pigeon - leg band composite
    Mystery Pigeon – leg band composite

    If this was your bird, it flew through Red Oaks Mill NY just after noon on 1 May 2017 …

  • Copying Video Files From Action Cameras to a NAS Drive

    For unknown reasons, a recent VLC update caused it to ignore uppercase file extensions: MP4 and AVI files no longer appear in its directory listings, while mp4 and avi files do. The least-awful solution involved renaming the files after copying them:

    find /mnt/video -name \*AVI -print0 | xargs -0 rename -v -f 's/AVI/avi/'
    find /mnt/video -name \*MP4 -print0 | xargs -0 rename -v -f 's/MP4/mp4/'
    find /mnt/video -name \*THM -print0 | xargs -0 rename -v -f 's/THM/thm/'
    

    Yup, that scans the whole drive every time, which takes care of stray files, manual tweaks, and suchlike. The THM files are useless thumbnails; I should just delete them.

    While I had the hood up, I listed the remaining space on the NAS drive and cleaned up a few misfeatures. I manually delete old video files / directories as needed, usually immediately after the script crashes for lack of room.

    The Sony HDR-AS30V can act as a USB memory device, but it dependably segfaults the ExFAT driver; I now transfer its MicroSD card to an adapter and jam it into the media slot on the monitor, where it works fine.

    Protip: always turn the AS30V on to verify the MicroSD card has seated correctly in its socket. Unfortunately, the socket can also hold Sony’s proprietary Memory Stick Micro cards (32 GB maximum capacity = roadkill), but the dual-use / dual-direction socket isn’t a snug fit around MicroSD cards. You (well, I) can insert a card so it looks fine, while sitting slightly canted and not making proper contact. The camera will kvetch about that and it’s easier to fix with the camera in hand.

    I’ve disabled USB device automounting, as I vastly prefer to handle them manually, so the script asks for permission in order to mount the drives. The transfer requires about an hour, so I’ve extended the time the sudo password remains active.

    The script lets both cards transfer data simultaneously; the Fly6 generally finishes first because it produces less data. That produces a jumbled progress display and the script waits for both drives to finish before continuing.

    The Bash source code as a GitHub Gist:

    #!/bin/sh
    thisdate=$(date –rfc-3339=date)
    echo Date is $thisdate
    date
    # MicroSD cards not automounted
    as30v=/mnt/AS30V
    fly6=/mnt/Fly6
    sudo mount -o uid=ed /dev/sdb1 /mnt/AS30V/
    sudo mount -o uid=ed /dev/sdc1 /mnt/Fly6/
    # IOmega NAS defined as /mnt/video in fstab
    sudo mount /mnt/video
    mkdir /mnt/video/$thisdate
    rsync -ahu –progress $as30v/MP_ROOT/100ANV01/ /mnt/video/$thisdate &
    pid1=$!
    rsync -ahu –progress $fly6 /mnt/video
    date
    rc2=$?
    echo Fly6 RC is $rc2
    echo Waiting for $as30v
    wait $pid1
    rc=$(( $rc2 + $? ))
    date
    echo Overall RC: $rc
    if [ $rc -eq 0 ] ; then
    echo Fix capitalized extensions
    find /mnt/video -name \*AVI -print0 | xargs -0 rename -v -f 's/AVI/avi/'
    find /mnt/video -name \*MP4 -print0 | xargs -0 rename -v -f 's/MP4/mp4/'
    find /mnt/video -name \*THM -print0 | xargs -0 rename -v -f 's/THM/thm/'
    echo Space remaining on NAS drive:
    df -h /mnt/video
    echo Remove files on AS30V
    rm $as30v/MP_ROOT/100ANV01/*
    echo Unmount cards and NAS
    sudo umount $as30v
    sudo umount $fly6
    sudo umount /mnt/video
    else
    echo Whoopsie: $rc
    fi
    view raw savevideo.sh hosted with ❤ by GitHub
  • Generic AD9850 DDS Modules: Beware Swapped D7 and GND Pins!

    Compare this picture:

    AD9850 DDS Module - swapped GND D7 pins
    AD9850 DDS Module – swapped GND D7 pins

    … with any of the doc for the generic AD8950/51 DDS modules you’ll find out on the Interwebs. This snippet from the seller’s schematic will suffice:

    AD9850 module schematic - cropped
    AD9850 module schematic – cropped

    Here’s a closer look at the 2×7 header in the upper left corner:

     

    AD9850 module schematic - J5 detail
    AD9850 module schematic – J5 detail

    Don’t blame me for the blur, the schematic is a JPG.

    Compared it with the board in hand:

    AD9850 DDS Module - swapped GND D7 pins - detail
    AD9850 DDS Module – swapped GND D7 pins – detail

    Yup, the D7 and GND pins are reversed.

    Some careful probing showed the silkscreen is correct: the pins are, in fact, correctly labeled.

    Should you be laying out a PCB in the expectation of using any DDS module from the lowest-price supplier, remember this high truth: Hell hath no fury like that of an unjustified assumption.

    Fortunately, I’m hand-wiring the circuit and caught it prior to the smoke test.