FW compilation and relay control



  • I recently bought a Duet Wifi and really like the board so far. Hoewer, as I was previously using a Megatronics board with relay-controlled 4 extruders, I was hoping to transfer that setup to Duet as is, without using the expansion boards (as I didn't order any). The setup I have consists of a relay board that switches the active extruder and the relay is controlled with AUX-port pins on the Megatronics. Only one stepper driver needed. I have a slightly modified Marlin running on the Megatronics, based on PrusaMM code.

    So the problems I'm facing are:

    1. building the firmware on Linux
    2. modifying the firmware to control the relay

    Step 1. So far I've cloned the CoreNG, DuetWiFiSocketServer, and RRF repositories and installed the gcc-arm-none-eabi and eclipse-cdt packages. RRF branch is 1.21 (also tried dev)
    CoreNG compiles fine, active configuration is SAM4E8E
    RRF does not compile, for some reason it cannot find the MessageFormats.h, even though DuetWiFiSocketServer is in the project includes. Probably could just copy the file over, but kinda hate leaving this unsolved... Also I'm bit confused about the active configuration for RRF; Alligator, Duet085, Duet2, DuetM, probably not RADDS or SAE70?

    Step 2. So how the relay control works with Marlin is that when tool change command (Tx) is issued, 3 AUX pins are controlled: 000 for T0, 111 for T1, 011 for T2 and 000 for T3. There's room for one more port in the relay so fourth pin could be used in the future for 5th extruder motor.
    I imagine this wouldn't be too hard to implement in RRF. I haven't looked at the code yet, kinda stuck with the build step. Any pointers about this appreciated. Or existing code forks.
    I'm thinking about using the expansion connector pins for this.


  • administrators

    I think you can do it without recompiling the firmware. Allocate some spare outputs to drive the relay board, for example heaters 3 to 6. Then use M42 commands in the tool change files to activate them. Use the tfree#.g files to turn off the relay connecting the old extruder drive, and tpost#.g to turn on the relay connecting the new extruder. The heater output are active low, so if your relay board has optically isolated differential inputs as most do, then connect the input between +3.3V and your chosen heater output.

    Switching stepper motors with relays while they are under power is bad for any kind of the stepper motor drivers. So I suggest that in the tool change files, before you do any switching, you disable the extruder motor driver using M18 E0.

    The firmware build configuration for a Duet WiFi is Duet2.



  • Great thanks. That's neat, never occurred to me that this could be done in g-code. Always better this way, no need to maintain my own fork of the code.
    Also good point about turning off the motor before switch. So far the DRV8825 I used with the Megatronics works fine, but might just been lucky. In this setup half of the motor wires all always connected to all motors, the relay controls the remaining two. Here's the original site where I copied the setup: https://www.marlinkimbra.it/?p=280



  • Ok the setup seems to be working, printed this gear with 4 colors (ABS, 0.2mm, S3D, Pressure Advance 0.27):
    alt text

    I used logical pins 60-63 for control and 5V from ATX PSU for power as I run whole system with it.

    tfreex.g:
    M18 E0

    tpost0.g:
    M116 P0
    M42 P60 S255
    M42 P61 S255
    M42 P62 S255
    M42 P63 S255
    G4 P300

    tpost1.g
    M116 P0
    M42 P60 S255
    M42 P61 S255
    M42 P62 S255
    M42 P63 S0
    G4 P300

    tpost2.g
    M116 P0
    M42 P60 S255
    M42 P61 S255
    M42 P62 S0
    M42 P63 S0
    G4 P300

    tpost3.g
    M116 P0
    M42 P60 S255
    M42 P61 S0
    M42 P62 S0
    M42 P63 S0
    G4 P300

    At first I had some trouble wrapping my head around how to keep E0 as the drive when changing tool, but luckily stumbled upon M563 definition in Duet Wiki and all was clear, just set all tools to use E0. I did my first configuration for Duet with some online configuration generator, so didn't really look it through all of the commands very keenly. Loving how much things can be configured without needing to touch the actual code.



  • That's really awesome. Shows the power of gcode and macros.


  • administrators

    @spegelius Great job, glad you got it working and as @Phaedrux says - shows the power of macros in gcode. When you get a chance it would be cool to see the printer and mechanism in the "my duet wifi controlled machine" sub forum!


  • administrators

    I'm glad you got it working.

    One more suggestion: after each M18 E0 commands, put a short G4 delay command to give the motor current time to drop to zero before the relay is changed. Probably unnecessary because of the delay in the relay activating, but better to be safe than sorry. Ten milliseconds should be more than enough.



  • @dc42 good call, I'll add 10ms delay after the turning off the driver. I did have some very rare problem with Marlin where right after tool change the feeding of new material would fail with motor squealing with skipped steps. Perhaps related to the relay being in inconsistent state. In Marlin the relay control had some delay (300ms) only after altering the relay state.

    @T3P3Tony I'll be happy to shed some light into this "frankenprinter" I've built from assorted parts. As the moniker hints, it's not that pretty but it's surprisingly functional. And it does not fully hate it's maker as far as I can tell.


 

Looks like your connection to Duet3D was lost, please wait while we try to reconnect.