Signal Generator

Dependencies:   IniManager RA8875 Watchdog mbed-rtos mbed

Fork of speaker_demo_Analog by jim hamblen

SignalGenDAC.h

Committer:
WiredHome
Date:
2017-01-16
Revision:
4:10281ddb673d
Parent:
2:8f71b71fce1b
Child:
5:49dd0c647a40

File content as of revision 4:10281ddb673d:


//
// Derived from AN10917: Memory to DAC data transfers using the LPC1700's DMA
//
#ifndef SIGNALGENDAC_H
#define SIGNALGENDAC_H

#include "mbed.h"

#include "SignalGenDefs.h"       // access the waveform mode data type


#define SIGNAL_MEM_ENTRIES 2048     // size of the DAC buffer

class SignalGenDAC {

public:

    /// Constructor, which is used to define the hardware
    ///
    /// @param[in] aout is the analog output pin
    /// @param[in] minV is based on the A/D low reference voltage (default 0.0)
    /// @param[in] maxV is based on the A/D high reference voltage (default 3.0)
    ///
    SignalGenDAC(PinName aout, float minV = 0.0, float maxV = 3.0);

    /// Destructor
    ///
    ~SignalGenDAC();

    /// Create the waveform in the private memory buffer that is used to DMA to the DAC
    ///
    /// @param[in] mode defines the waveform: Sine, Square, Triangle, Sawtooth, User
    /// @param[in] frequency defines the desired frequency
    /// @param[in] dutycycle defined the duty cycle of the waveform to be created. The value
    ///             is range limited to 5 to 95 (representing 5 to 95 %).
    /// @param[in] voltage is the peak-to-peak voltage, and it range limited to 0 to 3.0.
    /// @param[in] offset is the offset voltage, and is range limited to 0 to 3.0.
    ///
    void PrepareWaveform(SG_Mode mode, float frequency, float dutycycle, float voltage, float offset);

    /// Start the signal, in either a oneshot, or continuous mode.
    ///
    /// @param[in] oneShot defaults false, which causes continuous mode. 
    ///             When set true, one cycle is produced.
    ///
    void Start(bool oneShot = false);

    /// Stop the signal, if it is running.
    ///
    void Stop(void);

    /// Determine if the signal is running.
    ///
    /// @returns true if the signal is running.
    ///
    bool isRunning(void) { return isOn; }

private:
    bool isOn;              // tracks whether the signal is on or off
    AnalogOut * aout;
    float minV;             // Based on the A/D hardware
    float maxV;             // Based on the A/D hardware
    /// range limit a value.
    float rangelimit(float value, float min, float max);
    int numSamples;         // private container for number of samples
};

#endif // SIGNALGENDAC_H