Welcome! Log In Create A New Profile

Advanced

Fan issues

Posted by TinHead 
Fan issues
January 27, 2012 09:29AM
Hi,

I lust added 80 mm fans on my machine controlled from a PWM output (pin 4 on gen7 style atmega644).
I'm able to control them just fine but I have noticed two issues with the host (latest version):

1. The fan is turned on as soon as the slider is moved - I think it would be better to keep it off if it was off when adjusting the slider, and only turn it on if you press the "Fan On" button

2. I have noticed that turning the fan on or adjusting the fan speed during a print causes the printing to pause until the speed is set.

To replicate just try printing something, turn on fan -> should result in a small pause. Try dragging the speed slider -> it will pause until you release it, it will first jump back to the initial position, then jump to the position you attempted to set -> then printing resumes.

I think the problem causing both issues is that the host starts sending commands to the firmware as soon as you do something to that speed slider, instead of sending the command after the slider is released.

Not sure if this is a bug, let me know I'll open an issue.
Re: Fan issues
January 27, 2012 09:43AM
Well point 1, I'm not sure. If you move the slider you want to set the speed and that normally is the reason because you wan't it to run at that speed. So enabling the fan is a logical reaction.

The real problem is command flooding during slide. As manual commands are always executed the pause in print can really happen. I will check how I can prevent this command flooding, like sending the command if I haven't got a change for at least 0.5 seconds.

No need to open an issue, I'll change the behaviuor for the next release.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Fan issues
January 27, 2012 10:04AM
1. True you want the adjust the speed, but if it's off it should stay off. Like when you prepare for a print, you set the speed to 50 percent for example but you leave it off, you start printing and after 2 -3 layers you turn it on or maybe only when needed. I realize that turning on and off should be done by the gcode ... unfortunately Slic3r does not support it yet and skeinforge ... well I only got it to turn on the fan ad the beginning to the max ... not quite what I would hope for.

So I can only do it manually for now ... which brought 2 up smiling smiley
Re: Fan issues
January 27, 2012 02:02PM
I just checked the firmware and I think the problem is the firmware. Search in commands.cpp (around line 325)for

      case 106: //M106 Fan On
        wait_until_end_of_move();
        if (GCODE_HAS_S(com)){
            digitalWrite(FAN_PIN, HIGH);
            analogWrite(FAN_PIN, constrain(com->S,0,255) );
        }
        else
            digitalWrite(FAN_PIN, HIGH);
        break;

and uncomment the wait_until_end_of_move();

      case 106: //M106 Fan On
        // wait_until_end_of_move();
        if (GCODE_HAS_S(com)){
            digitalWrite(FAN_PIN, HIGH);
            analogWrite(FAN_PIN, constrain(com->S,0,255) );
        }
        else
            digitalWrite(FAN_PIN, HIGH);
        break;

I oriniginally added the wait, so the fan would only start after executing all moves until then. As you pointed out, this causes a short halt which can cause blobs. So the better solution would be to execute the change when it is seen without emptying the move queue. The disadvantage would be that you can not set the time exactly in code.
In this case it is no problem if the speed is changed directly. Also there are quite some calls, it is far behind the possible command rate.

Would be nice if you could test (I don't have a fan for testing) the change.

I disable the auto on change for the next release of the host.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Fan issues
January 27, 2012 03:10PM
OK I will try and let you know how it went.
Re: Fan issues
January 28, 2012 03:20AM
Hi,

I fixed the problem in version 0.45.
You can use your old configuration.h if you upgrade.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Fan issues
February 01, 2012 07:37AM
Hi,

Thanks for looking into it, I'll check as soon as I have my machine back online, I had a major hotend failure.
Re: Fan issues
February 03, 2012 10:29AM
Well my problem was not the hotend as it turns out, I'll be checking the update this weekend.
Re: Fan issues
February 05, 2012 05:27PM
Will the fan work on another pin? I've tried the default which is 31, this is a0, the fan is either off under 50% or full on at over 50% value. I tried 14 (pin 20 PD6) which is a spare PWM pin the fan doesn't do anything. Home built Gen7. Loving repetier firmware and host.
Paul
Re: Fan issues
February 05, 2012 06:00PM
Hardware PWM on PD6 is not possible with Gen7. This interrupt is used to control the extruder, thats why it doesn't work.

I could write a SIMULATE_FAN_PWM option, which does PWM simulation for any pin you want for your fan. To my shame I have only a gen6 which has no free pins for a fan. So if you say you will test it, I write it.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Fan issues
February 05, 2012 06:08PM
Sure, if you write it, the least i could do would be to test it and report back.
Cheers
Paul
Re: Fan issues
February 06, 2012 11:43AM
Ok, I've uploaded the new firmware with PWM simulation for fans on github.

The additions to configuration.h are shown below, so you can easy update your existing config.

/**
Normally you need a PWM controlable output, to define different fan speeds. If you
don't have one, you can only turn your fan on or off.

As a sulution, you can simulate PWM for your pin. This works for all pins, even non-PWM pins!
If your fan is connected to a PWM output that is used by the firmware internally, you must
activate PWM simulation.

To active fan PWM simulation uncomment the next define.
*/
//#define SIMULATE_FAN_PWM

Make sure to use pin define in pins.h as FAN_PIN and uncomment SIMULATE_FAN_PWM

I'm quite sure it works, but I will wait for your report, before I add it officially in the changelog.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Fan issues
February 06, 2012 06:19PM
Wow, your fast, sorry but I've only just got in and can't try now, will test this out tomorrow night, and tell you how it goes.
thanks
Paul
Re: Fan issues
February 07, 2012 04:27PM
I'm sorry to report that it doesn't seem to work. Tried it on pin14 and pin31 ( ic pin 20 and 40), no movement of the fan. Reinstalled the previous firmware (5b925be) and the fan turns off or fully on on pin 31.

tried with SIMULATE_FAN_PWM commented out and the fan works only on/off as expected.

It's below freezing in the garage so I don't really need a fan at the moment :-)
Paul

