File: examples.rst

package info (click to toggle)
libm2k 0.9.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,580 kB
  • sloc: xml: 1,611,497; cpp: 16,278; python: 4,181; cs: 516; sh: 471; ansic: 403; makefile: 35
file content (71 lines) | stat: -rw-r--r-- 1,838 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
libm2k Examples
===================


Generating data using the ADALM2000 DAC and acquiring it using the ADALM2000 ADC

.. code-block:: python

  # This example assumes the following connections:
  # W1 -> 1+
  # W2 -> 2+
  # GND -> 1-
  # GND -> 2-
  #
  # The application will generate a sine and triangular wave on W1 and W2. The signal is fed back into the analog input
  # and the voltage values are displayed on the screen

  import libm2k
  import matplotlib.pyplot as plt
  import time
  import numpy as np

  ctx=libm2k.m2kOpen()
  if ctx is None:
  	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()

  ain.enableChannel(0,True)
  ain.enableChannel(1,True)
  ain.setSampleRate(100000)
  ain.setRange(0,-10,10)

  ### uncomment the following block to enable triggering
  #trig.setAnalogSource(0) # Channel 0 as source
  #trig.setAnalogCondition(0,libm2k.RISING_EDGE_ANALOG)
  #trig.setAnalogLevel(0,0.5)  # Set trigger level at 0.5
  #trig.setAnalogDelay(0) # Trigger is centered
  #trig.setAnalogMode(1, libm2k.ANALOG)

  aout.setSampleRate(0, 750000)
  aout.setSampleRate(1, 750000)
  aout.enableChannel(0, True)
  aout.enableChannel(1, True)

  x=np.linspace(-np.pi,np.pi,1024)
  buffer1=np.linspace(-2.0,2.00,1024)
  buffer2=np.sin(x)

  buffer = [buffer1, buffer2]

  aout.setCyclic(True)
  aout.push(buffer)

  for i in range(10): # gets 10 triggered samples then quits
      data = ain.getSamples(1000)
      plt.plot(data[0])
      plt.plot(data[1])
      plt.show()
      time.sleep(0.1)

  libm2k.contextClose(ctx)


Other Python examples are available in the `source repository <https://github.com/analogdevicesinc/libm2k/tree/main/bindings/python/examples>`_