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.

Tag: CNC

Making parts with mathematics

  • DRV8825 Stepper Driver: Adding a Home Output

    The DRV8825 stepper driver chip has a -Home output going active during the (micro)step corresponding to 45°, where both winding currents equal 71% of the peak value:

    DRV8825 pinout
    DRV8825 pinout

    Unfortunately, pin 27 is another unconnected pin on the DRV8825 PCB, without even a hint of a pad for E-Z soldering.

    It’s also an open-drain output in need of a pullup, so I globbed on a 1/8 W 10 kΩ resistor in addition to the tiny wire from the IC pad to the left header pin:

    DRV8825 PCB - Home signal output
    DRV8825 PCB – Home signal output

    Read it from the right: brown black black red gold. Even in person, the colors don’t look like that, not even a little bit: always measure before installation!

    The right header pin is firmly soldered to the PCB ground pin I also used for the 1:8 microstep hack. The whole affair received a generous layer of hot melt glue in the hope of some mechanical stabilization, although hanging a scope probe off those pins can’t possibly end well.

    The general idea is to provide a scope sync output independent of the motor speed, so I can look at the current waveforms:

    3018 X - Fast - 12V - 140mm-min 1A-div
    3018 X – Fast – 12V – 140mm-min 1A-div

    The alert reader will note the pulse occurs on the down-going side of the waveforms, which means I have the current probes clipped on backwards or, equivalently, on the wrong wire. The point is to get a stable sync, so it’s all good no matter which way the current goes.

  • CNC 3018-Pro: LM6UU Linear-bearing Diamond Drag Bit Holder

    The CNC 3018-Pro normally holds a small DC motor with a nicely cylindrical housing,so this was an easy adaptation of the MPCNC’s diamond drag bit holder:

    CNC 3018-Pro - Diamond bit - overview
    CNC 3018-Pro – Diamond bit – overview

    The lip around the bottom part rests atop the tool clamp, with the spring reaction plate sized to clear the notch in the Z-axis stage.

    The solid model looks about like you’d expect:

    Diamond Scribe - Mount - solid model
    Diamond Scribe – Mount – solid model

    The New Thing compared to the MPCNC holder is wrapping LM6UU bearings around an actual 6 mm shaft, instead of using LM3UU bearings for the crappy diamond bit shank:

    CNC 3018-Pro - Diamond bit - epoxy curing
    CNC 3018-Pro – Diamond bit – epoxy curing

    I cut the shank in two pieces, epoxied them into 3 mm holes drilled into the 6 mm shaft, then epoxied the knurled stop ring on the end. The ring is curing in the bench block to stay perpendicular to the 6 mm shaft.

    The spring constant is 55 g/mm and it’s now set for 125 g preload:

    CNC 3018-Pro - Diamond bit - force measurement
    CNC 3018-Pro – Diamond bit – force measurement

    A quick test says all the parts have begun flying in formation:

    CNC 3018-Pro - Diamond bit - test CD
    CNC 3018-Pro – Diamond bit – test CD

    It’s definitely more rigid than the MPCNC!

    The OpenSCAD source code as a GitHub Gist:

    // Diamond Scribe in linear bearings for CNC3018
    // Ed Nisley KE4ZNU – 2019-08-9
    Layout = "Build"; // [Build, Show, Base, Mount, Plate]
    /* [Hidden] */
    ThreadThick = 0.25; // [0.20, 0.25]
    ThreadWidth = 0.40; // [0.40, 0.40]
    /* [Hidden] */
    Protrusion = 0.1; // [0.01, 0.1]
    HoleWindage = 0.2;
    inch = 25.4;
    function IntegerMultiple(Size,Unit) = Unit * ceil(Size / Unit);
    ID = 0;
    OD = 1;
    LENGTH = 2;
    //- Adjust hole diameter to make the size come out right
    module PolyCyl(Dia,Height,ForceSides=0) { // based on nophead's polyholes
    Sides = (ForceSides != 0) ? ForceSides : (ceil(Dia) + 2);
    FixDia = Dia / cos(180/Sides);
    cylinder(r=(FixDia + HoleWindage)/2,h=Height,$fn=Sides);
    }
    //- Dimensions
    // Knife holder & suchlike
    ScribeOD = 3.0; // diamond scribe shaft
    Bearing = [6.0,12.0,19.0]; // linear bearing body, ID = shaft diameter
    Spring = [4.5,5.5,3*ThreadThick]; // compression spring around shaft, LENGTH = socket depth
    //Spring = [9.5,10.0,3*ThreadThick]; // compression spring around shaft, LENGTH = socket depth
    WallThick = 4.0; // minimum thickness / width
    Screw = [3.0,6.75,25.0]; // holding it all together, OD = washer
    Insert = [3.0,5.0,8.0]; // brass insert
    //Insert = [4.0,6.0,10.0];
    Clamp = [43.2,44.0,34.0]; // tool clamp ring, OD = clearance around top
    LipHeight = IntegerMultiple(2.0,ThreadThick); // above clamp for retaining
    BottomExtension = 25.0; // below clamp to reach workpiece
    MountOAL = LipHeight + Clamp[LENGTH] + BottomExtension; // total mount length
    echo(str("Mount OAL: ",MountOAL));
    Plate = [1.5*ScribeOD,Clamp[ID] – 0*2*WallThick,WallThick]; // spring reaction plate
    NumScrews = 3;
    ScrewBCD = Bearing[OD] + Insert[OD] + 2*WallThick;
    echo(str("Retainer max OD: ",ScrewBCD – Screw[OD]));
    NumSides = 9*4; // cylinder facets (multiple of 3 for lathe trimming)
    // Basic mount shape
    module CNC3018Base() {
    translate([0,0,MountOAL – LipHeight])
    cylinder(d=Clamp[OD],h=LipHeight,$fn=NumSides);
    translate([0,0,MountOAL – LipHeight – Clamp[LENGTH] – Protrusion])
    cylinder(d=Clamp[ID],h=(Clamp[LENGTH] + 2*Protrusion),$fn=NumSides);
    cylinder(d1=Bearing[OD] + 2*WallThick,d2=Clamp[ID],h=BottomExtension + Protrusion,$fn=NumSides);
    }
    // Mount with holes & c
    module Mount() {
    difference() {
    CNC3018Base();
    translate([0,0,-Protrusion]) // bearing
    PolyCyl(Bearing[OD],2*MountOAL,NumSides);
    for (i=[0:NumScrews – 1]) // clamp screws
    rotate(i*360/NumScrews)
    translate([ScrewBCD/2,0,MountOAL – Clamp[LENGTH]])
    rotate(180/8)
    PolyCyl(Insert[OD],Clamp[LENGTH] + Protrusion,8);
    }
    }
    module SpringPlate() {
    difference() {
    cylinder(d=Plate[OD],h=Plate[LENGTH],$fn=NumSides);
    translate([0,0,-Protrusion])
    PolyCyl(Plate[ID],2*MountOAL,NumSides);
    translate([0,0,Plate[LENGTH] – Spring[LENGTH]]) // spring retainer
    PolyCyl(Spring[OD],Spring[LENGTH] + Protrusion,NumSides);
    for (i=[0:NumScrews – 1]) // clamp screws
    rotate(i*360/NumScrews)
    translate([ScrewBCD/2,0,-Protrusion])
    rotate(180/8)
    PolyCyl(Screw[ID],2*MountOAL,8);
    }
    }
    //—–
    // Build it
    if (Layout == "Base")
    CNC3018Base();
    if (Layout == "Mount")
    Mount();
    if (Layout == "Plate")
    SpringPlate();
    if (Layout == "Show") {
    Mount();
    translate([0,0,1.25*MountOAL])
    rotate([180,0,0])
    SpringPlate();
    }
    if (Layout == "Build") {
    translate([0,-0.75*Clamp[OD],MountOAL])
    rotate([180,0,0])
    Mount();
    translate([0,0.75*Plate[OD],0])
    SpringPlate();
    }
  • CNC 3018-Pro: Table Riser

    With the 3018-Pro used for drag engraving on CDs and hard drive platters, there’s no need for all the clearance below the Z-axis carriage required for the OEM motor and ER11 collet chuck. A chunk of laminate countertop and a hunk of Celotex foam insulation produce a nicely flat surface 47 mm above the platform:

    CNC 3018 Table Riser
    CNC 3018 Table Riser

    It’s surprisingly flat:

    Table Flatness Measurement - 2019-08-30
    Table Flatness Measurement – 2019-08-30

    Those are millimeters of clearance between the gray plastic clamp around the diamond drag tool holder (about which, more later) and my trusty bench block, measured at 50 mm intervals across the platform. The lower figures appeared after tightening the upper-left screw by a little over 1/6 turn = 0.2 mm, making the entire platform flat & aligned within ±0.1 mm.

    Yeah, not bad for a scrap countertop!

    The four M6 socket head cap screws pass through the stack into T-nuts in the platform:

    CNC 3018 Table Riser - screw clearance
    CNC 3018 Table Riser – screw clearance

    The countertop was thick enough to allow countersinking the screws slightly below the surface:

    CNC 3018 Table Riser - screw countersink
    CNC 3018 Table Riser – screw countersink

    I transfer-punched the screw clearance hole locations into the Celotex and drilled it with an ordinary twist drill. It wasn’t pretty, but nobody will ever notice.

    Two sheets, maybe 1 mm thick, of closed-cell foam below the Celotext provide enough squish to align the top surface without straining anything. The screws are firmly tight, so they shouldn’t work their way loose under minimal engraving loads.

    Taping the CDs to the surface works well for now, although a simpler version of the fixture may be in order.

  • DRV8825 Stepper Driver: Fast vs. Mixed Decay Current Waveforms

    Herewith, a look at CNC 3018-Pro stepper motor current waveforms as a function of supply voltage, PWM decay mode, and motor speed.

    The scope displays X and Y axis motor current at 1 A/div, with sensing through a pair of Tektronix Hall effect current probes:

    CNC 3018-Pro - XY axes - Tek current probes
    CNC 3018-Pro – XY axes – Tek current probes

    The X axis driver is an unmodified DRV8825 PCB operating in default mixed-decay mode. The Y axis DRV8825 has its DECAY pin pulled high, thereby putting it in fast decay mode.

    The scope timebase varies to match the programmed feed rate. Because the X and Y axes move simultaneously, each axis moves at 1/√2 the programmed speed:

    G1 X10 Y10 F100 → 71 mm/min on X and Y

    The motor generates minimal back EMF at slow speeds, so the winding sees nearly the full supply voltage. As described in the previous post, the basic problem arises when the current rises too fast during each PWM cycle:

    V = L di/dt
    di/dt = 24 V / 3 mH = 8 kA/s

    The first 1:32 microstep away from 0 calls for 5% of max current = 50 mA at a 1 A peak. The DRV8825 datasheet says the PWM typically runs at 30 kHz = 33 µs/cycle, during which the current will change by 270 mA:

    267 mA = 8 kA/s × 33.3 µs

    Notice how the current slams to a nearly constant, much-too-high value just after the first microstep. The incorrect current level decreases with lower supply voltage, because the rate-of-change decreases and the commanded current level reaches the actual (incorrect) current sooner.

    Varying the motor voltage at a constant 10 mm/min:

    3018 XY - Mixed Fast - 24V - 10mm-min 1A-div
    3018 XY – Mixed Fast – 24V – 10mm-min 1A-div
    3018 XY - Mixed Fast - 20V - 10mm-min 1A-div
    3018 XY – Mixed Fast – 20V – 10mm-min 1A-div
    3018 XY - Mixed Fast - 15V - 10mm-min 1A-div
    3018 XY – Mixed Fast – 15V – 10mm-min 1A-div
    3018 XY - Mixed Fast - 12V - 10mm-min 1A-div
    3018 XY – Mixed Fast – 12V – 10mm-min 1A-div
    3018 XY - Mixed Fast - 10V - 10mm-min 1A-div
    3018 XY – Mixed Fast – 10V – 10mm-min 1A-div

    Note that reducing the supply voltage doesn’t change the motor winding current, because the DRV8825 controls the current during each microstep, at least to the best of its ability.

    Also note that the current overshoots the target for those microsteps, even when the motor is stopped, because there’s no back EMF, so the power dissipation is too high even at rest.

    Enough back EMF appears at 100 mm/min to begin tamping down the current overshoot at 24 V:

    3018 XY - Mixed Fast - 24V - 100mm-min 1A-div
    3018 XY – Mixed Fast – 24V – 100mm-min 1A-div

    The current waveform looks good at 12 V:

    3018 XY - Mixed Fast - 12V - 100mm-min 1A-div
    3018 XY – Mixed Fast – 12V – 100mm-min 1A-div

    The back EMF at 1000 mm/min nearly eliminates the overshoot at 24 V, with fast decay in the Y axis causing some PWM ripple:

    3018 XY - Mixed Fast - 24V - 1000mm-min 1A-div
    3018 XY – Mixed Fast – 24V – 1000mm-min 1A-div

    Both decay modes look good at 12 V:

    3018 XY - Mixed Fast - 12V - 1000mm-min 1A-div
    3018 XY – Mixed Fast – 12V – 1000mm-min 1A-div

    At 1500 mm/min, the highest reasonable speed for the thing, and a 24 V supply, both waveforms still look good:

    3018 XY - Mixed Fast - 24V - 1500mm-min 1A-div
    3018 XY – Mixed Fast – 24V – 1500mm-min 1A-div

    However, the back EMF is now high enough to buck the 12 V supply, preventing the current from decreasing fast enough in mixed decay mode (top trace):

    3018 XY - Mixed Fast - 12V - 1500mm-min 1A-div
    3018 XY – Mixed Fast – 12V – 1500mm-min 1A-div

    Tweaking the GRBL config to allow 2000 mm/min feeds shows the waveforms starting to become triangular, even at 24 V:

    3018 XY - Mixed Fast - 24V - 2000mm-min 1A-div
    3018 XY – Mixed Fast – 24V – 2000mm-min 1A-div

    And a 12 V supply opposed by the back EMF simply can’t change the current fast enough to keep up with the DRV8825 microstep current levels:

    3018 XY - Mixed Fast - 12V - 2000mm-min 1A-div
    3018 XY – Mixed Fast – 12V – 2000mm-min 1A-div

    Bottom line: a +12 V motor supply and DRV8825 drivers modified to run in fast decay mode look like the best setup for the 3018-Pro: good current control at low speeds with enough moxie to handle higher speeds.

    I should hack the DRV8825 boards into 1:8 microstep mode to reduce the IRQ rate by a factor of four, then see what happens to the back EMF at absurd speeds.

  • DRV8825 Stepper Driver: Forcing Fast Decay Mode in a (Likely) Counterfeit Chip

    The DRV8825 stepper driver chip defaults to mixed decay mode, which TI defines thusly:

    Mixed decay mode begins as fast decay, but at a fixed period of time (75% of the PWM cycle) switches to slow decay mode for the remainder of the fixed PWM period. This occurs only if the current through the winding is decreasing (per the indexer step table); if the current is increasing, then slow decay is used.

    The 24 V supply on the CNC 3018-Pro provides too much voltage for the motors, because slow decay mode can’t handle those rising slopes:

    3018 XY - Mixed Fast - 24V - 10mm-min 12V 1A-div
    3018 XY – Mixed Fast – 24V – 10mm-min 12V 1A-div

    Note that “rising” means the current increases with either polarity from 0 A at the midline. The DRV8825 uses a MOSFET H-bridge to drive winding current in either direction from the +24 V motor supply voltage.

    Both traces show motor winding current at 1 A/div, with the XY axes creeping along at 10 mm/min (thus, 7.1 mm/min each). The upper trace is the X axis, with a stock DRV8825 module in mixed decay mode. The lower trace is the Y axis, with its DRV8825 hacked into fast decay mode.

    The basic problem, about which more later, comes from the current rising too fast during each PWM cycle:

    V = L di/dt
    di/dt = 24 V / 3 mH = 8 kA/s

    The first 1:32 microstep away from 0 calls for 5% of max current = 50 mA at a 1 A peak. The DRV8825 datasheet says the PWM typically runs at 30 kHz = 33 µs/cycle, during which the current will change by 270 mA:

    267 mA = 8 kA/s × 33.3 µs

    Some preliminary measurements suggest these (probably counterfeit) DRV8825 chips actually run at 16 kHz = 66 µs/cycle:

    3018 X - ripple 1 step - 18V - A0 B-90 500mA-div
    3018 X – ripple 1 step – 18V – A0 B-90 500mA-div

    During those cycles the current can increase by more than 500 mA. The first scope picture shows an abrupt increase to maybe 700 mA, so, yeah, that’s about right.

    Having the wrong current in one winding means the motor isn’t positioned correctly during those microsteps. The 3018-Pro runs at (an absurd) 1600 µstep/mm, so being off by even a full step isn’t big deal in terms of positioning.

    The real problem comes from running nearly 1 A through both windings. Those little motors run really hot: they’re dissipating twice what they should be.

    Anyhow, the pin layout shows the DRV8825 DECAY mode selection on pin 19:

    DRV8825 pinout
    DRV8825 pinout

    Which sits on an inconveniently skinny little PCB pad, fifth from the left on the bottom:

    DRV8825 PCB - open Decay pin
    DRV8825 PCB – open Decay pin

    Memo to Self: Don’t make that mistake when you lay out a PCB. Always put a little pad or via on a disconnected pin, so as to have a hand-soldering target big enough to work with.

    The objective is to pull the pin high:

    DRV8825 DECAY pin settings
    DRV8825 DECAY pin settings

    Pin 15, in the lower left corner, provides the output of a 3.3 V linear regulator, with its PCB trace connected to the left side of the ceramic cap:

    DRV8825 PCB - Decay pin wired low
    DRV8825 PCB – Decay pin wired low

    On the scale of TSSOP packages, even 30 AWG Wire-Wrap wire looks like a bus bar!

    Those are two different PCBs. The crappy TI logos, not easily visible in those low-res pix, on both ICs suggest they’re by-now-typical counterfeits, so seeing a factor-of-two difference in PWM frequency isn’t surprising.

  • CNC 3018-Pro: GRBL Configuration

    The CNC 3018-Pro router arrived with GRBL 1.1f installed on the Camtool V3.3 board and ran well enough, although it accelerated very slowly. After installing Home switches, figuring out the travel limits, and trying different speeds & accelerations, it runs much better:

    3018 CNC - Endstop switches - overview
    3018 CNC – Endstop switches – overview

    Configuration values to remember for next time:

    $1=100 turns off the stepper motor drivers after 100 ms of inactivity:

    3018 X - 100ms timeout - 100mm-min 12V 500 ma-div
    3018 X – 100ms timeout – 100mm-min 12V 500 ma-div

    There’s no force worth mentioning on a diamond scribe when the motors stop, so there’s no reason to keep them energized, and the DRV8825 chips resume from the same microstep when re-enabled.

    $3=5 reverses the X and Z motor rotation, so you can use the same type of cable on all three axes and have them move the way you’d expect.

    $20=1 turns on Soft Limits, thereby producing an error when you (or the G-Code) tries to move beyond the machine’s limits, as defined by the $120 $121 $122 values relative to the Home switch positions.

    $21=0 leaves Hard Limits off, because I didn’t see much point in switches on both ends of all the axes for this little bitty machine.

    $22=1 enables the Home cycle, after which you must start each session by homing the machine.

    $27=1.000 sets the Pull-off distance from all three Home positions, so the machine ends up at absolute XYZ = -1.000 mm relative to the switch trip points after homing. This depends on the mechanics of the limit switches, but seems OK with the MBI-style switches I used:

    3018 CNC - X axis endstop - 1 mm pull-off
    3018 CNC – X axis endstop – 1 mm pull-off

    $100 $101 $102 = 1600 set the XYZ step/mm, which requires knowing the 3018-Pro uses two-start leadscrews with a 2 mm pitch = 4 mm lead:

    3018 CNC - two-start leadscrew
    3018 CNC – two-start leadscrew

    The Camtool V3.3 board hardwires the DRV8825 stepper controllers into 32 microstep mode, so:

    1600 step/mm = (200 full step/rev) × (32 microstep/full step) / (4 mm/rev)

    $110 $111 $112 = 1100 set the maximum speed along the XYZ axes in mm/min. Note the hard upper limit set by the maximum microcontroller interrupt rate of about 40 k/s:

    1500 mm/min = 25 mm/s = (40×10³ step/s) / (1600 step/mm)

    I’ll have more to say about speed limits, stepper current, torque, and similar topics.

    $120 $121 $122 = 3000 set the acceleration along the XYZ axes in mm/sec². These are two orders of magnitude higher than the default acceleration, which accounts for the as-received sluggish acceleration.

    $130=299.000 $131=179.000 $132=44.000 set the XYZ travel limits relative to the Home switch trip points, which feed into the $20=1 Soft Limits. You could probably eke out another millimeter along each axis, but this is what I came up with.

    With all those in place, the G54 coordinate system puts the XY origin dead in the middle of the platform and the Z origin a little bit below its upper travel limit. Set them thusly:

    G10 L2 P1 X-147 Y-90.6 Z-1.5

    The original and tweaked GRBL configuration settings as a GitHub Gist:

    $0=10
    $1=25
    $2=0
    $3=5
    $4=0
    $5=0
    $6=0
    $10=1
    $11=0.010
    $12=0.002
    $13=0
    $20=0
    $21=0
    $22=0
    $23=0
    $24=25.000
    $25=500.000
    $26=250
    $27=1.000
    $30=1000
    $31=0
    $32=0
    $100=1600.000
    $101=1600.000
    $102=1600.000
    $110=1000.000
    $111=1000.000
    $112=800.000
    $120=30.000
    $121=30.000
    $122=30.000
    $130=200.000
    $131=200.000
    $132=200.000
    $0=10
    $1=100
    $2=0
    $3=5
    $4=0
    $5=0
    $6=0
    $10=1
    $11=0.010
    $12=0.020
    $13=0
    $20=1
    $21=0
    $22=1
    $23=0
    $24=100.000
    $25=1000.000
    $26=25
    $27=1.000
    $30=1000
    $31=0
    $32=0
    $100=1600.000
    $101=1600.000
    $102=1600.000
    $110=1100.000
    $111=1100.000
    $112=1100.000
    $120=3000.000
    $121=3000.000
    $122=3000.000
    $130=299.000
    $131=179.000
    $132=44.000
    ok
    [G54:-147.000,-90.600,-1.500]
    [G55:0.000,0.000,0.000]
    [G56:0.000,0.000,0.000]
    [G57:0.000,0.000,0.000]
    [G58:0.000,0.000,0.000]
    [G59:0.000,0.000,0.000]
    [G28:0.000,0.000,0.000]
    [G30:0.000,0.000,0.000]
    [G92:0.000,0.000,0.000]
    [TLO:0.000]
    [PRB:0.000,0.000,0.000:0]
    ok

    The as-shipped configuration is mostly for reference, but ya never know when it might come in handy.

  • Logitech “Quickcam for Notebooks Deluxe” USB Camera Disassembly

    My collection of old USB cameras emitted a Logitech Quickcam for Notebooks Deluxe, with a tag giving a cryptic M/N of V-UGB35. Given Logitech’s penchant for overlapping names, its USB identifiers may be more useful for positive ID:

    ID 046d:08d8 Logitech, Inc. QuickCam for Notebook Deluxe

    It works fine as a simple V4L camera and its 640×480 optical resolution may suffice for simple purposes, even if it’s not up to contemporary community standards.

    The key disassembly step turned out to be simply pulling the pivoting base off, then recovering an errant spring clip from the Laboratory Floor:

    Logitech V-UGB35 USB Camera - mount removed
    Logitech V-UGB35 USB Camera – mount removed

    The clips have a beveled side and fit into their recesses in only one orientation; there’s no need for brute force.

    Removing the two obvious case screws reveals the innards:

    Logitech V-UGB35 USB Camera - PCB rear
    Logitech V-UGB35 USB Camera – PCB rear

    Three more screws secure the PCB:

    Logitech V-UGB35 USB Camera - PCB front
    Logitech V-UGB35 USB Camera – PCB front

    The ribbed focus knob around the lens makes it more useful than a nominally fixed-focus camera.

    Reassembly is in reverse order.

    I miss having obvious case screws …