Control DC fan motors with PWM along with a minimum PWM duty before turning on.

Embed: (wiki syntax)

« Back to documentation index

DcFan Class Reference

DcFan Class Reference

Interface to control a 2 pin DC fan. More...

#include <DcFan.h>

Public Member Functions

 DcFan (PinName pwm, float min_active_pwm)
 Create a fan motor control interface.
void speed (float speed)
 Set the speed of the motor.
float current_speed (void)
 Get the set speed of the motor, does *not* read RPMs from fan.

Detailed Description

Interface to control a 2 pin DC fan.

Set speed with PWM. No rpm readings

Drive a fan using a PwmOut Example:

 //Initialize and control a TEC connected to an H-bridge
 #include "mbed.h"
 #include "DcFan.h"
 
 DcFan myFan(p26, 0.5); // pwm, minimum pwm speed
 
 int main() {
     double fanSpeed = 0.0;
     while(1) {
         if (fanSpeed < 1.0)
         {
             fanSpeed += 0.1;
         }
         // fans won't turn on until fanSpeed >= 0.5
         Fans.speed(fanSpeed);
         wait(1.0);
     }
 }

Definition at line 56 of file DcFan.h.


Constructor & Destructor Documentation

DcFan ( PinName  pwm,
float  min_active_pwm 
)

Create a fan motor control interface.

Parameters:
pwmA PwmOut pin, driving the H-bridge enable line to control the speed

Definition at line 32 of file DcFan.cpp.


Member Function Documentation

float current_speed ( void   )

Get the set speed of the motor, does *not* read RPMs from fan.

void speed ( float  speed )

Set the speed of the motor.

Parameters:
speedThe speed of the motor as a normalised value between 0.0 and 1.0

Definition at line 47 of file DcFan.cpp.