Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed_ES410_simpleSpeedMeasurement mbed_ES20X_V21_Tester
MotCon.h
00001 /* mbed MotCon Library, for the various DC motor control IC's using PWM and one 00002 * or two direction pins. 00003 * Copyright (c) 2016, Joseph Bradshaw 00004 * 20180316 - Added shorthand read and write operator functions. 00005 * May need to check implementation of overloaded class write function 00006 * using invert 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a copy 00009 * of this software and associated documentation files (the "Software"), to deal 00010 * in the Software without restriction, including without limitation the rights 00011 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00012 * copies of the Software, and to permit persons to whom the Software is 00013 * furnished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included in 00016 * all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00022 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00023 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00024 * THE SOFTWARE. 00025 */ 00026 #include "mbed.h" 00027 00028 #ifndef MBED_MOTCON_H 00029 #define MBED_MOTCON_H 00030 00031 class MotCon{ 00032 public: 00033 /** Create a motor control port object connected to the specified pins 00034 * 00035 * @param pwm_pin PwmOut pin for the enable or speed control 00036 * @param dir1_pin DigitalOut pin to control the motor direction 00037 */ 00038 MotCon(PinName pwm_pin, PinName dir1_pin); 00039 00040 /** Create a motor control port object connected to the specified pins. 00041 * The two direction pins are typically complementary and provide 00042 * the capability of dynamic braking, free-wheeling, forward and reverse. 00043 * 00044 * @param pwm_pin PwmOut pin for the enable or speed control 00045 * @param dir1_pin DigitalOut pin to control the motor direction 00046 * @param dir2_pin DigitalOut pin to control the motor direction 00047 */ 00048 MotCon(PinName pwm_pin, PinName dir1_pin, PinName dir2_pin); 00049 00050 /** This function will set the direction and pwm percent scaled 00051 * from 0.0 - 1.0 and control the direction pin or pins 00052 * If two direction pins are used, the user can control the breaking 00053 * mode by using the mutator functions for get_mode() and set_mode() 00054 * If only one direction pin is used, dynamic breaking and syncronous 00055 * rectification are assumed. See the specific motor driver part datasheet 00056 * for additional details. 00057 * 00058 * @param dc is signed float duty cycle (+/-1.0) 00059 */ 00060 void mot_control(float dc); 00061 void mot_control(float dc, int invert); //this function can be used to invert the motor direction 00062 00063 void setMode(int mode); //mode: 1 = dynamic braking, 0 = free-wheeling (default) 00064 int getMode(void); 00065 float read(void); 00066 /** Shorthand for the write and read functions */ 00067 MotCon& operator= (float value); 00068 MotCon& operator= (MotCon& rhs); 00069 operator float(); 00070 00071 float duty_cycle; 00072 00073 bool mc_mode; 00074 private: 00075 bool _dir2; 00076 00077 protected: 00078 PwmOut _pwm_pin; 00079 DigitalOut _dir1_pin; 00080 DigitalOut _dir2_pin; 00081 }; 00082 00083 #endif
Generated on Wed Jul 13 2022 04:21:51 by
