Skip to content

Commit

Permalink
Examples: Add reset() to examples, before calibrating the ADC and DAC.
Browse files Browse the repository at this point in the history
Some examples don't handle all the possible attributes (oversampling_ratio).
If the analogIn or analogOut object are not reset before using, the
result might be wrong.

Signed-off-by: Alexandra Trifan <[email protected]>
  • Loading branch information
AlexandraTrifan committed Sep 6, 2021
1 parent c082472 commit c2eecf5
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 36 deletions.
9 changes: 7 additions & 2 deletions bindings/python/examples/analog.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@
print("Connection Error: No ADALM2000 device available/connected to your PC.")
exit(1)

ctx.calibrateADC()
ctx.calibrateDAC()

ain=ctx.getAnalogIn()
aout=ctx.getAnalogOut()
trig=ain.getTrigger()

# Prevent bad initial config for ADC and DAC
ain.reset()
aout.reset()

ctx.calibrateADC()
ctx.calibrateDAC()

ain.enableChannel(0,True)
ain.enableChannel(1,True)
ain.setSampleRate(100000)
Expand Down
10 changes: 7 additions & 3 deletions bindings/python/examples/analog_raw_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
print("Connection Error: No ADALM2000 device available/connected to your PC.")
exit(1)

ctx.calibrateADC()
ctx.calibrateDAC()

ain=ctx.getAnalogIn()
aout=ctx.getAnalogOut()
trig=ain.getTrigger()

# Prevent bad initial config for ADC and DAC
ain.reset()
aout.reset()

ctx.calibrateADC()
ctx.calibrateDAC()

ain.enableChannel(0,True)
ain.enableChannel(1,True)
ain.setSampleRate(100000)
Expand Down
28 changes: 19 additions & 9 deletions bindings/python/examples/analogin_sync_2m2ks.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,31 @@ def generate_clock_signal():
print("Connection Error: No second ADALM2000 device available/connected to your PC.")
exit(1)

ctx.calibrateADC()
ctx.calibrateDAC()
ctx2.calibrateADC()
ctx2.calibrateDAC()

# Configure 1st context
ain = ctx.getAnalogIn()
aout = ctx.getAnalogOut()
dig = ctx.getDigital()
trig = ain.getTrigger()

# Prevent bad initial config for ADC and DAC
ain.reset()
aout.reset()
dig.reset()

# Configure 2nd context
ain2 = ctx2.getAnalogIn()
dig2 = ctx2.getDigital()
trig2 = dig2.getTrigger()

# Prevent bad initial config for ADC and DAC
ain2.reset()
dig2.reset()

ctx.calibrateADC()
ctx.calibrateDAC()
ctx2.calibrateADC()
ctx2.calibrateDAC()

if trig.hasExternalTriggerOut():
trig.setAnalogExternalOutSelect(libm2k.SELECT_ANALOG_IN) # Forward Analog trigger on TO pin

Expand All @@ -94,10 +108,6 @@ def generate_clock_signal():
dig.enableChannel(DIGITAL_CH, True)
dig.setValueRaw(DIGITAL_CH, libm2k.LOW)

# Configure 2nd context
ain2 = ctx2.getAnalogIn()
dig2 = ctx2.getDigital()
trig2 = dig2.getTrigger()
ain2.enableChannel(0, True)
ain2.enableChannel(1, True)
ain2.setSampleRate(sampling_frequency_in)
Expand Down
11 changes: 8 additions & 3 deletions bindings/python/examples/audio_flip.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@
print("Connection Error: No ADALM2000 device available/connected to your PC.")
exit(1)

ctx.calibrateADC()
ctx.calibrateDAC()

ain = ctx.getAnalogIn()
aout = ctx.getAnalogOut()
trig = ain.getTrigger()
ps = ctx.getPowerSupply()

# Prevent bad initial config for ADC and DAC
ain.reset()
aout.reset()
ps.reset()

ctx.calibrateADC()
ctx.calibrateDAC()

ps.enableChannel(0, True) # Consider using for microphone power,
ps.pushChannel(0, 4.0) # unfortunately DC blocking cap takes forever to charge
print("waiting 1 second for mic to settle...")
Expand Down
1 change: 1 addition & 0 deletions bindings/python/examples/digital.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
exit(1)

dig=ctx.getDigital()
dig.reset()

dig.setSampleRateIn(10000)
dig.setSampleRateOut(10000)
Expand Down
2 changes: 2 additions & 0 deletions bindings/python/examples/digitalin_sync_2m2ks.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def generate_clock_signal(digital, channel, sampling_frequency):

# Configure 1st M2K context
dig = ctx.getDigital()
dig.reset()
dig.setDirection(DIGITAL_CH_TRIG, libm2k.DIO_OUTPUT) # DIO pin which the digital interface
dig.enableChannel(DIGITAL_CH_TRIG, False)
dig.setValueRaw(DIGITAL_CH_TRIG, libm2k.LOW)
Expand All @@ -92,6 +93,7 @@ def generate_clock_signal(digital, channel, sampling_frequency):

