The PWM output by software. Can be output to any pin. It can be used to replace the Pwmout.
Fork of SoftPWM by
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 double width; 00018 double interval; 00019 public: 00020 SoftPWM(PinName,bool mode=true); 00021 // void attach_us(int); 00022 void start(); 00023 void write(double); 00024 double read(); 00025 void pulsewidth(double); 00026 void pulsewidth_ms(int); 00027 void pulsewidth_us(int); 00028 void period(double); 00029 void period_ms(int); 00030 void period_us(int); 00031 void stop(); 00032 operator double() { 00033 if ( width <= 0.0 ) return 0.0; 00034 if ( width > 1.0 ) return 1.0; 00035 return width / interval; 00036 } 00037 SoftPWM& operator=(double duty) { 00038 width = interval * duty; 00039 if ( duty <= 0.0 ) width = 0.0f; 00040 if ( duty > 1.0 ) width = interval; 00041 return *this; 00042 } 00043 00044 }; 00045 #endif
Generated on Tue Jul 26 2022 21:40:50 by
