Thursday 30 June 2011

Arduino - Triggered Function Generator

This is a triggered function generator / pulse generator for the Arduino Mega using Arduino 022.

The sketch is too long to present as a snippet, but it's downloadable from here.

Features


  • Configurable via commands from the Arduino IDE Serial Monitor.
  • Triggered by external digital input.
  • Output sequence includes an optional pulse of configurable duration (in ms) starting at lag 0.
  • Main output sequence has configurable start time and duration (in ms).
  • Includes a configurable internal test source which can be looped to the trigger input.
  • Configuration can be saved to EEPROM.
  • Automatically loads configuration from EEPROM at startup.
  • At the moment this design outputs a delayed pulse, but it can easily be extended to output any arbitrary digital waveform (function), i.e. to be a digital AWG (Arbitrary Waveform Generator).
  • With the addition of provision for analog output, either using PWM functionality or an external DAC, it could be easily extended to make an analog AWG.

Commands


The commands currently implemented are:

    BEEP ON/OFF       Switch beep on/off (stimulus input)
    HELP              Display help information (this command)
    INTMODE (string)  Set the interrupt mode
                      (options are LOW / CHANGE / RISING / FALLING)
    LAG (int)         Set the lag time (ms)
    MARKER (int)      Set the marker length (ms)
    OFF               Disable the output
    ON                Enable the output
    OUTPUT (int)      Set the output length (ms)
    PULSE (int)       Set the pulse length (ms)
    RESET             Reset to default values
    RESTORE           Restore configuration from EEPROM
    SAMPLE (int)      Set the sample frequency (KHz)
    SAVE              Save configuration to EEPROM
    STATUS            Display status information
    TEST (int)        Set the test stimulus interval on pin 12 (ms)

(int) signifies an integer parameter, separated by a space.
(string) signifies a string parameter, separated by a space.

Performance


Some screenshots of example output between 50 and 1000 ms lag:


50 ms lag


100 ms lag


200 ms lag


500 ms lag


1000 ms lag

The upper trace is the stimulus input, the positive edge of which triggers both the function generator and the oscilloscope.

Description


If anyone's interested, I can add some annotated snippets here describing the code.

Acknowledgements


Interrupt usage and tips in speaker_pcm by Michael Smith (michael@hurts.ca).

No comments:

Post a Comment