# Configure 2nd M2K context
dig2 = ctx2.getDigital()
dig2.reset()
dig2.setDirection(DIGITAL_CH_TRIG, libm2k.DIO_INPUT) # DIO pin on which the trigger signal is read
dig2.enableChannel(DIGITAL_CH_TRIG, False)
dig2.setDirection(DIGITAL_CH_READ, libm2k.DIO_INPUT) # DIO pin on which the clock signal is read
Expand Down
9 changes: 7 additions & 2 deletions bindings/python/examples/external_clocksource.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ def generate_clock_signal(number_of_samples):
# Context setup

ctx = libm2k.m2kOpen()
ctx.calibrateDAC()
ctx.calibrateADC()
aout = ctx.getAnalogOut()
dig = ctx.getDigital()

# Prevent bad initial config
dig.reset()
aout.reset()

ctx.calibrateDAC()
ctx.calibrateADC()

# AnalogOut setup

aout.setCyclic(True)
Expand Down
8 changes: 6 additions & 2 deletions bindings/python/examples/mixed_signal_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,16 @@ def main():
print("Mixed Signal not available")
exit(1)

context.calibrateDAC()

analog_in = context.getAnalogIn()
digital = context.getDigital()
trigger = analog_in.getTrigger()

# Prevent bad initial config
analog_in.reset()
digital.reset()

context.calibrateDAC()

analog_in.enableChannel(libm2k.CHANNEL_1, True)
analog_in.enableChannel(libm2k.CHANNEL_2, True)

Expand Down
1 change: 1 addition & 0 deletions bindings/python/examples/powersupply.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

ctx.calibrateADC()
ps=ctx.getPowerSupply()
ps.reset()
ps.enableChannel(0,True)
ps.pushChannel(0,1.7)
ain=ctx.getAnalogIn()
Expand Down
6 changes: 5 additions & 1 deletion bindings/python/examples/voltmeter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
print("Connection Error: No ADALM2000 device available/connected to your PC.")
exit(1)

ctx.calibrateADC()
ain=ctx.getAnalogIn()

# Prevent bad initial config
ain.reset()

ctx.calibrateADC()
ain.enableChannel(channel,True)
print(ain.getVoltage()[channel])

Expand Down
10 changes: 7 additions & 3 deletions examples/analog/analog_in_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ int main(int argc, char* argv[])
return 1;
}

ctx->calibrateADC();
ctx->calibrateDAC();

M2kAnalogIn *ain = ctx->getAnalogIn();
M2kAnalogOut *aout = ctx->getAnalogOut();
#ifdef TRIGGERING
M2kHardwareTrigger *trig = ain->getTrigger();
#endif

// Prevent bad initial config
ain->reset();
aout->reset();

ctx->calibrateADC();
ctx->calibrateDAC();

// Setup analog in
ain->enableChannel(0, true);
ain->enableChannel(1, true);
Expand Down
10 changes: 7 additions & 3 deletions examples/analog/stream_test_adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,17 @@ int main(int argc, char **argv)
return 1;
}

ctx->calibrateADC();
ctx->calibrateDAC();

M2kAnalogIn *ain = ctx->getAnalogIn();
M2kAnalogOut *aout = ctx->getAnalogOut();
M2kHardwareTrigger *trig = ain->getTrigger();

// Prevent bad initial config
ain->reset();
aout->reset();

ctx->calibrateADC();
ctx->calibrateDAC();

/* Always use MAX_SR_IN, adjust the samplerate using oversampling_ratio (sr_divider) */
ain->setSampleRate(MAX_SAMPLE_RATE_IN);
aout->setSampleRate(0, MAX_SAMPLE_RATE_OUT);
Expand Down
7 changes: 5 additions & 2 deletions examples/analog/stream_test_dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,13 @@ int main(int argc, char **argv)
return 1;
}

ctx->calibrateDAC();

M2kAnalogOut *aout = ctx->getAnalogOut();

// Prevent bad initial config
aout->reset();

ctx->calibrateDAC();

aout->setSampleRate(0, MAX_SAMPLE_RATE_OUT);
aout->setSampleRate(1, MAX_SAMPLE_RATE_OUT);

Expand Down
7 changes: 5 additions & 2 deletions examples/analog/streaming_one_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ int main()
return 1;
}

context->calibrateDAC();

M2kAnalogOut *analogOut = context->getAnalogOut();

// Prevent bad initial config
analogOut->reset();

context->calibrateDAC();

analogOut->setKernelBuffersCount(0, buffersCount);
analogOut->setKernelBuffersCount(1, buffersCount);

Expand Down
7 changes: 5 additions & 2 deletions examples/analog/streaming_synchronized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ int main()
return 1;
}

context->calibrateDAC();

M2kAnalogOut *analogOut = context->getAnalogOut();

// Prevent bad initial config
analogOut->reset();

context->calibrateDAC();

analogOut->setKernelBuffersCount(0, 32);
analogOut->setKernelBuffersCount(1, 20);

Expand Down
7 changes: 5 additions & 2 deletions examples/analog/sync_stream_diff_frequencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ int main()
return 1;
}

context->calibrateDAC();

M2kAnalogOut *analogOut = context->getAnalogOut();

// Prevent bad initial config
analogOut->reset();

context->calibrateDAC();

analogOut->setKernelBuffersCount(0, kernelBuffers[0]);
analogOut->setKernelBuffersCount(1, kernelBuffers[1]);

Expand Down

0 comments on commit c2eecf5

Please sign in to comment.