Edited 1 time(s). Last edit at 02/07/2012 05:17PM by P4LIL.
Re: Fan issues
February 08, 2012 04:14AM
I use the fan on pin 4 since I don't have a heated printed bed, and it works flawlessly with hardware pwm.

I also want to report that the firmware reacts a lot better now on changing the fan speed.
Re: Fan issues
February 08, 2012 12:01PM
@P4LIL

I just misused by heater as fan output and everything worked well. I could dimm the heater led with the fan slider and got some debug messages i inserted to verify it is really using the simulation. The only thing, I could think off was that I didn't configure the FAN pin explicitly as output. I just uploaded a new Repetier.pde where the FAN pin is explicitly defined as output. I hope with that change it works also for your board, so I hope I hear an "it works now!".

@TinHead

Hardware PWM is the preferred way. But the firmware uses two timer interrupts for fluid execution and the PWM pins they correspond to can't be used for that purpose, which is the problem of P4LIL and other Gen7 user.

Good to know that the removed wait is enough to make it react better.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Fan issues
February 08, 2012 01:39PM
It works now! Thank you, but it seems to run fine up to 85.5% above that it starts hunting and not really increasing in speed. I will try and get a scope on it later to see if it is my drive mosfet.
Thanks again
Paul
Re: Fan issues
February 08, 2012 01:47PM
P4LIL Wrote:
-------------------------------------------------------
> It works now! Thank you,
Very good.
> but it seems to run fine
> up to 85.5% above that it starts hunting and not
> really increasing in speed.

What do you mean with that?Hunting???
I'm sure the time with power is increased linear until nearly 100% (PWM has always a drop top 0).
The signal is repeated with ca. 122 hz, which shouldn't be too fast for a mosfet.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Fan issues
February 08, 2012 02:27PM
Sorry, hunting is when the motor is not at a static speed. The fan's speed oscillates above 85.5% going fast then slow with a period of about half a second and doesn't seem to really increase in speed above that point. It may be that the small MOSFET I've got cant handle the load of the fan, though I think it should.

Paul
Re: Fan issues
February 08, 2012 03:17PM
Fans have electronics in them for brushless commutation. It may get confused by high frequency PWM. Maybe lower frequency would be better.

Also the PWM might beat with commutation frequency causing it to cycle at the difference frequency,


[www.hydraraptor.blogspot.com]
Re: Fan issues
February 08, 2012 04:42PM
The pwm period is about 6.8mS and the pwm granularity about 0.52mS, the period increasing by 0.52mS about every 7% of fan speed, this means that at after about 12 steps ( about 85%) it runs out of spce, but the code always sets the pin low on each interrupt period so that after 85% the period increases to allow for that low pulse. I think that in the first if/then sequence the fan_pwm_pos was overflowing, I changed the code to reset fan_pwm_pos to 0 on overflow as below and it seems to be working properly now. The PWM period is now about 7.2mS, there is still a bit of hunting, but as nophed sys this is probably down to the fan motor.

#ifdef SIMULATE_FAN_PWM
  // If your fan output has no pwm or pwm is blocked by this interrupt routine
  
  if(fan_pwm_pos<=fan_speed) {
    fan_pwm_pos+=printer_state.timer0Interval;
    if(fan_pwm_pos>=2047) {                            // added to reset on rollover PJW
      fan_pwm_pos=0;}
    if(fan_pwm_pos>fan_speed) {
      WRITE(FAN_PIN,0 ); 
    }
  } else {
    fan_pwm_pos+=printer_state.timer0Interval;
    if(fan_pwm_pos>=2047) {
      fan_pwm_pos=0;
      if(fan_speed>0) { // Turn only on for values > 0
        WRITE(FAN_PIN,1 ); 
      }
    }
  }
