Signal Generator
Dependencies: IniManager RA8875 Watchdog mbed-rtos mbed
Fork of speaker_demo_Analog by
SignalGenDAC.h@6:1f48212fbaf9, 2017-05-20 (annotated)
- Committer:
- WiredHome
- Date:
- Sat May 20 19:52:23 2017 +0000
- Revision:
- 6:1f48212fbaf9
- Parent:
- 5:49dd0c647a40
Signal Generator - a work in process as the need arises.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WiredHome | 6:1f48212fbaf9 | 1 | // |
WiredHome | 6:1f48212fbaf9 | 2 | // Signal Generator DAC Driver |
WiredHome | 2:8f71b71fce1b | 3 | // |
WiredHome | 2:8f71b71fce1b | 4 | // Derived from AN10917: Memory to DAC data transfers using the LPC1700's DMA |
WiredHome | 2:8f71b71fce1b | 5 | // |
WiredHome | 6:1f48212fbaf9 | 6 | // |
WiredHome | 2:8f71b71fce1b | 7 | #ifndef SIGNALGENDAC_H |
WiredHome | 2:8f71b71fce1b | 8 | #define SIGNALGENDAC_H |
WiredHome | 2:8f71b71fce1b | 9 | |
WiredHome | 2:8f71b71fce1b | 10 | #include "mbed.h" |
WiredHome | 2:8f71b71fce1b | 11 | |
WiredHome | 2:8f71b71fce1b | 12 | #include "SignalGenDefs.h" // access the waveform mode data type |
WiredHome | 2:8f71b71fce1b | 13 | |
WiredHome | 2:8f71b71fce1b | 14 | |
WiredHome | 2:8f71b71fce1b | 15 | #define SIGNAL_MEM_ENTRIES 2048 // size of the DAC buffer |
WiredHome | 2:8f71b71fce1b | 16 | |
WiredHome | 6:1f48212fbaf9 | 17 | /// The Signal Generator DAC Driver |
WiredHome | 6:1f48212fbaf9 | 18 | /// |
WiredHome | 6:1f48212fbaf9 | 19 | /// This class provides the interface to first configure the DAC hardware characteristics, |
WiredHome | 6:1f48212fbaf9 | 20 | /// and then to define and control the DAC output. |
WiredHome | 6:1f48212fbaf9 | 21 | /// |
WiredHome | 6:1f48212fbaf9 | 22 | /// A choice of waveforms is available (Sine, Square, Triangle, Sawtooth, and User Defined. |
WiredHome | 6:1f48212fbaf9 | 23 | /// |
WiredHome | 6:1f48212fbaf9 | 24 | /// @todo add support for User Defined waveform. |
WiredHome | 6:1f48212fbaf9 | 25 | /// |
WiredHome | 6:1f48212fbaf9 | 26 | /// @code |
WiredHome | 6:1f48212fbaf9 | 27 | /// SignalGenDAC g_signal; // defaults to LPC1768 mbed module (p18 and 3.3v) |
WiredHome | 6:1f48212fbaf9 | 28 | /// |
WiredHome | 6:1f48212fbaf9 | 29 | /// g_signal.PrepareWaveform(SG_SINE, 1000, 50, 2.2, 1.5); |
WiredHome | 6:1f48212fbaf9 | 30 | /// g_signal.Start(); |
WiredHome | 6:1f48212fbaf9 | 31 | /// wait_ms(1000); |
WiredHome | 6:1f48212fbaf9 | 32 | /// g_signal.Stop(); |
WiredHome | 6:1f48212fbaf9 | 33 | /// @endcode |
WiredHome | 6:1f48212fbaf9 | 34 | /// |
WiredHome | 2:8f71b71fce1b | 35 | class SignalGenDAC { |
WiredHome | 2:8f71b71fce1b | 36 | |
WiredHome | 2:8f71b71fce1b | 37 | public: |
WiredHome | 2:8f71b71fce1b | 38 | |
WiredHome | 2:8f71b71fce1b | 39 | /// Constructor, which is used to define the hardware |
WiredHome | 5:49dd0c647a40 | 40 | /// |
WiredHome | 5:49dd0c647a40 | 41 | /// The default parameters are based on the mbed LPC1768 micro, which has |
WiredHome | 5:49dd0c647a40 | 42 | /// AnalogOut on p18 and uses a 3.3v supply for the A/D reference. |
WiredHome | 2:8f71b71fce1b | 43 | /// |
WiredHome | 2:8f71b71fce1b | 44 | /// @param[in] aout is the analog output pin |
WiredHome | 2:8f71b71fce1b | 45 | /// @param[in] minV is based on the A/D low reference voltage (default 0.0) |
WiredHome | 5:49dd0c647a40 | 46 | /// @param[in] maxV is based on the A/D high reference voltage (default 3.3) |
WiredHome | 2:8f71b71fce1b | 47 | /// |
WiredHome | 5:49dd0c647a40 | 48 | SignalGenDAC(PinName aout = p18, float minV = 0.0, float maxV = 3.3); |
WiredHome | 2:8f71b71fce1b | 49 | |
WiredHome | 2:8f71b71fce1b | 50 | /// Destructor |
WiredHome | 2:8f71b71fce1b | 51 | /// |
WiredHome | 2:8f71b71fce1b | 52 | ~SignalGenDAC(); |
WiredHome | 2:8f71b71fce1b | 53 | |
WiredHome | 2:8f71b71fce1b | 54 | /// Create the waveform in the private memory buffer that is used to DMA to the DAC |
WiredHome | 2:8f71b71fce1b | 55 | /// |
WiredHome | 2:8f71b71fce1b | 56 | /// @param[in] mode defines the waveform: Sine, Square, Triangle, Sawtooth, User |
WiredHome | 2:8f71b71fce1b | 57 | /// @param[in] frequency defines the desired frequency |
WiredHome | 2:8f71b71fce1b | 58 | /// @param[in] dutycycle defined the duty cycle of the waveform to be created. The value |
WiredHome | 2:8f71b71fce1b | 59 | /// is range limited to 5 to 95 (representing 5 to 95 %). |
WiredHome | 2:8f71b71fce1b | 60 | /// @param[in] voltage is the peak-to-peak voltage, and it range limited to 0 to 3.0. |
WiredHome | 2:8f71b71fce1b | 61 | /// @param[in] offset is the offset voltage, and is range limited to 0 to 3.0. |
WiredHome | 2:8f71b71fce1b | 62 | /// |
WiredHome | 6:1f48212fbaf9 | 63 | void PrepareWaveform(SG_Waveform mode, float frequency, float dutycycle, float voltage, float offset); |
WiredHome | 2:8f71b71fce1b | 64 | |
WiredHome | 2:8f71b71fce1b | 65 | /// Start the signal, in either a oneshot, or continuous mode. |
WiredHome | 2:8f71b71fce1b | 66 | /// |
WiredHome | 2:8f71b71fce1b | 67 | /// @param[in] oneShot defaults false, which causes continuous mode. |
WiredHome | 2:8f71b71fce1b | 68 | /// When set true, one cycle is produced. |
WiredHome | 2:8f71b71fce1b | 69 | /// |
WiredHome | 2:8f71b71fce1b | 70 | void Start(bool oneShot = false); |
WiredHome | 2:8f71b71fce1b | 71 | |
WiredHome | 2:8f71b71fce1b | 72 | /// Stop the signal, if it is running. |
WiredHome | 2:8f71b71fce1b | 73 | /// |
WiredHome | 2:8f71b71fce1b | 74 | void Stop(void); |
WiredHome | 2:8f71b71fce1b | 75 | |
WiredHome | 2:8f71b71fce1b | 76 | /// Determine if the signal is running. |
WiredHome | 2:8f71b71fce1b | 77 | /// |
WiredHome | 2:8f71b71fce1b | 78 | /// @returns true if the signal is running. |
WiredHome | 2:8f71b71fce1b | 79 | /// |
WiredHome | 2:8f71b71fce1b | 80 | bool isRunning(void) { return isOn; } |
WiredHome | 2:8f71b71fce1b | 81 | |
WiredHome | 2:8f71b71fce1b | 82 | private: |
WiredHome | 2:8f71b71fce1b | 83 | bool isOn; // tracks whether the signal is on or off |
WiredHome | 2:8f71b71fce1b | 84 | AnalogOut * aout; |
WiredHome | 5:49dd0c647a40 | 85 | float frequency; // signal parameters |
WiredHome | 5:49dd0c647a40 | 86 | float dutycycle; |
WiredHome | 5:49dd0c647a40 | 87 | float voltage; |
WiredHome | 5:49dd0c647a40 | 88 | float offset; |
WiredHome | 2:8f71b71fce1b | 89 | float minV; // Based on the A/D hardware |
WiredHome | 2:8f71b71fce1b | 90 | float maxV; // Based on the A/D hardware |
WiredHome | 2:8f71b71fce1b | 91 | /// range limit a value. |
WiredHome | 2:8f71b71fce1b | 92 | float rangelimit(float value, float min, float max); |
WiredHome | 4:10281ddb673d | 93 | int numSamples; // private container for number of samples |
WiredHome | 2:8f71b71fce1b | 94 | }; |
WiredHome | 2:8f71b71fce1b | 95 | |
WiredHome | 2:8f71b71fce1b | 96 | #endif // SIGNALGENDAC_H |