Skip to content

Commit

Permalink
Updated schematic to show use with a Rheostat instead of a potentiome…
Browse files Browse the repository at this point in the history
…ter.

Fix bug in Teensy Emulate to allow replay of more than once curve.
Added concept of gain to record.
  • Loading branch information
jhester committed Dec 9, 2014
1 parent 09e1857 commit 3814879
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 146 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -19,7 +19,7 @@ For more information on the concept, design, and evaluation of Ekho, checkout th
- [Teensy ADC package installed](https://github.com/pedvide/ADC)
- [GNU Scientific Library (GSL)](http://brewformulas.org/Gsl)
- 2x [Teensy 3.1 Dev Boards](https://www.sparkfun.com/products/12646)
- 1x [MCP413X/415X/423X/425X Digital Potentiometer](https://www.sparkfun.com/products/10613)
- 1x [MCP413X/415X/423X/425X Digital Potentiometer](https://www.sparkfun.com/products/10613). Prefferably the 100k from Digikey: # MCP4152-104E/P-ND
- Breadboard, headers, jumpers, iron will


Expand All @@ -40,7 +40,7 @@ Once the PCB is in hand, you can either:

1. Flash the Teensy 3.1 with the `code/record/micro/EkhoRecord_t3.ino` image using the Arduino application.

2. Connect the Teensy 3.1, the digital potentiometer (synthetic load) and the Analog-front end as shown above.
2. Connect the Teensy 3.1, the digital potentiometer / rheostat (synthetic load) and the Analog-front end as shown above.

3. Connect jumpers JP4 and the left side of JP1 for replay path.

Expand Down
97 changes: 49 additions & 48 deletions code/emulate/micro/EkhoEmulate_t3.ino
Expand Up @@ -3,70 +3,71 @@
#include <RingBuffer.h>
#include <RingBufferDMA.h>

ADC *adc = new ADC(); // adc object
byte response[6];
ADC *adc = new ADC();
uint16_t current_curve[65];
const int statPin=21;
int16_t interpolate_f(int16_t _adc_14_value, uint16_t _shift_bits)
int16_t current=0;
int16_t voltage=0;
unsigned char buf[512];
uint16_t bcount = 0;
uint16_t i = 0;

uint16_t interpolate_f(uint16_t _adc_14_value, uint16_t _shift_bits)
{
int16_t left = _adc_14_value >> _shift_bits;
return current_curve[left] -
uint16_t left = _adc_14_value >> _shift_bits;
return current_curve[left] -
((
(uint32_t)(current_curve[left] - current_curve[left+1]) *
(uint32_t)(_adc_14_value - (left << _shift_bits))
) >> _shift_bits);
};

void setup() {
Serial.begin(115200);
Serial.begin(115200);

pinMode(A3, INPUT);
pinMode(statPin, OUTPUT);

////// ADC1 /////
adc->setAveraging(1, ADC_1); // set number of averages
adc->setResolution(12, ADC_1); // set bits of resolution
adc->setConversionSpeed(ADC_HIGH_SPEED, ADC_1); // change the conversion speed
adc->setSamplingSpeed(ADC_HIGH_SPEED, ADC_1); // change the sampling speed
pinMode(A3, INPUT);
pinMode(statPin, OUTPUT);

// 12-bit DAC
analogWriteResolution(12);

// Let everything settle
delay(1000);
}
////// ADC1 /////
adc->setAveraging(1, ADC_1); // set number of averages
adc->setResolution(12, ADC_1); // set bits of resolution
adc->setConversionSpeed(ADC_HIGH_SPEED, ADC_1); // change the conversion speed
adc->setSamplingSpeed(ADC_HIGH_SPEED, ADC_1); // change the sampling speed

void printLine() {
Serial.print( response[0]);
Serial.print(",");
Serial.print( response[1]);
Serial.print(",");
Serial.print( response[2]);
Serial.print(",");
Serial.println( response[3]);
// 12-bit DAC
analogWriteResolution(12);

// Let everything settle
digitalWrite(statPin, LOW);
delay(2000);
}

uint16_t current=0;
uint16_t voltage=0;
unsigned char buf[512];
uint16_t bcount = 0;
uint16_t i = 0;
void loop() {
digitalWrite(statPin, LOW);
while(Serial.available()) {
buf[bcount++] = Serial.read();
if(bcount > 130) {
for(i=0;i<130;i+=2) {
current_curve[i / 2] = (buf[i] << 8) + buf[i+1];
}
bcount = 0;
break;
}
}
digitalWrite(statPin, HIGH);
voltage = adc->analogRead(A3, ADC_1);
analogWrite(A14, interpolate_f(voltage, 6));
//delayMicroseconds();
// Calculate output value (TODO: dont use float math, use a table)
voltage = adc->analogRead(A3, ADC_1);
// = voltage * (3.3 / 4096) * 4;
double actual_voltage = voltage * 0.00322265;
double actual_voltage_digital = actual_voltage / 0.0019178;
uint16_t avd = (uint16_t)actual_voltage_digital;

// Start reading in a new curve if necessary
while(Serial.available()) {
if(bcount == 0) {
digitalWrite(statPin, HIGH);
}
buf[bcount++] = Serial.read();
if(bcount > 129) {
digitalWrite(statPin, LOW);
for(i=0;i<130;i+=2) {
current_curve[i / 2] = (buf[i] << 8) + buf[i+1];
}
bcount = 0;
break;
}
}

// Write to DAC
analogWrite(A14, interpolate_f(avd, 6));
}


Expand Down

0 comments on commit 3814879

Please sign in to comment.