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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DcFan.h Source File

DcFan.h

00001 /* Mbed DC fan PWM control.  
00002 Copyright 2020 Jonathan L. Martin <jon.martini@gmail.com>
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy of 
00005 this software and associated documentation files (the "Software"), to deal in 
00006 the Software without restriction, including without limitation the rights to 
00007 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
00008 the Software, and to permit persons to whom the Software is furnished to do so, 
00009 subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in all 
00012 copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
00020 SOFTWARE.
00021 
00022 Allows setting a minimum threshold
00023 
00024 */
00025 
00026 #ifndef MBED_DC_FAN_H
00027 #define MBED_DC_FAN_H
00028 
00029 #include "mbed.h"
00030 
00031 /** Interface to control a 2 pin DC fan.  Set speed with PWM. No rpm readings
00032  *
00033  * Drive a fan using a PwmOut
00034  * Example:
00035  * @code
00036  * //Initialize and control a TEC connected to an H-bridge
00037  * #include "mbed.h"
00038  * #include "DcFan.h"
00039  * 
00040  * DcFan myFan(p26, 0.5); // pwm, minimum pwm speed
00041  * 
00042  * int main() {
00043  *     double fanSpeed = 0.0;
00044  *     while(1) {
00045  *         if (fanSpeed < 1.0)
00046  *         {
00047  *             fanSpeed += 0.1;
00048  *         }
00049  *         // fans won't turn on until fanSpeed >= 0.5
00050  *         Fans.speed(fanSpeed);
00051  *         wait(1.0);
00052  *     }
00053  * }
00054  * @endcode
00055  */
00056 class DcFan {
00057 public:
00058 
00059     /** Create a fan motor control interface    
00060      *
00061      * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed
00062      */
00063     DcFan(PinName pwm, float min_active_pwm);
00064     
00065     /** Set the speed of the motor
00066      * 
00067      * @param speed The speed of the motor as a normalised value between 0.0 and 1.0
00068      */
00069     void speed(float speed);
00070 
00071     /** Get the set speed of the motor, does *not* read RPMs from fan */
00072     float current_speed(void);
00073 
00074 protected:
00075     PwmOut _pwm;
00076     float  _min_active_pwm;
00077 };
00078 
00079 #endif