Skip to main content

fixedfrequencydac.stop(flag)

Stops the fixed-frequency DAC

Availability

Device
Not available on the imp005

Parameters

Name Type Description
flag Constant An optional processing flag, SYNC

Returns

Nothing

Description

Call this method to stop the fixed-frequency DAC from processing any more data. It should also be called if you intend to reconfigure a pin that has already configured to use the fixed-frequency DAC, even if fixedfrequencydac.start() has not yet been called. Call fixedfrequencydac.stop() before calling pin.configure() on the chosen pin.

The fixed-frequency DAC’s data-consumed callback, which you have already registered using fixedfrequencydac.configure(), can be called before the final sample has played out. Passing the SYNC flag when calling fixedfrequencydac.stop() directly from the final data-consumed callback will cause it to block until the final sample has played out.

To understand when using SYNC would be useful, consider an application that uses the fixed-frequency DAC as a signal generator with a 1Hz sample rate. When the final sample has been written to the DAC, the data-consumed callback will be executed, but this happens at the start of that sample’s one-second lifetime, not at the end. So if fixedfrequencydac.stop() is called at that moment, the final sample will be ‘live’ for a tiny fraction of a second, not the full second intended. Calling

fixedfrequencydac.stop(SYNC);

will instead cause the final sample to play for its full second before the DAC is turned off.

Example Code

Output at 0.5kHz from pin 5 on an imp001 or imp002 for 40 seconds. By way of illustration, this code generates a sinusoidal output with an amplitude that also varies sinusoidally. This example recycles the buffers and they are added back in the callback.