Skip to content

Commit

Permalink
Merge pull request #26 from OpenBCI/23-synthetic-mode-broken-on-v3-fi…
Browse files Browse the repository at this point in the history
…rmware

Assign square wave values on all synthetic mode updates
  • Loading branch information
philippitts authored Oct 26, 2023
2 parents b29fba8 + f92bf50 commit 76cc3c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
40 changes: 19 additions & 21 deletions OpenBCI_Ganglion_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void OpenBCI_Ganglion::processData() {
wifi.storeByteBufTx(sampleCounter);
}
if (streamSynthetic) {
incrementSyntheticChannelData();
updateSyntheticChannelData();
} else {
updateMCPdata();
if (useAccel){
Expand Down Expand Up @@ -229,22 +229,20 @@ void OpenBCI_Ganglion::initSyntheticData() {
}

void OpenBCI_Ganglion::startRunningSynthetic() {
thatTime = millis();
previousTime = millis();
startRunning();
}

void OpenBCI_Ganglion::incrementSyntheticChannelData() {
thisTime = millis();
if (thisTime - thatTime > syntheticFrequency) {
thatTime = thisTime;
for (int i = 0; i < 4; i++) {
rising[i] = !rising[i];
if (rising[i]) {
channelData[i] = 8000000;
} else {
channelData[i] = -8000000;
}
}
void OpenBCI_Ganglion::updateSyntheticChannelData() {
currentTime = millis();

if (currentTime - previousTime > syntheticFrequency) {
previousTime = currentTime;
syntheticValue = -syntheticValue;
}

for (int i = 0; i < 4; i++) {
channelData[i] = syntheticValue;
}
}

Expand Down Expand Up @@ -411,22 +409,22 @@ void OpenBCI_Ganglion::testImpedance() {
}
else
{
thisTime = micros(); // time critical activities!
if (thisTime - halfPeriodTimer > HALF_PERIOD) {
halfPeriodTimer = thisTime;
currentTime = micros(); // time critical activities!
if (currentTime - halfPeriodTimer > HALF_PERIOD) {
halfPeriodTimer = currentTime;
if (ACrising) {
updateDAC(realZeroPosition - HALF_WAVE);
ACrising = false;
edge = true;
uAsampleTimer = thisTime;
uAsampleTimer = currentTime;
} else {
updateDAC(realZeroPosition + HALF_WAVE);
ACrising = true;
edge = true;
uAsampleTimer = thisTime;
uAsampleTimer = currentTime;
}
}
if (thisTime - uAsampleTimer > UA_SAMPLE_TIME) {
if (currentTime - uAsampleTimer > UA_SAMPLE_TIME) {
if (uAsampleCounter > UA_SAMPLE_LIMIT) {
updateDAC(realZeroPosition);
ACwaveTest = false;
Expand Down Expand Up @@ -477,7 +475,7 @@ void OpenBCI_Ganglion::testImpedance() {
} else {
if(currentCounts < minNegCurrentCounts){ minNegCurrentCounts = currentCounts; }
}
uAsampleTimer = thisTime;
uAsampleTimer = currentTime;
uAsampleCounter++;
}
}
Expand Down
8 changes: 4 additions & 4 deletions OpenBCI_Ganglion_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class OpenBCI_Ganglion {
int changeChannelState_maintainRunningState(int, int);
void initSyntheticData(void);
void startRunningSynthetic(void);
void incrementSyntheticChannelData(void);
void updateSyntheticChannelData(void);
void buildRawPacket(void);
void sendRawPacket(void);
void compressData18(void);
Expand Down Expand Up @@ -198,12 +198,12 @@ class OpenBCI_Ganglion {
unsigned long gain = GAIN_1;
// unsigned long sps = SAMPLE_200;
boolean requestToStartRunning = false;
unsigned long thisTime;
unsigned long thatTime;
unsigned long currentTime;
unsigned long previousTime;
unsigned long thisStampTime;
unsigned long thatStampTime;
int timeDifference;
boolean rising[4] = {true,true,true,true};
int syntheticValue = 8000000;
unsigned long regVal;


Expand Down

0 comments on commit 76cc3c1

Please sign in to comment.