Writes data to DSP task.
mdaqDSPWrite(index, data) mdaqDSPWrite(linkID, index, data)
This function writes data to an application running on MicroDAQ DSP core. The function must be used with DSP application generated from XCos model containing 'MEM Read' block. Data written by the function is read by 'MEM Read' block during every DSP application 'step'. The 'index' argument shall be equal to 'Start index' 'MEM Read' block parameter. Depending on 'MEM Read' block 'Mode' parameter, function can be used to write initial data. In case of writing initial data, the function shall be called before starting DSP application. This functionality allows changing DSP application parameters during its execution in Ext and Standalone mode.
linkID: Valid connection link ID (optional)
index: Memory index on which data will be written from
data: Data to be written
This example shows how to modify and read DSP application data during its execution. The example uses Xcos model with 'MEM Read' and SIGNAL blocks and a script which modifies and reads DSP data with mdaqDSPWrite() and mdaqDSPRead() functions. The mdaqDSPBuild() function is used to build executable from existing Xcos model. When built, resulting binary file path is passed as a first argument to mdaqDSPInit() function which initializes DSP and configures the model frequency and its execution duration. After calling mdaqDSPStart() DSP application is started on MicroDAQ DSP.
When DSP application is started 'MEM Read' block reads data from memory index 1 every model step. By calling mdaqDSPWrite() function we change the value of number located at index 1. This way we can change the DSP application parameter during its execution. Apart from reading our model performs multiplication by 2 and after that operation it passes value to SIGNAL block which sends data to the host PC. This modified value can be read by mdaqDSPRead() function.
Xcos model used in examples below:
Example 1: Using standard DSP API
Freq = 10; // Hz Druration = 5; // seconds signalID = 1; memIndex = 1; disp("Building DSP model..."); mdaqDSPBuild(mdaqToolboxPath() + filesep() + "examples" + filesep() +"dsp_rw_demo.zcos"); disp("Starting DSP model..."); mdaqDSPInit('dsp_rw_demo_scig\dsp_rw_demo.out', Freq, Druration); mdaqDSPStart(); disp("Passing value 2 to DSP model..."); mdaqDSPWrite(memIndex, 2); disp("Reading data from DSP model..."); data1 = mdaqDSPRead(signalID, 1, 10, -1); disp(data1); disp("Passing value 4 to DSP model..."); mdaqDSPWrite(memIndex, 4); disp("Reading data from DSP model..."); data2 = mdaqDSPRead(signalID, 1, 10, -1); disp(data2); disp("Waiting for the end of execution..."); mdaqDSPWait(-1); disp("End of execution DSP model"); | ![]() | ![]() |
Example 2: Using DSP task API
Freq = 10; // Hz Druration = 5; // seconds signalID = 1; memIndex = 1; // Create DSP task dsp = mdaqDSPTask(); disp("Building DSP model..."); mdaqDSPBuild(mdaqToolboxPath() + filesep() + "examples" + filesep() +"dsp_rw_demo.zcos"); disp("Starting DSP model..."); dsp.init('dsp_rw_demo_scig\dsp_rw_demo.out', Freq, Druration); dsp.start(); disp("Passing value 2 to DSP model..."); dsp.write(memIndex, 2); disp("Reading data from DSP model..."); data1 = dsp.read(signalID, 1, 10, -1); disp(data1); disp("Passing value 4 to DSP model..."); dsp.write(memIndex, 4); disp("Reading data from DSP model..."); data2 = dsp.read(signalID, 1, 10, -1); disp(data2); disp("Waiting for the end of execution..."); dsp.waitUntilDone(-1); disp("End of execution DSP model"); | ![]() | ![]() |