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.

Category: Electronics Workbench

Electrical & Electronic gadgets

  • Mostly Printed CNC: Stepper Drive

    The MPCNC kit includes five Automation Technology KL17H248-15-4A stepper motors:

    MPCNC Stepper label - KL17H248-15-4A
    MPCNC Stepper label – KL17H248-15-4A

    If link rot should set in, a direct rip from the website:

    NEMA 17 BIPOLAR STEPPER MOTOR, KL17H248-15-4A, 76 oz-in

    Specifications:
    Shaft: 5mm diameter with flat
    Current Per Phase: 1.5A
    Holding Torque: 5.5Kg.cm (76 oz-in)
    Rated Voltage: 4.2V
    NO.of Phase: 2
    Step Angle: 1.8° ± 5%
    Resistance Per Phase: 2.8Ω± 10%
    Inductance Per Phase: 4.8mH± 20%
    Insulation Class: Class B
    Dielectric Strength: 100Mohm
    Operation Temp Range: -20 ~ +40° C
    Lead Wire: 22AWG / 750mm with connector to stepper motor driver

    Red- 1A
    Green- 1B
    Yellow- 2A
    Blue- 2B

    A nice torque curve:

    KL17H248-15-4A - Torque curve
    KL17H248-15-4A – Torque curve

    The present MPCNC design wires the motors on each end of X / Y axes in series. Each motor has 2.8 Ω of DC resistance = 5.6 Ω total and, given the small wire gauge (allegedly 22 AWG on the motors and unspecified for any eBay cables) and six (!) teeny header pins in series along the wires for each winding, a total series resistance of 6 Ω seems reasonable and is, in fact, what I measure with an ohmmeter.

    The stepper drivers arrived preset for 1 A peak:

    MPCNC Stepper Drive - as delivered - 500 mA div
    MPCNC Stepper Drive – as delivered – 500 mA div

    The vertical scale is 500 mA/div. The waveform comes from a 10 mm move at 5000 mm/min = 83 mm/s, which is absurdly fast for such a machine, particularly seeing as how the default firmware limits it to 190 mm/min = 3 mm/s. Cutting speeds will be much lower than either of those.

    The default DRV8825 current-setting pot setting was 600 mV, for a nominal current motor current of 1.2 A peak. That’s reasonably close to the measurement, all things considered.

    However, because the motors run from a 12 V supply at 1 A, the winding and wiring losses mean they operate at a bit over 8 V: much much less than the nominal 24 and 32 V plotted in the torque curve. More voltage = faster response to microstep current changes = higher top speed. At sensible speeds, this surely does not matter.

    The default DRV8825 stepper driver module jumpers select 32 microsteps = 6400 step/rev, a factor of four higher than the chart.

    Part of the tweakage will be to sort that out; a 24 V supply may be in order. Driving each motor separately (as required for automatic de-racking homing) at 1.5 A/phase would require 3  1.5×√2 A/motor × 5 motors = 15 10.5 A, which seems excessive even to me, particularly in light of sending it across a RAMPS board. At 1 A/phase, you need 10 7 A, which falls within the realm of reason and would be kinder to the PLA motor mounts. It’s not clear boosting the motor voltage will produce any real benefit, although giving the drivers more headroom seems reasonable.

    The GT2 drive belts have 2 mm pitch, so the 16 tooth drive pulleys move 32 mm/rev and require 200 step/mm, which seems high to me. At a nice round 100 mm/s, the steppers must tick along at 20 k step/s, half of Marlin’s top speed, which may explain some of the roughness around 80 mm/s.

    The torque curve suggests the motors want to run under 200 RPM = 3.3 rev/s = 100 mm/s with the stock 16 tooth pulley. No problem with those numbers!

    Using 16:1 microstepping would produce 3200 step/rev, 100 step/mm, thus half the step rate at any speed. Reducing the driver step frequency can’t possibly be a Bad Thing for Marlin.

  • Mostly Printed CNC: Stepper Wiring

    To the end of documenting colors, connectors, and connections for the MPCNC stepper motors …

    At the stepper motors:

    MPCNC - Stepper Connector
    MPCNC – Stepper Connector

    The plug for the stepper at the end of the harness:

    MPCNC - Stepper Harness end connector
    MPCNC – Stepper Harness end connector

    I opted to match the “pin 1” marks on the connectors, because that’s easy to remember, although it puts the pin latches on opposite sides:

    MPCNC - Stepper to Harness End
    MPCNC – Stepper to Harness End

    Some obligatory Kapton tape holds the two connectors together.

    The joint at the middle of the harness, with the near-end stepper cable on the upper left:

    MPCNC - Stepper Harness mid connection
    MPCNC – Stepper Harness mid connection

    At the RAMPS driver end of the cable:

    MPCNC - Stepper harness - driver end
    MPCNC – Stepper harness – driver end

    The Z-axis extension cable, with the stepper cable on the right:

    MPCNC - Z stepper to extension cable
    MPCNC – Z stepper to extension cable

    I plugged the cables into the RAMPS board with the “pin 1” mark at the A1A2 end of the connectors.

    With all the wires in place (and the GT2 drive belt still in its bag), I stuck masking tape tabs on the motor shafts, connected the RAMPS board, and verified the directions:

    MPCNC - Stepper motor direction test
    MPCNC – Stepper motor direction test

    Although the Y axis needed reversing, both pairs of motors turned in the same direction!

    Being that type of guy, I reversed the Y axis direction in the firmware configuration, because it’s easier for me to make all the physical connections look the same than (try to) remember to flip the Y axis connector whenever I must reconnect the cable to the driver.

  • Arduino Pseudo-Random White Noise Source

    A reader (you know who you are!) proposed an interesting project that will involve measuring audio passbands and suggested using white noise to show the entire shape on a spectrum analyzer. He pointed me at the NOISE 1B Noise Generator based on a PIC microcontroller, which led to trying out the same idea on an Arduino.

    The first pass used the low bit from the Arduino runtime’s built-in random() function:

    Arduino random function bit timing
    Arduino random function bit timing

    Well, that’s a tad pokey for audio: 54 μs/bit = 18.5 kHz. Turns out they use an algorithm based on multiplication and division to produce nice-looking numbers, but doing that to 32 bit quantities takes quite a while on an 8 bit microcontroller teleported from the mid 1990s.

    The general idea is to send a bit from the end of a linear feedback shift register to an output to produce a randomly switching binary signal. Because successive values involve only shifts and XORs, it should trundle along at a pretty good clip and, indeed, it does:

    Arduino Galois shift reg bit timing
    Arduino Galois shift reg bit timing

    I used the Galois optimization, rather than a traditional LFSR, because I only need one random bit and don’t care about the actual sequence of values. In round numbers, it spits out bits an order of magnitude faster at 6 μs/bit = 160 kHz.

    For lack of anything smarter, I picked the first set of coefficients from the list of 32 bit maximal-length values at https://users.ece.cmu.edu/~koopman/lfsr/index.html:
    0x80000057.

    The spectrum looks pretty good, particularly if you’re only interested in the audio range way over on the left side:

    Arduino Galois bit spectrum
    Arduino Galois bit spectrum

    It’s down 3 dB at 76 kHz, about half the 160 kHz bit flipping pace.

    If you were fussy, you’d turn off the 1 ms timer interrupt to remove a slight jitter in the output.

    It’s built with an old Arduino Pro Mini wired up to a counterfeit FTDI USB converter. Maybe this is the best thing I can do with it: put it in a box with a few audio filters for various noise colors and be done with it.

    It occurs to me I could fire it into the 60 kHz preamp’s snout to measure the response over a fairly broad range while I’m waiting for better RF reception across the continent.

    The Arduino source code as a GitHub Gist:

    // Quick test for random bit generation timing
    // Ed Nisley KE4ZNU – 2017-10-25
    // Observe output bit on an oscilloscope
    // LFSR info https://en.wikipedia.org/wiki/Linear-feedback_shift_register
    // This code uses the Galois implementation
    // Coefficients from https://users.ece.cmu.edu/~koopman/lfsr/index.html
    #define PIN_RND 13
    #include <Entropy.h>
    uint32_t Rnd;
    byte LowBit;
    void setup() {
    Serial.begin(57600);
    Serial.println("Random bit timing");
    Serial.println("Ed Nisley KE4ZNU – 2017-10-25");
    Entropy.initialize();
    pinMode(PIN_RND,OUTPUT);
    uint32_t Seed = Entropy.random();
    Serial.print("Seed: ");
    Serial.println(Seed,HEX);
    randomSeed(Seed);
    do {
    Rnd = random();
    } while (!Rnd); // get nonzero initial value
    }
    void loop() {
    // digitalWrite(PIN_RND,Rnd & 1); // about 55 us/bit
    // Rnd = random();
    LowBit = Rnd & 1;
    digitalWrite(PIN_RND,LowBit); // about 6 us/bit
    Rnd >>= 1;
    Rnd ^= LowBit ? 0x80000057ul : 0ul;
    }
    view raw Random_Time.ino hosted with ❤ by GitHub
  • RAMPS 1.4: Simulated Heater

    Epoxying a 100 kΩ thermistor to a 909 Ω resistor (because I have a bunch of them) serves as a simple heater tester:

    Simulated heater - thermistor bonding
    Simulated heater – thermistor bonding

    It dissipates 450 mW, raising the temperature enough to let the PWM control kick in, but not enough to get scary hot.

    Some heatstink tubing prevents reduces the likelihood of horrible accidents involving the 20 V motor / heater power supply:

    RAMPS 1.4 - Simulated heaters
    RAMPS 1.4 – Simulated heaters

    Keeping it under 50 °C seems like a Good Idea:

    RAMPS 1.4 - Simulated heater - LCD
    RAMPS 1.4 – Simulated heater – LCD

    Not that I have a need to heat anything, but the MOSFETs work!

     

     

  • Monthly Science: 60 kHz Preamp Resonator Bandwidth

    Putting a small capacitor in series with the tuning fork resonator pulls the series resonant frequency upward and reduces the amplitude:

    60 kHz Quartz TF Resonator - CX variations
    60 kHz Quartz TF Resonator – CX variations

    So something around 10 pF, net of stray capacitance and suchlike, should suffice. Plunk a small twiddlecap on the preamp board and tune for best picture:

    LF Crystal Tester - resonator protection
    LF Crystal Tester – resonator protection

    Using the DDS generator as a manual signal source with 1.0 Hz step size shows the resonator tightens up the preamp’s response quite nicely:

    60 kHz Preamp - Bandwidth - 1 Hz steps
    60 kHz Preamp – Bandwidth – 1 Hz steps

    I’m not convinced the preamp will have filter skirts that low farther away from the peak, but it’ll do for a start.

    Zoom in on the peak with 0.1 Hz steps:

    60 kHz Preamp - Bandwidth - 100 mHz steps
    60 kHz Preamp – Bandwidth – 100 mHz steps

    The bandwidth looks like 0.6 Hz, centered just slightly above 60.000 kHz, which should be fine for a first pass.

    I’m tickled: all the hardware & firmware fell neatly into place to make those graphs possible!

    Next step: install it in the attic and see whether the filter cuts back the RF clutter enough to stabilize the SDR’s AGC gain.

  • Two-Wheel Plotter

    While contemplating all the hocus-pocus and precision alignment involved in the DIY plotter project, it occurred to me you could conjure a plotter from a pair of steppers, two disks, a lifting mechanism, and not much else. The general idea resembles an Rθ plotter, with the paper glued to a turntable for the “theta” motion, but with the “radius” motion produced by pen(s) on another turntable:

    Rotary Plotter - geometry 4
    Rotary Plotter – geometry 4

    The big circle is the turntable with radius R1, which might be a touch over 4.5 inches to fit an 8.5 inch octagon cut from ordinary Letter paper. The arc with radius R2 over on the right shows the pen path from the turntable’s center to its perimeter, centered at (R1/2,-R1) for convenience.

    The grid paper represents the overall Cartesian grid containing the XY points you’d like to plot, like, for example, point Pxy in the upper right corner. The object of the game is to figure out how to rotate the turntable and pen holder to put Pxy directly under the pen at Ixy over near the right side, after which one might make a dot by lowering the pen. Drawing a continuous figure requires making very small motions between closely spaced points, using something like Bresenham’s line algorithm to generate the incremental coordinates or, for parametric curves like the SuperFormula, choosing a small parameter step size.

    After flailing around for a while, I realized this requires finding the intersections of two circles after some coordinate transformations.

    The offset between the two centers is (ΔX,ΔY) and the distance is R2 = sqrt(ΔX² + ΔY²).  The angle between the +X axis and the pen wheel is α = atan2(ΔY,ΔX), which will be negative for this layout.

    Start by transforming Pxy to polar coordinates PRθ, which produces the circle containing both Pxy and Ixy. A pen positioned at radius R from the center of the turntable will trace that circle and Ixy sits at the intersection of that circle with the pen rotating around its wheel.

    The small rectangle with sides a and b has R as its diagonal, which means a² + b² = R² and the pointy angle γ = atan a/b.

    The large triangle below that has base (R2 – a), height b, and hypotenuse R2, so (R2 – a)² + b² = R2².

    Some plug-and-chug action produces a quadratic equation that you can solve for a as shown, solve for b using the first equation, find γ from atan a/b, then subtract γ from θ to get β, the angle spearing point Ixy. You can convert Rβ back to the original grid coordinates with the usual x = R cos β and y = R sin β.

    Rotate the turntable by (θ – β) to put Pxy on the arc of the pen at Ixy.

    The angle δ lies between the center-to-center line and Ixy. Knowing all the sides of that triangle, find δ = arccos (R2 – a) / R2 and turn the pen wheel by δ to put the pen at Ixy.

    Lower the pen to make a dot.

    Done!

    Some marginal thinking …

    I’m sure there’s a fancy way to do this with, surely, matrices or quaternions, but I can handle trig.

    You could drive the steppers with a Marlin / RAMPS controller mapping between angles and linear G-Code coordinates, perhaps by choosing suitable steps-per-unit values to make the degrees (or some convenient decimal multiple / fraction thereof) correspond directly to linear distances.

    You could generate points from an equation in, say, Python on a Raspberry Pi, apply all the transformations, convert the angles to G-Code, and fire them at a Marlin controller over USB.

    Applying 16:1 microstepping to a stock 200 step/rev motor gives 0.113°/step, so at a 5 inch radius each step covers 0.01 inch. However, not all microsteps are moved equally and I expect the absolute per-step accuracy would be somewhere between OK and marginal. Most likely, given the application, even marginal accuracy wouldn’t matter in the least.

    The pen wheel uses only 60-ish degrees of the motor’s rotation, but you could mount four-ish pens around a complete wheel, apply suitable pen lift-and-lower action and get multicolor plots.

    You could gear down the steppers to get more steps per turntable revolution and way more steps per pen arc, perhaps using cheap & readily available RepRap printer GT2 pulleys / belts / shafts / bearings from the usual eBay sellers. A 16 tooth motor pulley driving a 60 tooth turntable pulley would improve the resolution by a factor of 3.75: more microsteps per commanded motion should make the actual motion come out better.

    Tucking the paper atop the turntable and under the pen wheel could be a challenge. Perhaps mounting the whole pen assembly on a tilting plate would help?

    Make all the workings visible FTW!

    Some doodles leading up to the top diagram, complete with Bad Ideas and goofs …

    Centering the pen wheel at a corner makes R2 = R1 * sqrt(2), which seems attractive, but seems overly large in retrospect:

    Rotary Plotter - geometry 1
    Rotary Plotter – geometry 1

    Centering the pen wheel at (-R1,R1/2) with a radius of R1 obviously doesn’t work out, because the arc doesn’t reach the turntable pivot, so you can’t draw anything close to the center. At least I got to work out some step sizes.

    A first attempt at coordinate transformation went nowhere:

    Rotary Plotter - geometry 2
    Rotary Plotter – geometry 2

    After perusing the geometric / triangle solution, this came closer:

    Rotary Plotter - geometry 3
    Rotary Plotter – geometry 3
  • Vacuum Tube LEDs: PAR30 Halogen Spotlight

    Breaking the fake heatsink off the big floodlight, drilling out the guts, and rebuilding it with a WS2812 RGBW LED left the PET braid too short for a nice curve from socket to bulb, so I swapped in a smaller and equally defunct PAR30 halogen spotlight:

    PAR30 Halogen - red phase
    PAR30 Halogen – red phase

    And in green:

    PAR30 Halogen - green phase
    PAR30 Halogen – green phase

    The white glass frit ring around the perimeter lights up nicely in the dark.

    The knockoff Arduino Nano now runs the RGBW program, with Morse transmissions disabled and the white LED dialed back to MaxPWM = 32.