syouichi imamori
/
MulticopterQuadX
Quad X Type Multicopter
SoftPWM/SoftPWM.h@8:1db19b529b22, 2021-02-21 (annotated)
- Committer:
- komaida424
- Date:
- Sun Feb 21 05:14:57 2021 +0000
- Revision:
- 8:1db19b529b22
- Parent:
- 4:4060309b9cc0
rev 020
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
komaida424 | 2:59ac9df97701 | 1 | #ifndef SoftPWM_H |
komaida424 | 2:59ac9df97701 | 2 | #define SoftPWM_H |
komaida424 | 2:59ac9df97701 | 3 | #define POSITIVE true |
komaida424 | 2:59ac9df97701 | 4 | #define NEGATIVE false |
komaida424 | 2:59ac9df97701 | 5 | |
komaida424 | 2:59ac9df97701 | 6 | #include "mbed.h" |
komaida424 | 2:59ac9df97701 | 7 | |
komaida424 | 2:59ac9df97701 | 8 | class SoftPWM |
komaida424 | 2:59ac9df97701 | 9 | { |
komaida424 | 2:59ac9df97701 | 10 | private: |
komaida424 | 2:59ac9df97701 | 11 | Timeout _timeout; |
komaida424 | 2:59ac9df97701 | 12 | Ticker _ticker; |
komaida424 | 2:59ac9df97701 | 13 | void end(); |
komaida424 | 2:59ac9df97701 | 14 | DigitalOut pulse; |
komaida424 | 2:59ac9df97701 | 15 | bool positive; |
komaida424 | 2:59ac9df97701 | 16 | void TickerInterrapt(); |
komaida424 | 2:59ac9df97701 | 17 | float width; |
komaida424 | 2:59ac9df97701 | 18 | float interval; |
komaida424 | 2:59ac9df97701 | 19 | public: |
komaida424 | 2:59ac9df97701 | 20 | SoftPWM(PinName,bool mode=true); |
komaida424 | 2:59ac9df97701 | 21 | // void attach_us(int); |
komaida424 | 2:59ac9df97701 | 22 | void start(); |
komaida424 | 2:59ac9df97701 | 23 | void write(float); |
komaida424 | 2:59ac9df97701 | 24 | float read(); |
komaida424 | 2:59ac9df97701 | 25 | void pulsewidth(float); |
komaida424 | 2:59ac9df97701 | 26 | void pulsewidth_ms(int); |
komaida424 | 2:59ac9df97701 | 27 | void pulsewidth_us(int); |
komaida424 | 2:59ac9df97701 | 28 | void period(float); |
komaida424 | 2:59ac9df97701 | 29 | void period_ms(int); |
komaida424 | 2:59ac9df97701 | 30 | void period_us(int); |
komaida424 | 2:59ac9df97701 | 31 | void stop(); |
komaida424 | 2:59ac9df97701 | 32 | operator float() { |
komaida424 | 4:4060309b9cc0 | 33 | if ( width <= 0.0f ) return 0.0f; |
komaida424 | 4:4060309b9cc0 | 34 | if ( width > 1.0f ) return 1.0f; |
komaida424 | 2:59ac9df97701 | 35 | return width / interval; |
komaida424 | 2:59ac9df97701 | 36 | } |
komaida424 | 2:59ac9df97701 | 37 | SoftPWM& operator=(float duty) { |
komaida424 | 2:59ac9df97701 | 38 | width = interval * duty; |
komaida424 | 4:4060309b9cc0 | 39 | if ( duty <= 0.0f ) width = 0.0f; |
komaida424 | 4:4060309b9cc0 | 40 | if ( duty > 1.0f ) width = interval; |
komaida424 | 2:59ac9df97701 | 41 | return *this; |
komaida424 | 2:59ac9df97701 | 42 | } |
komaida424 | 2:59ac9df97701 | 43 | |
komaida424 | 2:59ac9df97701 | 44 | }; |
komaida424 | 2:59ac9df97701 | 45 | #endif |