Skip to content

Commit

Permalink
test remove spi individual transaction handling
Browse files Browse the repository at this point in the history
  • Loading branch information
markzakharyan committed Oct 12, 2024
1 parent f2d2adf commit 5a6b838
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 89 deletions.
28 changes: 0 additions & 28 deletions m4/src/Peripherals/ADC/ADCBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,19 @@ class ADCBoard {
byte data[2];
data[0] = READ | ADDR_ADCSTATUS;

commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 2);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();
return data[1];
}

void channelSetup(int adc_channel, uint8_t flags) {
byte data[2];
data[0] = WRITE | ADDR_CHANNELSETUP(adc_channel);
data[1] = flags;
commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 2);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();
}

// tells the ADC to start a single conversion on the passed channel
Expand All @@ -140,11 +136,9 @@ class ADCBoard {
data[0] = WRITE | ADDR_MODE(adc_channel);
// setup mode register
data[1] = SINGLE_CONV_MODE;
commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 2);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();

// data is ready when _rdy goes low
}
Expand All @@ -162,11 +156,9 @@ class ADCBoard {
data_array[3] = CONT_CONV_MODE;

// send off command
commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data_array, 4);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();

// data is ready when _rdy goes low
}
Expand All @@ -179,22 +171,18 @@ class ADCBoard {
data[0] = WRITE | ADDR_CHANNELCONVERSIONTIME(adc_channel);
data[1] = send;

commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 2);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();
}

uint32_t getConversionData(int adc_channel) {
byte data[4];
data[0] = READ | ADDR_CHANNELDATA(adc_channel);

commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 4);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();

uint32_t upper = data[1];
uint32_t lower = data[2];
Expand Down Expand Up @@ -246,11 +234,9 @@ class ADCBoard {
byte data[2];
data[0] = WRITE | ADDR_MODE(adc_channel);
data[1] = IDLE_MODE;
commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 2);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();
}

bool isChannelActive(int adc_channel) {
Expand All @@ -259,7 +245,6 @@ class ADCBoard {
}

void reset() {
commsController.beginSingleTransaction();
digitalWrite(reset_pin, HIGH);
digitalWrite(reset_pin, LOW);
delay(5);
Expand All @@ -277,18 +262,15 @@ class ADCBoard {
digitalWrite(cs_pin, LOW);
commsController.transfer(0);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();
for (int i = 0; i < NUM_CHANNELS_PER_ADC_BOARD; i++) {
idleMode(i);
}
}

uint8_t talkADC(byte command) {
commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
uint8_t comm = commsController.transfer(command);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();
return comm;
}

Expand Down Expand Up @@ -318,11 +300,9 @@ class ADCBoard {
data[0] = WRITE | ADDR_CHANNELCONVERSIONTIME(channel);
data[1] = send;

commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 2);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();

delayMicroseconds(100);

Expand All @@ -338,11 +318,9 @@ class ADCBoard {
float getConversionTime(int channel, bool moreThanOneChannelActive) {
byte data[2];
data[0] = READ | ADDR_CHANNELCONVERSIONTIME(channel);
commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 2);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();

return calculateConversionTime(data[1], moreThanOneChannelActive);
}
Expand Down Expand Up @@ -398,35 +376,29 @@ class ADCBoard {
byte data[2];
data[0] = WRITE | ADDR_MODE(0); // channel is zero but this is system-wide
data[1] = ZERO_SCALE_SELF_CAL_MODE;
commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 2);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();
waitDataReady();
}

void zeroScaleChannelSystemSelfCalibration(int channel) {
byte data[2];
data[0] = WRITE | ADDR_MODE(channel);
data[1] = CH_ZERO_SCALE_SYS_CAL_MODE;
commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 2);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();
waitDataReady();
}

