Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers



  • Hi,

    I've got a 4-Pin 12V PWM fan which I'd like to connect to the Fan1 (PWM) header on the Duet and use to actively cool the TMC2660 drivers from the underside of the board when needed.

    The specifics I'm looking for are:

    • I'd like the fan to operate in Thermostatic Mode, that is, be completely off when all drivers are under 45 deg celsius, run at 50%-100% if any of the drivers is between 45-65 deg, and turn fully on (100%) if any of the drivers goes above that temp limit.

    • Utilize the true PWM capability of the fan (i.e. not the voltage-based PWM grounding of the fan's supply).

    • It would be nice to have a visual indication in DWC of the fan's status (though this is optional).

    Having read through the gcode documentation, I'm not entirely clear about the exact formulation of the M106 command that needs to be put in config.g for all of this to work, as well as hardware setup (as I'll explain further below).

    Software Side

    From what I gather, the relevant M106 to achieve the above goals ought to look something like this:

    (please see my questions in bold in the relevant places)

    M106 P1 S0 I1 F25000 L0.5 B4 H100:101:102:103:104 T45:65 CDuet_Fan
    

    Parameter Explanandum:

    P1 - PWM Fan 1

    S0 - Set initial fan speed to 0 RPM (fan is initially off)

    I1 - Invert PWM signal (not sure about this one? is this right?)

    F25000 - Set PWM frequency 25MHz

    L0.5 - Set minimum fan speed (when fan is on) to 50%

    B4 - Set startup from standstill at 100% PWM for a 4 seconds duration

    H100:101:102:103:104 - Enable Thermostatic Mode and assign it to virtual heaters 100-104 (i.e. the Duet's 5 x TMC2660) (is this right?)

    T45:65 - Thermostatic mode trigger temperatures set between 45-65 deg celsius (however, if I understand correctly, the TMC2660 drivers only provide 'over-temperature' and 'critical temperature' flags rather than accurate temp info - how does this conform with setting the temp range for the fan's operation?)

    CDuet_Fan - sets the fan's name (is it possible to use a white space in the name instead of the underscore? and, if so, how?)

    Hardware Side

    To utilize the true PWM capability of the fan, the documentation suggests that:

    "The I parameter causes the fan output signal to be inverted if its value is greater than zero. This makes the cooling fan output suitable for feeding the PWM input of a 4-wire fan via a diode."

    But what kind of diode (signal/schottky)? with what rating? and in which direction?

    Here's my understanding of how the setup should be:

    0_1531470266913_DUET_PWM_FAN_HOOKUP.png

    Is this hook-up correct? Is the diode oriented correctly?

    Thanks!
    SnowCrash


  • administrators

    The diode should be connected the other way round (anode to the fan PWM input). An ordinary small signal silicon diode such as 1N4148 should work.



  • @snowcrash You are right that TMC drivers will only have a fake-temperature reported. it is 100°C if the driver goes into warning and 150°C if the driver goes into thermal-shutdown. In any other case the reported temperature of virtual heater 101 will be at 0°C - unless @dc42 accepts my pull request at GitHub. In that case there will be another fake-temperatur of 50°C if any driver is activated. 0°C would then mean all drivers are shut off.

    So unless you add your own thermistor to the stepper drivers there is no way of getting their temperature.

    The following virtual heaters are defined:
    100: MCU
    101: All TMCs on Duet board
    102: All TMCs on DueX(2|5) board

    P.S.: This means your H parameter checks for temperature of MCU, all TMCs on the Duet, all TMCs on DueX and temperatures on heaters that probably are not defined (103, 104). I think it will take the highest value of any of these to apply to what speed the fan should spin. So if any of these heaters will report 65°C (probably only 100 is able to ever do that anyway) it will spin the fan at full speed even if all other channels report a (much) lower temperature.

    P.P.S.: This is probably only a typo in your post but F25000 means 25 KHz not MHz. The value of F is given in Hz.



  • @dc42 said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    The diode should be connected the other way round (anode to the fan PWM input). An ordinary small signal silicon diode such as 1N4148 should work.

    Thanks, @dc42! Diagram fixed:

    0_1531476871756_DUET_PWM_FAN_HOOKUP_fixed.png

    @wilriker said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    Thanks @wilriker!

    @snowcrash You are right that TMC drivers will only have a fake-temperature reported. it is 100°C if the driver goes into warning and 150°C if the driver goes into thermal-shutdown. In any other case the reported temperature of virtual heater 101 will be at 0°C - unless @dc42 accepts my pull request at GitHub. In that case there will be another fake-temperatur of 50°C if any driver is activated. 0°C would then mean all drivers are shut off.

    OK, I think I got it 🙂

    So, given these limitations, and assuming I want the fan to be normally on at 50% (i.e. all the time), and only have it go to up to 100% if any of the 5 drivers on the Duet goes above the 'warning' limit (100°C), I've revised M106 command to this:

    M106 P1 S0.5 I1 F25000 L0.5 B4 H101 T100 CDuet_Fan
    

    Is this the correct formulation to achieve the above?

    So unless you add your own thermistor to the stepper drivers there is no way of getting their temperature.

    The following virtual heaters are defined:
    100: MCU
    101: All TMCs on Duet board
    102: All TMCs on DueX(2|5) board

    P.S.: This means your H parameter checks for temperature of MCU, all TMCs on the Duet, all TMCs on DueX and temperatures on heaters that probably are not defined (103, 104). I think it will take the highest value of any of these to apply to what speed the fan should spin. So if any of these heaters will report 65°C (probably only 100 is able to ever do that anyway) it will spin the fan at full speed even if all other channels report a (much) lower temperature.

    Thanks for the clarification.

    In this case, I think documentation on this parameter is very unhelpful to the point of being misleading (I'm mainly referring to the fourth example and the subsequent text that's supposed to explain it).

    P.P.S.: This is probably only a typo in your post but F25000 means 25 KHz not MHz. The value of F is given in Hz.

    Yep, typo, good catch. I indeed meant 25KHz (though might be interesting to see a fan running at 25MHz... 🙂



  • @snowcrash said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    So, given these limitations, and assuming I want the fan to be normally on at 50% (i.e. all the time), and only have it go to up to 100% if any of the 5 drivers on the Duet goes above the 'warning' limit (100°C), I've revised M106 command to this:

    M106 P1 S0.5 I1 F25000 L0.5 B4 H101 T100 CDuet_Fan
    

    Is this the correct formulation to achieve the above?

    I think your T parameter should rather be T0:100 because I have a similar configuration with T25 (on the heated bed for the PSU fan) that will stop the fan below this temperature.

    Also I think you do not need L0.5 here. I won't hurt but don't see a reason to use this on a thermostatically controlled fan.

    Thanks for the clarification.

    In this case, I think documentation on this parameter is very unhelpful to the point of being misleading (I'm mainly referring to the fourth example and the subsequent text that's supposed to explain it).

    OK, I have to say I find this very example in the documentation to be very clear - but it may be my software engineer background that immediately translates this into code in my head. 😁

    Can you say, how you would have explained this fourth example? Maybe we can improve documentation this way.



  • @wilriker said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    @snowcrash said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    So, given these limitations, and assuming I want the fan to be normally on at 50% (i.e. all the time), and only have it go to up to 100% if any of the 5 drivers on the Duet goes above the 'warning' limit (100°C), I've revised M106 command to this:

    M106 P1 S0.5 I1 F25000 L0.5 B4 H101 T100 CDuet_Fan
    

    Is this the correct formulation to achieve the above?

    I think your T parameter should rather be T0:100 because I have a similar configuration with T25 (on the heated bed for the PSU fan) that will stop the fan below this temperature.

    I think you're right, thanks!

    So the formulation updates to:

    > > M106 P1 S0.5 I1 F25000 L0.5 B4 H101 T0:100 CDuet_Fan
    

    Which means the fan will normally be running at 50% (i.e. when all drivers are under 100°C).

    But this leaves the question of how to ramp the fan up to 100% if the temp of any of the drivers goes above 100°C?

    Also I think you do not need L0.5 here. I won't hurt but don't see a reason to use this on a thermostatically controlled fan.

    I take your point, so now we have:

    > > M106 P1 S0.5 I1 F25000 B4 H101 T0:100 CDuet_Fan
    

    Thanks for the clarification.

    In this case, I think documentation on this parameter is very unhelpful to the point of being misleading (I'm mainly referring to the fourth example and the subsequent text that's supposed to explain it).

    OK, I have to say I find this very example in the documentation to be very clear - but it may be my software engineer background that immediately translates this into code in my head. 😁

    Can you say, how you would have explained this fourth example? Maybe we can improve documentation this way.

    Here's one example I've just encountered that illustrates the difficulty I have with following the text.

    Take this line from the documentation about the T parameter:

    "In this mode the fan will be on with the PWM set by the S parameter (subject to a minimum of 0.5) when the temperature of any of the heaters listed in the H parameter is at or above the trigger temperature set by the T parameter, and off otherwise. Thermostatic mode can be disabled using parameter H-1."

    ...it's very long and phrased in a highly complicated way. I'd break it down into much shorter and concise sentences, while trying to bear in mind that some of the people reading the text are totally clueless about these things (like me 🙂 )

    Regarding the examples themselves, I'd start by adding many more of them and have at least one example dedicated for each of the parameters (atm there are some parameters that aren't covered in the examples). In other words, I'd cover all the parameters, and use each example to tackle one parameter at a time (thus keeping things as simple as possible).

    I'd also rearange the text so that each example is followed by its explication so it's easier to read (rather than constantly scrolling up and down and getting confused).

    Moreover, I'd definitely add all the things you explained about the virtual heaters destination codes (100, 101, 102), as it isn't mentioned at all in the text, and to my mind at least, when the text says:

    "if any TMC2660 drivers (virtual heaters 101 and 102)..."

    and later on,

    "... to virtual heaters (which have heater numbers 100 upwards)..."

    This would logically (but apparently wrongly) imply that 'driver 0' is referred to by virtual heater '100'; 'driver 1' is referred to by virtual heater '101', etc.

    Lastly, notice that although virtual heaters 101 and 102 are explicitly mentioned in the text and the fourth example, there is no mention of how they are actually assigned and/or any mention of the DueX2/5.



  • @snowcrash said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    > > M106 P1 S0.5 I1 F25000 L0.5 B4 H101 T0:100 CDuet_Fan
    

    Which means the fan will normally be running at 50% (i.e. when all drivers are under 100°C).

    But this leaves the question of how to ramp the fan up to 100% if the temp of any of the drivers goes above 100°C?

    Usually this ramp-up would be progressing as the temperature progresses. Here we have special case as this is a virtual heater with only 3 fixed temperatures and jumps between them. This also means that as soon as one of the TMC drivers will go into warning state, the temperature will jump from 0°C to 100°C - so will the fan jump from its initial 50% speed to 100% speed without ramp-up.


    About the documenation part:
    More detailed explanation on virtual heaters can be found at M305 which also explains how to add your own. So this part is already there.

    Regarding the other parts you mentioned about M106: it is a wiki after all. How about you propose in this thread a new text with all the changes you think should go in there and we do a peer-review here? Afterwards one of us can update the wiki. I think that would be a great idea with input from a lot of people.
    Maybe even start a new thread about it so that everyone can spot the purpose of it right away.



  • @wilriker said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    @snowcrash said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    > > M106 P1 S0.5 I1 F25000 L0.5 B4 H101 T0:100 CDuet_Fan
    

    Which means the fan will normally be running at 50% (i.e. when all drivers are under 100°C).

    But this leaves the question of how to ramp the fan up to 100% if the temp of any of the drivers goes above 100°C?

    Usually this ramp-up would be progressing as the temperature progresses. Here we have special case as this is a virtual heater with only 3 fixed temperatures and jumps between them. This also means that as soon as one of the TMC drivers will go into warning state, the temperature will jump from 0°C to 100°C - so will the fan jump from its initial 50% speed to 100% speed without ramp-up.

    Cool, will try it out.


    About the documenation part:
    More detailed explanation on virtual heaters can be found at M305 which also explains how to add your own. So this part is already there.

    Fair enough, but then I'd have a note in M106 like the one in M143 saying:

    "(refer to M305 for further details on how to set this up)"

    Regarding the other parts you mentioned about M106: it is a wiki after all. How about you propose in this thread a new text with all the changes you think should go in there and we do a peer-review here? Afterwards one of us can update the wiki. I think that would be a great idea with input from a lot of people.
    Maybe even start a new thread about it so that everyone can spot the purpose of it right away.

    I just walked straight into this one, ha? 🙂 Man, I've got to learn when to keep my big mouth shut...

    Although I don't feel even marginally qualified to write/edit wiki's on the Duet, I can also see a certain advantage to the 'newbie writes the guide' approach. It will definitely keep things at the very basic level 🙂 Plus, I'm a big believer that one of the best ways to learn something is to try explaining it to someone else.

    The biggest question in this context is time. If I go about doing it, I'll try to do the best I can and that means investing time into it. Having multiple projects in the air atm, it won't be easy, but I promise to put this on my TODO list and hopefully get it in done as soon as time allows.


    Edit:

    @wilriker, I just had a quick look at the M305 section of the Wiki and it says there that:

    "Channel 1001 represents the temperature warning and overheat flags on the TMC2660 drivers on the Duet Wif/Ethernet."

    This means my M106 with H101 is not right, no?

    How sure are you about your description above of the virtual heaters' code designations?


    Edit of the Edit:

    Ok, it was a very quick look... from the text that follows that quoted above, it looks like you have it right.

    Sorry to have doubted you 🙂



  • Update:

    Hooked-up the fan as per the (corrected) schematic above and edited config.g to have the latest formulation of the M106 command, namely:

    M106 P2 S0.5 I1 F25000 L0.5 B4 H101 T0:100 CDuet_Fan
    

    (Note that I've changed the fan header to FAN2 both in the above command and in the hardware connection).

    ... but the fan isn't running.

    I believe the problem lies somewhere within the thermostatic-mode and/or triggering-range parameters, because when I tried running the fan in regular PWM mode with:

    M106 P2 S0.5 I1 F25000 L0.5 B4 H-1 CDuetFan
    

    I can manually control the fan's speed with the slider and it runs exactly as is it should.

    Another issue - which I don't know if related to the above - is that FAN2's name as defined in the M106 command (i.e. 'Duet_Fan'), doesn't show in the 'misc' section of DWG:

    0_1531556661228_misc.png

    I deleted all the browsing history, cookies, etc., and reloaded DWG, but the name still doesn't appear.

    I've attached the complete config.g and config-overdrive.g files below.

    Help please?

    config.g
    config-override.g



  • @snowcrash Let's start at the end: naming fans is currently only possible in @chrishamm's fork of RRF. In the regular version this will only be available from version 2.02 (note that 2.01 is next to come).

    About the fans not spinning: I just tested the same command (except the I1 part) on my machine and can confirm that it is not working this way - but if you lower the start value of the temperature to -1°C, i.e. T-1:100 it will work.
    I thought I had a theory why that is but in the middle of writing it here I realized it doesn't make sense. So: no clue why it has to be like that but it works. 😁

    And the last part: never be sorry to doubt me! I mean it. I'd rather have you doubt me all the time than expecting I know everything. When I got the email notification of your post I was also thinking about the possibility that in this case out of some reason the heater channel would have been required instead of the virtual heater, so I also doubted myself here. 😉


  • administrators

    The name (like many other string parameters in RRF) probably needs to be enclosed in double quotes.



  • @SnowCrash
    @wilriker said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    @snowcrash Let's start at the end: naming fans is currently only possible in @chrishamm's fork of RRF. In the regular version this will only be available from version 2.02 (note that 2.01 is next to come).

    This is true, however, @chrishamm released a version of the firmware with the fan name change included. You can find it here. And I can confirm as @dc42 says that you will need to enclose the name in double quotes. Ex: C"Duet_Fan". Once that's done it works as advertised.



  • @phaedrux said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    @SnowCrash
    And I can confirm as @dc42 says that you will need to enclose the name in double quotes. Ex: C"Duet_Fan". Once that's done it works as advertised.

    I just updated the wiki accordingly to reflect this as well.

    P.S.: I have not tried it but when enclosed in double-quotes I at least guess this can then also contain whitespace.



  • @phaedrux We are going to upvote each other into the hall of fame of reputation. 😂



  • @wilriker said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    @phaedrux said in Help Configuring PWM Fan in Thermostatic Mode for Duet Drivers:

    @SnowCrash
    And I can confirm as @dc42 says that you will need to enclose the name in double quotes. Ex: C"Duet_Fan". Once that's done it works as advertised.

    I just updated the wiki accordingly to reflect this as well.

    P.S.: I have not tried it but when enclosed in double-quotes I at least guess this can then also contain whitespace.

    Just tested and I can confirm that white space is allowed when enclosed with quotes.



  • Very cool, guys! thank you very much! great job and upvotes all around 🙂

    I'll test both the modified M106 formulation and fan naming tonight on my machine so as to (hopefully) add a nice 'solved' to the title of this tread.

    p.s. this has been nagging at me for a while now so have to ask: what do the little pin buttons next to each fan name in DWC actually do?



  • @snowcrash The pins let you lock the fan speed. Useful for gcode controlled fans if you set the speed too high or too low in the slicer.



  • Thanks, @Phaedrux 🙂

    I can also happily confirm @wilriker's solution (T-1:100) works great (Thanks @wilriker!)

    (though obviously I can only affirm this for the initial 50% speed and not the jump to 100% if temps go above 100°C - unless someone knows of a way to do this?)

    However, a final snag remains as the fan's naming still eludes me.

    I added double-quotes to the fan's name in the C parameter as instructed:

    M106 P2 S0.5 I1 F25000 L0.5 B4 H101 T-1:100 C"DuetFan"
    

    Reset the Duet and re-loaded DWC, But the name remains 'FAN2' like before.

    That's my M115 data:

    M115
    FIRMWARE_NAME: RepRapFirmware for Duet 2 WiFi/Ethernet FIRMWARE_VERSION: 1.21 ELECTRONICS: Duet WiFi 1.02 or later FIRMWARE_DATE: 2018-03-2

    So my firmware is 1.21, but perhaps my specific version of that release isn't up-to-date enough?



  • @snowcrash to get the renaming to work you would need to use the DWC version 1.22.1 v2 and the special firmware version 2.01 (b1.5?) from here https://forum.duet3d.com/topic/5485/duet-web-control-wishlist-notes-and-priorities/25

    But at this point it might just be worth waiting for the next official release of 2.01 and associated DWC version.



  • If the TMC chip does not report temperatures correctly, isn't it better to measure the temperatures with a sensor yourself (e.g. at the heat sink of the controller which is under max load, so X or Y controller) and take this temperature to decide how to handle fan speed?


Locked
 

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