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: Motor_Control_using_lib Motor_Control_API
PwmOutResetSync.h
00001 00002 #ifndef PWMOUT_RESET_SYNC_H 00003 #define PWMOUT_RESET_SYNC_H 00004 00005 #if !defined(TARGET_RZ_A1H) 00006 #error The PwmOutResetSync library is not supported on this target 00007 #endif 00008 00009 #include "platform.h" 00010 #include "pwmout_rst_sync_api.h" 00011 00012 /** A pulse-width modulation digital output 00013 * 00014 * Example 00015 * @code 00016 * // Moter Control. 00017 * #include "mbed.h" 00018 * #include "PwmOutResetSync.h" 00019 * 00020 * PwmOutResetSync pwm_l(P4_4); 00021 * PwmOutResetSync pwm_r(P4_5); 00022 * 00023 * int main() { 00024 * while(1) { 00025 * pwm_l = 0.5; 00026 * pwm_r = 0.5; 00027 * wait(1); 00028 * pwm_l = 0.0; 00029 * pwm_r = 0.8; 00030 * wait(1); 00031 * } 00032 * } 00033 * @endcode 00034 * 00035 * @note 00036 * The PWMs all share the same period - if you change the period for 00037 * one, you change it for all. 00038 * Routines that change the period maintain the duty cycle for its PWM. 00039 */ 00040 class PwmOutResetSync { 00041 00042 public: 00043 00044 /** Create a PwmOutResetSync connected to the specified pin 00045 * 00046 * @param pin PwmOutResetSync pin to connect to 00047 * 00048 * @attention 00049 * Output Pins for Reset-Synchronized PWM Mode. 00050 * [TIOC3B : P8_11, (P7_9), (P3_5)], 00051 * [TIOC4A : P3_8, P4_4, (P7_12), (P11_0)], 00052 * [TIOC4B : P3_9, P4_5, (P7_13), (P11_1)] 00053 * ():On the GR-PEACH, it can not be used. 00054 * 00055 */ 00056 PwmOutResetSync(PinName pin) { 00057 pwmout_rst_sync_init(&_pwm, pin); 00058 } 00059 00060 /** Destructor 00061 * 00062 */ 00063 virtual ~PwmOutResetSync() { 00064 pwmout_rst_sync_free(&_pwm); 00065 } 00066 00067 /** Set the ouput duty-cycle, specified as a percentage (float) 00068 * 00069 * @param value A floating-point value representing the output duty-cycle, 00070 * specified as a percentage. The value should lie between 00071 * 0.0f (representing on 0%) and 1.0f (representing on 100%). 00072 * Values outside this range will be saturated to 0.0f or 1.0f. 00073 */ 00074 void write(float value) { 00075 pwmout_rst_sync_write(&_pwm, value); 00076 } 00077 00078 /** Return the current output duty-cycle setting, measured as a percentage (float) 00079 * 00080 * @returns 00081 * A floating-point value representing the current duty-cycle being output on the pin, 00082 * measured as a percentage. The returned value will lie between 00083 * 0.0f (representing on 0%) and 1.0f (representing on 100%). 00084 * 00085 * @note 00086 * This value may not match exactly the value set by a previous <write>. 00087 */ 00088 float read() { 00089 return pwmout_rst_sync_read(&_pwm); 00090 } 00091 00092 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same. 00093 * 00094 * @param seconds Specified in seconds (float). The maximum period is 2s. When you set 00095 * a number greater than 2s, 2s is set. 00096 * 00097 * @note 00098 * The resolution is currently in microseconds; periods smaller than this 00099 * will be set to zero. 00100 */ 00101 static void period(float seconds) { 00102 pwmout_rst_sync_period(seconds); 00103 } 00104 00105 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same. 00106 * 00107 * @param seconds Specified in milli-seconds (int). The maximum period is 2s. When you set 00108 * a number greater than 2s, 2s is set. 00109 */ 00110 static void period_ms(int ms) { 00111 pwmout_rst_sync_period_ms(ms); 00112 } 00113 00114 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same. 00115 * 00116 * @param seconds Specified in micro-seconds (int). The maximum period is 2s. When you set 00117 * a number greater than 2s, 2s is set. 00118 */ 00119 static void period_us(int us) { 00120 pwmout_rst_sync_period_us(us); 00121 } 00122 00123 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same. 00124 */ 00125 void pulsewidth(float seconds) { 00126 pwmout_rst_sync_pulsewidth(&_pwm, seconds); 00127 } 00128 00129 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same. 00130 */ 00131 void pulsewidth_ms(int ms) { 00132 pwmout_rst_sync_pulsewidth_ms(&_pwm, ms); 00133 } 00134 00135 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same. 00136 */ 00137 void pulsewidth_us(int us) { 00138 pwmout_rst_sync_pulsewidth_us(&_pwm, us); 00139 } 00140 00141 /** A operator shorthand for write() 00142 */ 00143 PwmOutResetSync& operator= (float value) { 00144 write(value); 00145 return *this; 00146 } 00147 00148 PwmOutResetSync& operator= (PwmOutResetSync& rhs) { 00149 write(rhs.read()); 00150 return *this; 00151 } 00152 00153 /** An operator shorthand for read() 00154 */ 00155 operator float() { 00156 return read(); 00157 } 00158 00159 protected: 00160 pwmout_rst_sync_t _pwm; 00161 }; 00162 00163 #endif
Generated on Tue Jul 12 2022 14:35:42 by
1.7.2