#endif

Im not an Atmel person I use PICS generally, though im slowly understanding arduino java, so I hope ive not done anything untoward with the code.

Thanks
Paul

Oh and Hi NopHead, thanks to your parts of EBay ive got into this 3d printing lark, just got get my prints as good as yourssmileys with beer
Re: Fan issues
February 09, 2012 11:19AM
That was a really good analysis. As I copied this from the software PWM for heater, the same problem was there.

I just made an official release for all the software PWM changes.

I changed the FAN frequency to 50% so you get higher precision and less problems with fan electronics (thanks nophead for the hint).
Your code is correct only the 2047 should better be 2040 as it was 255*8. The same with my 2047 which also should be 2040 (I guess you copied my error :-). In the new version it is even 4080, because I reduced the frequency.

There will still be a little error, because the frequency the interrupt is called depends on the max. extruder speed and extruder steps per mm. But the calls are around 8000-15000 Hz, so that shouldn't be the greatest problem. In case the extruder speed is not used, I quadrupled the default frequency for better PWM.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Fan issues
February 09, 2012 02:37PM
The new release works perfectly now, thank you.

Im glad I have been a little help rather than just a user of your code.

Paul
Re: Fan issues
February 10, 2012 03:11AM
Yes, you really were a great help. Only your precise analysis showed the last error. Most people would have said, it works after the second iteration and I wouldn't have seen the full power issue.


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Fan issues
March 01, 2012 03:32PM
Sorry to bring this up again, but been trying Slic3r 0.7 with the fan cooling, and I noticed that M106 S255 wasnt turning on the fan, I think with the code as it stands, it would enter the following routine with fan_speed = 4080 this is then compared to fan_pwm_pos which can never be 4080 as it rolls back to 0, therefore the PWM pin is never set high. Strangely if the fan was already running it could be increased to 100%

// If your fan output has no pwm or pwm is blocked by this interrupt routine
  if(fan_pwm_pos<=fan_speed) {
    fan_pwm_pos+=printer_state.timer0Interval;
    if(fan_pwm_pos>=4080) 
      fan_pwm_pos=0;
    if(fan_pwm_pos>fan_speed) {
      WRITE(FAN_PIN,0 ); 
    }
  } else {
    fan_pwm_pos+=printer_state.timer0Interval;
    if(fan_pwm_pos>=4080) {
      fan_pwm_pos=0;
      if(fan_speed>0) { // Turn only on for values > 0
        WRITE(FAN_PIN,1 ); 
      }
    }
  }

ive changed my code to

// If your fan output has no pwm or pwm is blocked by this interrupt routine
    fan_pwm_pos+=printer_state.timer0Interval;
    if(fan_pwm_pos>=4080) 
    {
      fan_pwm_pos=0;
    }
    if ((fan_pwm_pos<=fan_speed) & (fan_speed>0)) 
    {
      WRITE(FAN_PIN,1 );
    }
    else
    {
     WRITE(FAN_PIN,0 ); 
    }

and it seems to now work correctly

Paul


Paul

Mendel prusa, homemade Gen7 on stripboard

'A little knowledge is a dangerous thing' - Alexander Pope
Re: Fan issues
March 01, 2012 03:41PM
You are right, this version was wrong. The problem is fixed in the latest version where the code is as follows:

#ifdef SIMULATE_FAN_PWM
  // If your fan output has no pwm or pwm is blocked by this interrupt routine
  if(fan_pwm_pos<=fan_speed) {
    fan_pwm_pos+=printer_state.timer0Interval;
    if(fan_pwm_pos>=4080) {
      fan_pwm_pos=0;
      WRITE(FAN_PIN,1 ); 
    } else if(fan_pwm_pos>fan_speed) {
      WRITE(FAN_PIN,0 ); 
    }
  } else {
    fan_pwm_pos+=printer_state.timer0Interval;
    if(fan_pwm_pos>=4080) {
      fan_pwm_pos=0;
      if(fan_speed>0) { // Turn only on for values > 0
        WRITE(FAN_PIN,1 ); 
      }
    }
  }
#endif


Repetier-Software - the home of Repetier-Host (Windows, Linux and Mac OS X) and Repetier-Firmware.
Repetier-Server - the solution to control your printer from everywhere.
Visit us on Facebook and Twitter!
Re: Fan issues
March 01, 2012 04:22PM
doh!, I should really keep up to date.

Thanks

Paul
Sorry, only registered users may post in this forum.

Click here to login