Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perimeterV2 10bits analog read #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions code/tests/perimeterV2/adcman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int16_t ADCMax[CHANNELS]; // ADC max sample value (ADC-ADC7)
int16_t ADCAvg[CHANNELS]; // ADC avg sample value (ADC-ADC7)
volatile boolean captureComplete[CHANNELS]; // ADC buffer filled?
boolean autoCalibrate[CHANNELS]; // do auto-calibrate? (ADC0-ADC7)
int16_t *sample[CHANNELS]; // ADC one sample (ADC0-ADC7) - 10 bit unsigned
ADCManager ADCMan;


Expand All @@ -70,6 +70,10 @@ ADCManager::ADCManager(){
ADCAvg[i] = 0;
}
capturedChannels = 0;
// NOTE: when choosing a higher perimeter sample rate (38 kHz) and using odometry interrupts,
// the Arduino Mega cannot handle all ADC interrupts anymore - the result will be a 'noisy'
// perimeter filter output (mag value) which disappears when disabling odometry interrupts.
// SOLUTION: allow odometry interrupt handler nesting (see odometry interrupt function)
//sampleRate = SRATE_19231;
sampleRate = SRATE_38462;
//sampleRate = SRATE_9615;
Expand Down Expand Up @@ -98,6 +102,7 @@ void ADCManager::setCapture(byte pin, byte samplecount, boolean autoCalibrateOfs
int ch = pin-A0;
captureSize[ch] = samplecount;
capture[ch] = new int8_t[samplecount];
sample[ch] = new int16_t[samplecount];
autoCalibrate[ch] = autoCalibrateOfs;
}

Expand Down Expand Up @@ -221,7 +226,8 @@ void ADC_Handler(void){
return;
}
value -= ofs[channel];
capture[channel][position] = min(SCHAR_MAX, max(SCHAR_MIN, value / 4)); // convert to signed (zero = ADC/2)
capture[channel][position] = min(SCHAR_MAX, max(SCHAR_MIN, value / 4)); // convert to signed (zero = ADC/2)
sample[channel][position] = value;
position++;
}

Expand Down Expand Up @@ -291,7 +297,7 @@ int ADCManager::read(byte pin){
int ch = pin-A0;
captureComplete[ch]=false;
if (captureSize[ch] == 0) return 0;
else return capture[ch][0];
else return sample[ch][(captureSize[ch]-1)];
}


Expand Down