Provides a simple way to generate complex square wave signals on any available pin. In addition the SignalGenerator can generate a carrier wave which is useful when generating IR signals to control electronic devices like a TV etc. The signal generation can be carried out either synchronously or asynchronously. In the case of synchronous signal generation all interrupts can optionally be disabled to improve timing accuracy.
SignalGenerator.h@1:4a1bcc41c473, 2014-09-12 (annotated)
- Committer:
- taylorza
- Date:
- Fri Sep 12 04:13:43 2014 +0000
- Revision:
- 1:4a1bcc41c473
- Parent:
- 0:b7c65c0d82d3
- Child:
- 2:b2a449bd787f
Added author details in comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
taylorza | 1:4a1bcc41c473 | 1 | /////////////////////////////////////////////////////////////////////////////// |
taylorza | 1:4a1bcc41c473 | 2 | // Signal Generator |
taylorza | 1:4a1bcc41c473 | 3 | // Author: Chris Taylor (taylorza) |
taylorza | 0:b7c65c0d82d3 | 4 | #ifndef __SIGNALGENERATOR_H__ |
taylorza | 0:b7c65c0d82d3 | 5 | #define __SIGNALGENERATOR_H__ |
taylorza | 0:b7c65c0d82d3 | 6 | |
taylorza | 0:b7c65c0d82d3 | 7 | /** Simplifies generation of a high frequency signal on any pin with optional support for a carrier frequency. |
taylorza | 0:b7c65c0d82d3 | 8 | */ |
taylorza | 0:b7c65c0d82d3 | 9 | class SignalGenerator |
taylorza | 0:b7c65c0d82d3 | 10 | { |
taylorza | 0:b7c65c0d82d3 | 11 | public: |
taylorza | 0:b7c65c0d82d3 | 12 | /** Create a SignalGenerator tied to the specified pin. */ |
taylorza | 0:b7c65c0d82d3 | 13 | SignalGenerator(PinName pin); |
taylorza | 0:b7c65c0d82d3 | 14 | |
taylorza | 0:b7c65c0d82d3 | 15 | /** Set the state of the pin associated with the SignalGenerator. */ |
taylorza | 0:b7c65c0d82d3 | 16 | void set(bool pinState); |
taylorza | 0:b7c65c0d82d3 | 17 | |
taylorza | 0:b7c65c0d82d3 | 18 | /** Set parameter and generate the corresponding signal on the pin associated with the SignalGenerator. |
taylorza | 0:b7c65c0d82d3 | 19 | * @param initialState Defines the initial state of the signal pin |
taylorza | 0:b7c65c0d82d3 | 20 | * @param timingBuffer Specificies the wime periods in microseconds before the signal pin changes state |
taylorza | 0:b7c65c0d82d3 | 21 | * @param bufferCount The count of transition times passed in the timingBuffer |
taylorza | 0:b7c65c0d82d3 | 22 | * @param lastStateHoldTime The time in microseconds that the last state is held |
taylorza | 0:b7c65c0d82d3 | 23 | * @param carrierFrequency The carrier frequency in Hz |
taylorza | 0:b7c65c0d82d3 | 24 | */ |
taylorza | 1:4a1bcc41c473 | 25 | void set( |
taylorza | 1:4a1bcc41c473 | 26 | bool initialState, |
taylorza | 1:4a1bcc41c473 | 27 | uint32_t timingBuffer[], |
taylorza | 1:4a1bcc41c473 | 28 | uint16_t bufferCount, |
taylorza | 1:4a1bcc41c473 | 29 | uint32_t lastStateHoldTime = 0, |
taylorza | 1:4a1bcc41c473 | 30 | int carrierFrequency = -1); |
taylorza | 1:4a1bcc41c473 | 31 | |
taylorza | 0:b7c65c0d82d3 | 32 | private: |
taylorza | 0:b7c65c0d82d3 | 33 | DigitalOut _pin; |
taylorza | 0:b7c65c0d82d3 | 34 | }; |
taylorza | 0:b7c65c0d82d3 | 35 | |
taylorza | 0:b7c65c0d82d3 | 36 | #endif //__SIGNALGENERATOR_H__ |