Stimulation offset in STG 4002

View previous topic View next topic Go down

Stimulation offset in STG 4002

Post  mrklab on Mon May 29, 2017 9:56 pm

I am using the mscusb.dll to control the STG4002 stimulator from a C++ program. Working from the example code I wrote/copied the lines below to generate a simple sinusoidal stimulation pattern.
The issue were having is that the stimulation does not start at phase zero when we send the Start(1) command (or when we press the sweep button on the stimulator).

For instance, for a 20Hz sinusoid with a 1mA amplitude, the first sample is not 0 Ma, but closer to 1 mA. Note that the full sinusoid does appear to be in memory because with nrRepeats >1 the pattern looks like a sinusoid
(except that it does not start or end at 0 mA).

Can you help?


---
int j,i,nrSamples;
double amp;
double adScale;
uint32 elements= 10;
double dt=20;
uint16* stimData ;
uint16* syncData;
uint64* timeData;
uint32 DACResolution;
STG200x_GetDacResolution(device, &DACResolution);
adScale = (pow(2.0,(double)DACResolution-1.0)-1)/1.6; // current is scaled by this such that max AD value == 1.6mA



if (ontime.size()>1){
errLog << "Version 3 can only do one stimulus at a time" << endl;
}
j=0; // Keeping this for future extensions..
switch ((int) type[j]){
case 1:
// Sine
ClearChannelData(channelNum);
nrSamples = (int) floor((1./frequency[j])/(dt*1e-6));
stimData = (uint16*) malloc(nrSamples*sizeof(uint16));
syncData = (uint16*) malloc(nrSamples*sizeof(uint16));
timeData = (uint64*) malloc(nrSamples*sizeof(uint64));

for(i= 0; i<nrSamples;i++){
amp = amplitude[j]*sin(2*PI*frequency[j]*i*dt*(1e-6))*0.5*adScale;
// calculate sign
stimData[i] = amp >= 0 ? (uint16)amp : (uint16)( (int)abs(amp) + 8192);
timeData[i]= (uint64) dt; // duration in s
syncData[i]= (uint16) 1;
}
STG200x_SendChannelData(device, channelNum, stimData, timeData, nrSamples);
STG200x_SendSyncData(device, 0, syncData, timeData, nrSamples);
uint32 nrTriggers;
STG200x_GetNumberOfTriggerInputs(device, &nrTriggers);
// Setup Trigger
for ( i = 0; i < nrTriggers; i++){
channelMap[i] = 0;
syncoutMap[i] = 0;
repeat[i] = 0;
digoutMap[i] = 0;
autostart[i] = 0;
}

// Define trigger 1 to start this channel and syncout
channelMap[0] = channelNum;
syncoutMap[0] = 1;
repeat[0] = (uint32) ceil(1000*(offtime[j]-ontime[j])*frequency[j]);
STG200x_SetupTrigger(device, elements, channelMap, syncoutMap, digoutMap, autostart, repeat);

free(stimData);
free(syncData);
free(timeData);

mrklab

Posts : 1
Join date : 2017-05-29

View user profile

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum