The PWM output by software. Can be output to any pin. It can be used to replace the Pwmout.
Dependents: SoftPWM_Example XYZ_Joystick_PWM mbed_pwm mbed_Ahan_robocon ... more
SoftPWM.h
00001 #ifndef SoftPWM_H 00002 #define SoftPWM_H 00003 #define POSITIVE true 00004 #define NEGATIVE false 00005 00006 #include "mbed.h" 00007 00008 class SoftPWM 00009 { 00010 private: 00011 Timeout _timeout; 00012 Ticker _ticker; 00013 void end(); 00014 DigitalOut pulse; 00015 bool positive; 00016 void TickerInterrapt(); 00017 float width; 00018 float interval; 00019 public: 00020 SoftPWM(PinName,bool mode=true); 00021 // void attach_us(int); 00022 void start(); 00023 void write(float); 00024 float read(); 00025 void pulsewidth(float); 00026 void pulsewidth_ms(int); 00027 void pulsewidth_us(int); 00028 void period(float); 00029 void period_ms(int); 00030 void period_us(int); 00031 void stop(); 00032 operator float() { 00033 if ( width <= 0.0 ) return 0.0; 00034 if ( width > 1.0 ) return 1.0; 00035 return width / interval; 00036 } 00037 SoftPWM& operator=(float duty) { 00038 width = interval * duty; 00039 if ( duty <= 0.0 ) width = 0.0; 00040 if ( duty > 1.0 ) width = interval; 00041 return *this; 00042 } 00043 00044 }; 00045 #endif
Generated on Fri Jul 15 2022 22:21:28 by 1.7.2