Jacob Isakson
/
AFG_project
jisakson3
Embed:
(wiki syntax)
Show/hide line numbers
SignalGenDAC.h
00001 // 00002 // Signal Generator DAC Driver 00003 // 00004 // Derived from AN10917: Memory to DAC data transfers using the LPC1700's DMA 00005 // 00006 // 00007 #ifndef SIGNALGENDAC_H 00008 #define SIGNALGENDAC_H 00009 00010 #include "mbed.h" 00011 00012 #include "SignalGenDefs.h" // access the waveform mode data type 00013 00014 00015 #define SIGNAL_MEM_ENTRIES 2048 // size of the DAC buffer 00016 00017 /// The Signal Generator DAC Driver 00018 /// 00019 /// This class provides the interface to first configure the DAC hardware characteristics, 00020 /// and then to define and control the DAC output. 00021 /// 00022 /// A choice of waveforms is available (Sine, Square, Triangle, Sawtooth, and User Defined. 00023 /// 00024 /// @todo add support for User Defined waveform. 00025 /// 00026 /// @code 00027 /// SignalGenDAC g_signal; // defaults to LPC1768 mbed module (p18 and 3.3v) 00028 /// 00029 /// g_signal.PrepareWaveform(SG_SINE, 1000, 50, 2.2, 1.5); 00030 /// g_signal.Start(); 00031 /// wait_ms(1000); 00032 /// g_signal.Stop(); 00033 /// @endcode 00034 /// 00035 class SignalGenDAC { 00036 00037 public: 00038 00039 /// Constructor, which is used to define the hardware 00040 /// 00041 /// The default parameters are based on the mbed LPC1768 micro, which has 00042 /// AnalogOut on p18 and uses a 3.3v supply for the A/D reference. 00043 /// 00044 /// @param[in] aout is the analog output pin 00045 /// @param[in] minV is based on the A/D low reference voltage (default 0.0) 00046 /// @param[in] maxV is based on the A/D high reference voltage (default 3.3) 00047 /// 00048 SignalGenDAC(PinName aout = p18, float minV = 0.0, float maxV = 3.3); 00049 00050 /// Destructor 00051 /// 00052 ~SignalGenDAC(); 00053 00054 /// Create the waveform in the private memory buffer that is used to DMA to the DAC 00055 /// 00056 /// @param[in] mode defines the waveform: Sine, Square, Triangle, Sawtooth, User 00057 /// @param[in] frequency defines the desired frequency 00058 /// @param[in] dutycycle defined the duty cycle of the waveform to be created. The value 00059 /// is range limited to 5 to 95 (representing 5 to 95 %). 00060 /// @param[in] voltage is the peak-to-peak voltage, and it range limited to 0 to 3.0. 00061 /// @param[in] offset is the offset voltage, and is range limited to 0 to 3.0. 00062 /// 00063 void PrepareWaveform(SG_Waveform mode, float frequency, float dutycycle, float voltage, float offset); 00064 00065 /// Start the signal, in either a oneshot, or continuous mode. 00066 /// 00067 /// @param[in] oneShot defaults false, which causes continuous mode. 00068 /// When set true, one cycle is produced. 00069 /// 00070 void Start(bool oneShot = false); 00071 00072 /// Stop the signal, if it is running. 00073 /// 00074 void Stop(void); 00075 00076 /// Determine if the signal is running. 00077 /// 00078 /// @returns true if the signal is running. 00079 /// 00080 bool isRunning(void) { return isOn; } 00081 00082 private: 00083 bool isOn; // tracks whether the signal is on or off 00084 AnalogOut * aout; 00085 float frequency; // signal parameters 00086 float dutycycle; 00087 float voltage; 00088 float offset; 00089 float minV; // Based on the A/D hardware 00090 float maxV; // Based on the A/D hardware 00091 /// range limit a value. 00092 float rangelimit(float value, float min, float max); 00093 int numSamples; // private container for number of samples 00094 }; 00095 00096 #endif // SIGNALGENDAC_H
Generated on Mon Dec 5 2022 02:02:14 by 1.7.2