Signal Generator

Dependencies:   IniManager RA8875 Watchdog mbed-rtos mbed

Fork of speaker_demo_Analog by jim hamblen

Committer:
WiredHome
Date:
Mon Jan 16 21:05:13 2017 +0000
Revision:
4:10281ddb673d
Parent:
2:8f71b71fce1b
Child:
5:49dd0c647a40
Basic functions (excluding frequency) are working. Waveform, amplitude, offset, start/stop.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 2:8f71b71fce1b 1
WiredHome 2:8f71b71fce1b 2 //
WiredHome 2:8f71b71fce1b 3 // Derived from AN10917: Memory to DAC data transfers using the LPC1700's DMA
WiredHome 2:8f71b71fce1b 4 //
WiredHome 2:8f71b71fce1b 5 #ifndef SIGNALGENDAC_H
WiredHome 2:8f71b71fce1b 6 #define SIGNALGENDAC_H
WiredHome 2:8f71b71fce1b 7
WiredHome 2:8f71b71fce1b 8 #include "mbed.h"
WiredHome 2:8f71b71fce1b 9
WiredHome 2:8f71b71fce1b 10 #include "SignalGenDefs.h" // access the waveform mode data type
WiredHome 2:8f71b71fce1b 11
WiredHome 2:8f71b71fce1b 12
WiredHome 2:8f71b71fce1b 13 #define SIGNAL_MEM_ENTRIES 2048 // size of the DAC buffer
WiredHome 2:8f71b71fce1b 14
WiredHome 2:8f71b71fce1b 15 class SignalGenDAC {
WiredHome 2:8f71b71fce1b 16
WiredHome 2:8f71b71fce1b 17 public:
WiredHome 2:8f71b71fce1b 18
WiredHome 2:8f71b71fce1b 19 /// Constructor, which is used to define the hardware
WiredHome 2:8f71b71fce1b 20 ///
WiredHome 2:8f71b71fce1b 21 /// @param[in] aout is the analog output pin
WiredHome 2:8f71b71fce1b 22 /// @param[in] minV is based on the A/D low reference voltage (default 0.0)
WiredHome 2:8f71b71fce1b 23 /// @param[in] maxV is based on the A/D high reference voltage (default 3.0)
WiredHome 2:8f71b71fce1b 24 ///
WiredHome 2:8f71b71fce1b 25 SignalGenDAC(PinName aout, float minV = 0.0, float maxV = 3.0);
WiredHome 2:8f71b71fce1b 26
WiredHome 2:8f71b71fce1b 27 /// Destructor
WiredHome 2:8f71b71fce1b 28 ///
WiredHome 2:8f71b71fce1b 29 ~SignalGenDAC();
WiredHome 2:8f71b71fce1b 30
WiredHome 2:8f71b71fce1b 31 /// Create the waveform in the private memory buffer that is used to DMA to the DAC
WiredHome 2:8f71b71fce1b 32 ///
WiredHome 2:8f71b71fce1b 33 /// @param[in] mode defines the waveform: Sine, Square, Triangle, Sawtooth, User
WiredHome 2:8f71b71fce1b 34 /// @param[in] frequency defines the desired frequency
WiredHome 2:8f71b71fce1b 35 /// @param[in] dutycycle defined the duty cycle of the waveform to be created. The value
WiredHome 2:8f71b71fce1b 36 /// is range limited to 5 to 95 (representing 5 to 95 %).
WiredHome 2:8f71b71fce1b 37 /// @param[in] voltage is the peak-to-peak voltage, and it range limited to 0 to 3.0.
WiredHome 2:8f71b71fce1b 38 /// @param[in] offset is the offset voltage, and is range limited to 0 to 3.0.
WiredHome 2:8f71b71fce1b 39 ///
WiredHome 2:8f71b71fce1b 40 void PrepareWaveform(SG_Mode mode, float frequency, float dutycycle, float voltage, float offset);
WiredHome 2:8f71b71fce1b 41
WiredHome 2:8f71b71fce1b 42 /// Start the signal, in either a oneshot, or continuous mode.
WiredHome 2:8f71b71fce1b 43 ///
WiredHome 2:8f71b71fce1b 44 /// @param[in] oneShot defaults false, which causes continuous mode.
WiredHome 2:8f71b71fce1b 45 /// When set true, one cycle is produced.
WiredHome 2:8f71b71fce1b 46 ///
WiredHome 2:8f71b71fce1b 47 void Start(bool oneShot = false);
WiredHome 2:8f71b71fce1b 48
WiredHome 2:8f71b71fce1b 49 /// Stop the signal, if it is running.
WiredHome 2:8f71b71fce1b 50 ///
WiredHome 2:8f71b71fce1b 51 void Stop(void);
WiredHome 2:8f71b71fce1b 52
WiredHome 2:8f71b71fce1b 53 /// Determine if the signal is running.
WiredHome 2:8f71b71fce1b 54 ///
WiredHome 2:8f71b71fce1b 55 /// @returns true if the signal is running.
WiredHome 2:8f71b71fce1b 56 ///
WiredHome 2:8f71b71fce1b 57 bool isRunning(void) { return isOn; }
WiredHome 2:8f71b71fce1b 58
WiredHome 2:8f71b71fce1b 59 private:
WiredHome 2:8f71b71fce1b 60 bool isOn; // tracks whether the signal is on or off
WiredHome 2:8f71b71fce1b 61 AnalogOut * aout;
WiredHome 2:8f71b71fce1b 62 float minV; // Based on the A/D hardware
WiredHome 2:8f71b71fce1b 63 float maxV; // Based on the A/D hardware
WiredHome 2:8f71b71fce1b 64 /// range limit a value.
WiredHome 2:8f71b71fce1b 65 float rangelimit(float value, float min, float max);
WiredHome 4:10281ddb673d 66 int numSamples; // private container for number of samples
WiredHome 2:8f71b71fce1b 67 };
WiredHome 2:8f71b71fce1b 68
WiredHome 2:8f71b71fce1b 69 #endif // SIGNALGENDAC_H