void fullScaleChannelSystemSelfCalibration(int channel) {
byte data[2];
data[0] = WRITE | ADDR_MODE(channel);
data[1] = CH_FULL_SCALE_SYS_CAL_MODE;
commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 2);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();
waitDataReady();
}
};
8 changes: 0 additions & 8 deletions m4/src/Peripherals/DAC/DACChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ class DACChannel {
byte bytesToSend[3] = {
32, 0,
2}; // Write to control register; Reserved byte; Unclamp DAC from GND
commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(bytesToSend, 3);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();
setVoltage(0.0);

// char offsetKey[14];
Expand Down Expand Up @@ -70,13 +68,11 @@ class DACChannel {

byte bytesToSend[3] = {b1, b2, b3};

commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(bytesToSend,
3); // send command byte to DAC; MS data bits,
// DAC2; LS 8 data bits, DAC2
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();

digitalWrite(ldac, LOW);
digitalWrite(ldac, HIGH);
Expand Down Expand Up @@ -135,13 +131,11 @@ class DACChannel {

byte bytesToSend[3] = {b1, b2, b3};

commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(bytesToSend,
3); // send command byte to DAC; MS data bits,
// DAC2; LS 8 data bits, DAC2
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();

digitalWrite(ldac, LOW);

Expand All @@ -153,15 +147,13 @@ class DACChannel {
float getVoltage() {
byte bytesToSend[3] = {144, 0, 0};
byte data[3];
commsController.beginSingleTransaction();
digitalWrite(cs_pin, LOW);
commsController.transfer(bytesToSend, 3);
digitalWrite(cs_pin, HIGH);
delayMicroseconds(2);
digitalWrite(cs_pin, LOW);
commsController.transfer(data, 3);
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();

float voltage = threeByteToVoltage(data[0], data[1], data[2]);
return gain_error * (voltage + offset_error);
Expand Down
12 changes: 0 additions & 12 deletions m4/src/Peripherals/God.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class God {

while (x < saved_data_size && !getStopFlag()) {
if (TimingUtil::adcFlag) {
ADCBoard::commsController.beginTransaction();
if (steps <= 1) {
for (int i = 0; i < numAdcChannels; i++) {
ADCController::getVoltageDataNoTransaction(adcChannels[i]);
Expand All @@ -123,11 +122,9 @@ class God {
delete[] packets;
x++;
}
ADCBoard::commsController.endTransaction();
TimingUtil::adcFlag = false;
}
if (TimingUtil::dacFlag && steps < numSteps + 1) {
DACChannel::commsController.beginTransaction();
if (steps == 0) {
for (int i = 0; i < numDacChannels; i++) {
DACController::setVoltageNoTransactionNoLdac(dacChannels[i],
Expand All @@ -141,7 +138,6 @@ class God {
}
}
DACController::toggleLdac();
DACChannel::commsController.endTransaction();
steps++;
TimingUtil::dacFlag = false;
}
Expand Down Expand Up @@ -264,7 +260,6 @@ class God {
}
while (x < numSteps && !getStopFlag()) {
if (TimingUtil::adcFlag) {
ADCBoard::commsController.beginTransaction();
if (steps <= 1) {
for (int i = 0; i < numAdcChannels; i++) {
for (int j = 0; j < numAdcAverages; j++) {
Expand All @@ -286,11 +281,9 @@ class God {
delete[] packets;
x++;
}
ADCBoard::commsController.endTransaction();
TimingUtil::adcFlag = false;
}
if (TimingUtil::dacFlag && steps < numSteps + 1) {
DACChannel::commsController.beginTransaction();
if (steps == 0) {
for (int i = 0; i < numDacChannels; i++) {
DACController::setVoltageNoTransactionNoLdac(dacChannels[i],
Expand All @@ -304,7 +297,6 @@ class God {
}
}
DACController::toggleLdac();
DACChannel::commsController.endTransaction();
steps++;
TimingUtil::dacFlag = false;
}
Expand Down Expand Up @@ -428,7 +420,6 @@ class God {

while (x < total_data_size && !getStopFlag()) {
if (TimingUtil::adcFlag && x < (steps-1) * numAdcMeasuresPerDacStep) {
ADCBoard::commsController.beginTransaction();
if (steps <= 1) {
for (int i = 0; i < numAdcChannels; i++) {
ADCController::getVoltageDataNoTransaction(adcChannels[i]);
Expand All @@ -447,11 +438,9 @@ class God {
}
}
adcGetsSinceLastDacSet++;
ADCBoard::commsController.endTransaction();
TimingUtil::adcFlag = false;
}
if (TimingUtil::dacFlag && steps < totalSteps) {
DACChannel::commsController.beginTransaction();
if (steps == 0) {
for (int i = 0; i < numDacChannels; i++) {
DACController::setVoltageNoTransactionNoLdac(dacChannels[i],
Expand Down Expand Up @@ -480,7 +469,6 @@ class God {
}
}
DACController::toggleLdac();
DACChannel::commsController.endTransaction();
steps++;
adcGetsSinceLastDacSet = 0;
TimingUtil::dacFlag = false;
Expand Down
12 changes: 0 additions & 12 deletions m4/src/Peripherals/God2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,12 @@ class God2D {

for (int slowStep = 0; slowStep < numStepsSlow && !getStopFlag();
++slowStep) {
DACChannel::commsController.beginTransaction();
for (int i = 0; i < numSlowDacChannels; ++i) {
DACController::setVoltageNoTransactionNoLdac(slowDacChannels[i],
previousVoltageSet[i]);
previousVoltageSet[i] += voltageStepSize[i];
}
DACController::toggleLdac();
DACChannel::commsController.endTransaction();

bool isReverse = false;
if (retrace) {
Expand Down Expand Up @@ -240,7 +238,6 @@ class God2D {

while (x < saved_data_size && !getStopFlag()) {
if (TimingUtil::adcFlag) {
ADCBoard::commsController.beginTransaction();
if (steps <= 1) {
for (int i = 0; i < numAdcChannels; i++) {
ADCController::getVoltageDataNoTransaction(adcChannels[i]);
Expand All @@ -256,11 +253,9 @@ class God2D {
delete[] packets;
x++;
}
ADCBoard::commsController.endTransaction();
TimingUtil::adcFlag = false;
}
if (TimingUtil::dacFlag && steps < numSteps + 1) {
DACChannel::commsController.beginTransaction();
if (steps == 0) {
for (int i = 0; i < numDacChannels; i++) {
DACController::setVoltageNoTransactionNoLdac(dacChannels[i],
Expand All @@ -274,7 +269,6 @@ class God2D {
}
}
DACController::toggleLdac();
DACChannel::commsController.endTransaction();
steps++;
TimingUtil::dacFlag = false;
}
Expand Down Expand Up @@ -424,14 +418,12 @@ class God2D {

for (int slowStep = 0; slowStep < numStepsSlow && !getStopFlag();
++slowStep) {
DACChannel::commsController.beginTransaction();
for (int i = 0; i < numSlowDacChannels; ++i) {
DACController::setVoltageNoTransactionNoLdac(slowDacChannels[i],
previousVoltageSet[i]);
previousVoltageSet[i] += voltageStepSize[i];
}
DACController::toggleLdac();
DACChannel::commsController.endTransaction();

bool isReverse = false;
if (retrace) {
Expand Down Expand Up @@ -522,7 +514,6 @@ class God2D {

while (x < numSteps && !getStopFlag()) {
if (TimingUtil::adcFlag) {
ADCBoard::commsController.beginTransaction();
if (steps <= 1) {
for (int i = 0; i < numAdcChannels; i++) {
for (int j = 0; j < numAdcAverages; j++) {
Expand All @@ -544,11 +535,9 @@ class God2D {
delete[] packets;
x++;
}
ADCBoard::commsController.endTransaction();
TimingUtil::adcFlag = false;
}
if (TimingUtil::dacFlag && steps < numSteps + 1) {
DACChannel::commsController.beginTransaction();
if (steps == 0) {
for (int i = 0; i < numDacChannels; i++) {
DACController::setVoltageNoTransactionNoLdac(dacChannels[i],
Expand All @@ -562,7 +551,6 @@ class God2D {
}
}
DACController::toggleLdac();
DACChannel::commsController.endTransaction();
steps++;
TimingUtil::dacFlag = false;
}
Expand Down
Loading

0 comments on commit 5a6b838

Please sign in to comment.