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: Improvements

Making the world a better place, one piece at a time

  • Hall Effect LED Current Control: Crisp Gate Drive Shaping

    Because the current control loop closes through the Arduino loop(), the code’s path length limits the bandwidth. Worse, the PWM filter imposes a delay while the DC value catches up with the new duty cycle. Here’s what that looks like:

    LoopStatus ILED 50 mA div - 200 50 150 25 mA
    LoopStatus ILED 50 mA div – 200 50 150 25 mA

    The setpoint current for this pulse is 200 mA, ramping upward from 50 mA. It should have started from 25 mA, but the loop really wasn’t under control here.

    The top trace goes low during the drain current measurement, which occurs just before the code nudges the gate drive by 1 PWM count to reduce the error between the setpoint and the measurement. A delay(1) after each PWM change, plus the inherent delay due to all the program statements, produces an update every 1.7 ms, more or less.

    Even at that low rate, the current overshoots by 50 mA before the loop can tamp it down again. The current varies by 200 mA for 7 PWM counts, call it 30 mA per count at the high end, so overshooting by 50 mA comes with the territory. There’s just not a lot of resolution available.

    The program reads each pulse duration and amplitude from an array-of-structs, so it’s a simple matter of software to save the gate drive voltage at the end of each pulse and restore it when that pulse comes around on the guitar again:

    	if (millis() >= (EventStart + (unsigned long)Events[EventIndex].duration)) {
    		Events[EventIndex].drive_a = VGateDriveA;						// save drive voltages
    		Events[EventIndex].drive_b = VGateDriveB;
    
            if (++EventIndex > MAX_EVENT_INDEX)								// step to next event
    		    EventIndex = 0;
    
    		VGateDriveA = Events[EventIndex].drive_a;						// restore previous drives
    		VGateDriveB = Events[EventIndex].drive_b;
    
    		SetPWMVoltage(PIN_SET_VGATE_A,VGateDriveA);
    		SetPWMVoltage(PIN_SET_VGATE_B,VGateDriveB);
    
    		delay(PWM_Settle);
    
    		digitalWrite(PIN_ENABLE_A,Events[EventIndex].en_a);				// enable gates for new state
    		digitalWrite(PIN_ENABLE_B,Events[EventIndex].en_b);
    
            NeedHallNull = !(Events[EventIndex].en_a || Events[EventIndex].en_b);	// null sensor if all off
    
    		EventStart = millis();                                          // record start time
    	}
    

    … which produces this happy result, with a different time scale to show all four pulses in the array:

    I Sense Amp  ILED 50 mA div - 200 100 150 50 mA
    I Sense Amp ILED 50 mA div – 200 100 150 50 mA

    The top trace shows the current amp output that goes into the Arduino analog input and the bottom trace shows the MOSFET drain current. Notice those nice, crisp edges with a nearly complete lack of current adjustment.

    The small bumps in the amp output just after the LED turns off happen while the the code nulls the Hall effect sensor offset. Whenever the LEDs turn off, the code nulls the sensor, which is probably excessive; it really doesn’t have much else to do, so why not?

    This trickery doesn’t improve the loop bandwidth at all, because the code must still drag the current to meet each setpoint, but now that happens only when the pulse first appears. After a few blinks, the current stabilizes at the setpoint and the loop need handle only slight variations due to temperature or battery voltage changes.

    Speaking of voltages:

    VDS ILED 50 mA div - 200 100 150 50 mA
    VDS ILED 50 mA div – 200 100 150 50 mA

    The top trace now shows the MOSFET drain voltage and the bottom still has the LED current. There’s only 650 mV of difference at the drain for currents of 50 mA and 200 mA through the LEDs, with about 1 V of headroom remaining at 200 mA.

    The power supply delivers 7.4 V to the anode end of the LEDs, so they drop 6.3 V @ 200 mA and 5.7 V @ 50 mA. Some informal knob twiddling suggests that the MOSFET loses control authority at about 6.5 V, so, given that there’s not much energy in the battery below 7.0 V anyway, the program could limit the  maximum current to 50 mA when the battery hits 7 V, regain 650 mV of headroom, and run at reduced brightness (and perhaps a different blink pattern) until the battery drops to 6.5 V, at which point the lights go out.

    There’s more improvement to be had in the code, but those pulses look much better.

    (If you’re keeping track, as I generally don’t, this is Post Number 2048: love those round numbers!)

  • Hall Effect LED Current Control: 64 kHz PWM

    The original 32 kHz PWM produced plenty of ripple in the LED current:

    VG 1193 mV - ID 50 mA-div - 1 ms PWM filter
    VG 1193 mV – ID 50 mA-div – 1 ms PWM filter

    Using 64 kHz PWM requires putting the timers in Fast PWM Mode:

    • Timer 1: Mode 5 = Fast PWM, 8-bit resolution
    • Timer 2: Mode 3

    The Arduino code that does the deed:

    // Timer 1: PWM 9 PWM 10 - Hall offset
    TCCR1A = B10000001; // Mode 5 = fast 8-bit PWM with TOP=FF
    TCCR1B = B00001001; // ... WGM, 1:1 clock scale -> 64 kHz
    
    // Timer 2: PWM3 PWM11 - MOSFET gate drive A, B
    TCCR2A = B10100011; // Mode 3 = fast PWM with TOP=FF
    TCCR2B = B00000001; // ... 1:1 clock scale -> 64 kHz
    
    analogWrite(PIN_SET_VGATE_A,0); // force gate voltage = 0
    analogWrite(PIN_SET_VGATE_B,0);
    

    With that in hand, things look a lot better:

    PWM Ripple - 64 kHz 200 mA
    PWM Ripple – 64 kHz 200 mA

    The oscilloscope scales aren’t the same and the PWM duty cycle isn’t quite the same, but the LED current ripple drops by a little more than the factor of two you’d expect.

    The crisp rising edge comes from the analog switch between the PWM filter and the MOSFET gate, plus a bit of code trickery that presets the PWM and lets it ramp up before turning on the gate drive.

    I should recompute the voltage-to-current scale factor, but that could rapidly turn into a curve-fitting exercise. It’s pretty close already.

  • Sencha Green Tea: Japanese vs. Chinese

    I recently ordered a pound of genuine Japanese Sencha Green Tea from Harney & Sons (who turn out to be a long bike ride away at the Millerton end of the Harlem Valley Rail Trail), having had entirely enough of the rather bitter Chinese Sencha from the local grocery store.

    Guess which one is which:

    Japanese vs Chinese Sencha Green Tea
    Japanese vs Chinese Sencha Green Tea

    Yup, Japanese on the left, Chinese on the right. The latter comes from the bottom of the container, hence the larger proportion of flakes, but it’s obviously different stuff.

    Based on the first few cups, the new tea has a much better taste.

    From what I read, the price of Japanese teas has taken a real beating in recent years, because everyone (else) fears Fukushima Daiichi fallout. My feeling is that a Chinese tea plantation could be downwind of Smiling Face Heavy Metal Refinery Complex Number 5 and you’d never know it.

    For reference, the Japanese Green Sencha was $40 for 1 lb delivered.

    They tossed in a few sample packets, including “Paris: Black tea with Fruit and Caramel”, which was horrible…

  • Hall Effect LED Current Control: Switched MOSFET Gates

    The rise and fall times for the LEDs on the over-the-top blinky taillight left a bit to be desired, at least if you were interested in short pulses:

    VG 1193 mV - ID 50 mA-div - 1 ms PWM filter - overview
    VG 1193 mV – ID 50 mA-div – 1 ms PWM filter – overview

    So I spliced an analog switch between the PWM filter and the gate, with inputs selecting ground and the PWM drive voltage:

    Switched MOSFET gate - analog switch schematic
    Switched MOSFET gate – analog switch schematic

    This being a prototype, that involved epoxying a SOT23-6 package atop the MOSFET, with flying wires all over the PCB:

    Hall Effect PCB - MOSFET gate switch
    Hall Effect PCB – MOSFET gate switch

    It works pretty well:

    VDS ILED 50 mA div - 200 50 150 25 mA
    VDS ILED 50 mA div – 200 50 150 25 mA

    The top trace is the drain voltage and the bottom trace is the LED current at 50 mA/div.

    The current transitions come out vertical at any sweep speed, even through the Tek Hall effect current probe. The pulses would be rectangular if I weren’t changing the current for each one.

    The current feedback loop closes through the Arduino’s main loop, which includes a 1 ms delay after each PWM output change before measuring the LED current. As a result, each loop takes just under 2 ms, but, fortunately, ramping from 25 mA (in the last pulse) to 200 mA (in the first pulse) requires less than 10 PWM increments; you can see the stairsteps if you squint.

    Next up: bump the PWM to 64 kHz (from 32 kHz) and rip out the pull-down resistor that used to hold the gate near ground when the output floated as an input. That should improve the output ripple caused by the MOSFET’s bias as a perfectly serviceable linear amplifier.

    The control loop now fetches durations & currents from an array-of-structs, so I can customize each pulse. An obvious enhancement: remember the gate drive that produced a given current, then restore the corresponding value as the starting PWM setting for each pulse, so the loop begins closer to reality. The gate drive varies with temperature and suchlike, so it can’t be a compile-time constant, but maybe the startup routine could preload the array / list / cache with values taken from a “lamp test”.

    Four close-together flashes repeating at about 2 Hz, even with two runt pulses, turn the LEDs into a real eye magnet…

  • Subaru Forester Manual: Oddities

    Our shiny new Subaru Forester came with a 540 page user manual and, being that type of guy, I’ve been reading through it. I suspect warnings like this come from a lawsuit in the not-too-far-distant past:

    Camera Disassembly Warning
    Camera Disassembly Warning

    They seem to be very, very worried about small animals:

    Check for Small Animals
    Check for Small Animals

    In this situation, I’d hope the engine would fare better than, say, a squirrel:

    Trapping Small Animals
    Trapping Small Animals

    Unlike the Toyota Sienna’s enclosed belt, I could actually replace this one, so I suppose a squirrel could take up residence somewhere in there:

    Subaru Forester - belt and oil filter
    Subaru Forester – belt and oil filter

    And look at that oil filter: right up top, inside a bowl! The never-sufficiently-to-be-damned Toyota engineers mounted the Sienna’s filter horizontally, halfway up the side of the transverse V6 engine, where it slobbers oil down the block and over the front exhaust manifold.

    So far, so good…

  • HP Super Glossy Paper vs. Generic Ink: FAIL

    When Aitch moved to NC, he unloaded a stack of printer paper on me to avoid paying half a buck a pound to haul it along. One package contained some high-end HP photo paper that, not being a high-end photo kind of guy, I figured I’d use for my 3D printing brag sheets.

    Alas, after trying several permutations of image quality / paper type / ink density, it seems that the cheap generic ink I’m using in the Epson R380 simply isn’t compatible with the HP paper. The top image shows that the ink doesn’t wet the paper and forms a weird alligator-skin pattern:

    HP vs Staples Glossy Photo Paper
    HP vs Staples Glossy Photo Paper

    The bottom image looks perfectly fine; it’s on cheap Staples photo paper, printed with the usual Photo quality on Photo paper.

    I’ve read vague statements here-and-there that some HP ink uses an entirely different chemistry from the usual inkjet printers and, perhaps, that accounts for the mismatch. Not a problem, but it did blow an hour while proving that it wasn’t the configuration settings doing me in.

  • Slicing Anomaly: Resolved, With Cross-Check

    Some pix that serve as a stick in the ground showing that my current Slic3r configuration constellation doesn’t produce thin infill

    All of the layers in the 20 mm calibration cube look just like this:

    Solid cube - Slic3r normal infill
    Solid cube – Slic3r normal infill

    The bottom layer of the Tux mold comes out solid:

    Tux thread fill - bottom
    Tux thread fill – bottom

    As does the top:

    Tux thread fill - top
    Tux thread fill – top

    The Gcode Analyzer algorithm that assigns colors to numeric values tends to produce many aliases, although most of the time you can figure out what’s going on. If somebody wants to dive into the code, I’d like to have unique colors and get the color table sorted in ascending order.

    The current Slic3r configuration:

    # generated by Slic3r 1.1.1 on Sat May  3 10:31:36 2014
    avoid_crossing_perimeters = 0
    bed_size = 190,250
    bed_temperature = 70
    bottom_solid_layers = 3
    bridge_acceleration = 0
    bridge_fan_speed = 100
    bridge_flow_ratio = 1
    bridge_speed = 150
    brim_width = 0
    complete_objects = 0
    cooling = 1
    default_acceleration = 0
    disable_fan_first_layers = 1
    duplicate_distance = 6
    end_gcode = ;-- Slic3r End G-Code for M2 starts --\n;  Ed Nisley KE4NZU - 15 November 2013\nM104 S0		; drop extruder temperature\nM140 S0		; drop bed temperature\nM106 S0		; bed fan off\nG1 Z180 F2000	; lower bed\nG1 X130 Y125 F30000	; nozzle to right, bed front\nM84     	; disable motors\n;-- Slic3r End G-Code ends --
    external_perimeter_speed = 25
    external_perimeters_first = 0
    extra_perimeters = 1
    extruder_clearance_height = 25
    extruder_clearance_radius = 15
    extruder_offset = 0x0
    extrusion_axis = E
    extrusion_multiplier = 1.07
    extrusion_width = 0.4
    fan_always_on = 0
    fan_below_layer_time = 30
    filament_diameter = 1.79
    fill_angle = 45
    fill_density = 100%
    fill_pattern = rectilinear
    first_layer_acceleration = 0
    first_layer_bed_temperature = 70
    first_layer_extrusion_width = 0.4
    first_layer_height = 100%
    first_layer_speed = 25
    first_layer_temperature = 175
    g0 = 0
    gap_fill_speed = 50
    gcode_arcs = 0
    gcode_comments = 0
    gcode_flavor = reprap
    infill_acceleration = 0
    infill_every_layers = 3
    infill_extruder = 1
    infill_extrusion_width = 0
    infill_first = 1
    infill_only_where_needed = 0
    infill_speed = 150
    interface_shells = 0
    layer_gcode = 
    layer_height = 0.2
    max_fan_speed = 100
    min_fan_speed = 75
    min_print_speed = 4
    min_skirt_length = 15
    notes = 
    nozzle_diameter = 0.35
    only_retract_when_crossing_perimeters = 1
    ooze_prevention = 0
    output_filename_format = [input_filename_base].gcode
    overhangs = 1
    perimeter_acceleration = 0
    perimeter_extruder = 1
    perimeter_extrusion_width = 0.4
    perimeter_speed = 150
    perimeters = 2
    post_process = 
    print_center = 0,0
    raft_layers = 0
    randomize_start = 1
    resolution = 0.05
    retract_before_travel = 1
    retract_layer_change = 0
    retract_length = 1
    retract_length_toolchange = 5
    retract_lift = 0
    retract_restart_extra = 0
    retract_restart_extra_toolchange = 0
    retract_speed = 60
    skirt_distance = 3
    skirt_height = 1
    skirts = 3
    slowdown_below_layer_time = 20
    small_perimeter_speed = 25
    solid_fill_pattern = rectilinear
    solid_infill_below_area = 5
    solid_infill_every_layers = 0
    solid_infill_extrusion_width = 0
    solid_infill_speed = 150
    spiral_vase = 0
    standby_temperature_delta = -5
    start_gcode = ;-- Slic3r Start G-Code for M2 starts --\n;  Ed Nisley KE4NZU - 15 Nov 2013\n;  28 Feb 2014 - 6 Mar 2014 - tweak Z offset\n; Z-min switch at platform, must move nozzle to X=130 to clear\nM140 S[first_layer_bed_temperature]	; start bed heating\nG90				; absolute coordinates\nG21				; millimeters\nM83				; relative extrusion distance\nG92 Z0			; set Z to zero, wherever it might be now\nG1 Z10 F1000	; move platform downward to clear nozzle; may crash at bottom\nG28 Y0			; home Y to be sure of clearing probe point\nG92 Y-127 		; set origin so 0 = center of plate\nG28 X0			; home X\nG92 X-95		; set origin so 0 = center of plate\nG1 X130 Y0 F30000	; move off platform to right side, center Y\nG28 Z0			; home Z with switch near center of platform\nG92 Z-4.40		; set origin to measured z offset\nG0 Z2.0			; get air under switch\nG0 Y-127 F10000	; set up for priming, zig around corner\nG0 X0			;  center X\nM109 S[first_layer_temperature]	; set extruder temperature and wait\nM190 S[first_layer_bed_temperature]	; wait for bed to finish heating\nG1 Z0.0 F500	; put extruder near plate \nG1 E25 F300		; prime to get pressure, generate blob\nG1 Z5 F2000		; rise above blob\nG1 X15 Y-125 F20000	; jerk away from blob, move over surface\nG1 Z0.0 F1000	; dab nozzle to attach outer snot to platform\nG4 P1			; pause to attach\nG1 X35 F500		; slowly smear snot to clear nozzle\nG1 Z1.0 F2000	; clear bed for travel\n;-- Slic3r Start G-Code ends --
    start_perimeters_at_concave_points = 1
    start_perimeters_at_non_overhang = 1
    support_material = 0
    support_material_angle = 0
    support_material_enforce_layers = 0
    support_material_extruder = 1
    support_material_extrusion_width = 0
    support_material_interface_extruder = 1
    support_material_interface_layers = 0
    support_material_interface_spacing = 0
    support_material_pattern = honeycomb
    support_material_spacing = 2.5
    support_material_speed = 150
    support_material_threshold = 0
    temperature = 175
    thin_walls = 1
    threads = 2
    toolchange_gcode = 
    top_infill_extrusion_width = 0.4
    top_solid_infill_speed = 25
    top_solid_layers = 3
    travel_speed = 250
    use_firmware_retraction = 0
    use_relative_e_distances = 0
    vibration_limit = 0
    wipe = 0
    z_offset = 0