Jump to content

Oznur Caliskan

Members
  • Posts

    12
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Oznur Caliskan's Achievements

Member

Member (2/4)

0

Reputation

  1. Hi, Thank you so much for your help. It worked very well. :) Best, Öznur
  2. Hi @reddish, According to your recommendation, I simplified my code as much as possible. But the problem still continues. I think there are different issues, you can run the following code either, and connect W1,Scope1 to a pin and GNDs to GND. """Demonstrate the simplest way to control the AnalogOut instrument.""" import json import time import math import argparse import keyboard import matplotlib.pyplot as plot from datetime import datetime import numpy as np from matplotlib import pyplot from matplotlib.animation import FuncAnimation from operator import itemgetter #listeden item çekmek için from pydwf import DwfLibrary, DwfAnalogOutNode, DwfAnalogOutFunction, DwfAnalogOutIdle, PyDwfError, DwfAnalogInTriggerLengthCondition, DwfAnalogInTriggerType from pydwf.utilities import openDwfDevice from keyboard import press def parse_test_procedure(output,input): CH1 = 1 CH2 = 2 #Applied Voltage List applied = 5 print("Applied voltages:", applied) print("*************") #Expected Results List expected = 5 print("Expected results:", expected) print("*************") #Tolerance Value List tolerance = 0.3 print("Tolerance values:", tolerance) results = [] input.reset() output.reset(CH1) x = 0 print("Applied values", applied) print("Expected values", expected) print("Tolerance values", tolerance) output.nodeFunctionSet(CH1, DwfAnalogOutNode.Carrier, DwfAnalogOutFunction.Square) output.idleSet(CH1, DwfAnalogOutIdle.Initial) output.nodeEnableSet(CH1, DwfAnalogOutNode.Carrier, True) output.configure(CH1, True) voltage_DC = float(applied) output.amplitudeSet(CH1, voltage_DC) print("Given voltage:",output.amplitudeGet(CH1)) input.status(False) read_voltage_CH1 = input.statusSample(CH1) time.sleep(0.010) print("Read voltage:", input.channelOffsetGet(CH1)) expected_voltage_CH1 = expected if ((voltage_DC * (1 - float(tolerance))) <= read_voltage_CH1 <= ( voltage_DC * (1 + float(tolerance)))) and ( (expected_voltage_CH1 * (1 - float(tolerance))) <= read_voltage_CH1 <= ( expected_voltage_CH1 * (1 + float(tolerance)))): x += 1 print( f"\n Applied voltage:{voltage_DC} and Read voltage:{read_voltage_CH1}, Expected voltage:{expected_voltage_CH1} are equal!") else: print( f"Applied voltage:{voltage_DC} and Read voltage:{read_voltage_CH1}, Expected voltage:{expected_voltage_CH1} are NOT equal!!") if x == 3: print("x:", x) result = "TEST PASSED" print(result) results.append(result) else: print("x:", x) result = "TEST FAILED" print("\n\nAmplitude: ", voltage_DC) print(result) def main(): #parser operations must be done in main() parser = argparse.ArgumentParser(description="Demonstrate simple usage of the AnalogOut functionality.") parser.add_argument( "-sn", "--serial-number-filter", type=str, nargs='?', dest="serial_number_filter", help="serial number filter to select a specific Digilent Waveforms device" ) args = parser.parse_args() try: dwf = DwfLibrary() with openDwfDevice(dwf, serial_number_filter=args.serial_number_filter) as device: parse_test_procedure(device.analogOut,device.analogIn) except PyDwfError as exception: print("PyDwfError:", exception) except KeyboardInterrupt: print("Keyboard interrupt, ending demo.") if __name__ == "__main__": main() You will see this: Let me know the results, please. Best, Öznur
  3. Hi, It is normal that you're confused. Let me explain. I will not be using Waveforms application ever. I want the things that Waveforms do to be done by pydwf as this is the reason I chose to use pydwf. What I am saying is, I want to use wavegen and scope at the same time ON PYDWF. So when I am giving 5V to the related pin, I want to observe that I am giving exactly the right voltage by printing them... As we go back to my previous quote, I said I tested using wavegen and scope at the same time, it worked on Waveforms application so it shows us this is possible. However when I am trying to do it on my pydwf code, it gives the voltage but cannot read it properly. ( "Applied voltage:5.0 and Read voltage:-0.01881317031239038, Expected voltage:5.0 are NOT equal!!" )
  4. Hi @reddish, I did what it has been told me but there is one discrepancy, when I am using the Waveforms application itself I can both give DC waveform and observe it from Scope. However, when I am using pydwf it cannot give waveform so I cannot observe the signal as a consequence. Here are the screen shots; How is this possible? Best, Öznur
  5. Hi @zygot, Thank you for the heads-up. I use Analog Discovery 2 for this way of supplying/reading voltage to my development board. I agree with what you said, timing is important I can add sleep(). Do you think Analog Discovery 2 is not suitable for this application? What would you recommend? Best, Öznur
  6. Hi again @reddish, Thank you for your comments... They led me to simplify my code and it got easier to understand the concept. According to the examples, am I going to use "read_voltage_CH1 = input.statusSample(CH1)" to read the voltage? Or maybe I couldn't set the voltage properly or maybe it cannot read the voltage because it can't keep up with the set voltage should I put sleep() between them? Additionally, is it important which Digilent Device I am using? I am using Analog Discovery 2 and I am connecting both Wavegen and Scope cables to the related pin. Here I will show you my code: def parse_test_procedure(output,input): CH1 = 1 CH2 = 2 print("Processing...\n") with open("signal_procedure.json", "r") as file: procedure = json.load(file) print(type(procedure)) print("There are", len([_ for _ in procedure.keys() if "Test Case" in _]), "test cases.") #Test Case List listof_cases = [] index = 0 for index in procedure.keys(): listof_cases.insert(len(listof_cases), index) #Test Infos List listof_content = [] index = 0 for index in procedure.values(): listof_content.insert(len(listof_content), index) #Verification Method List verification_method = {} for k, v in procedure.items(): verification_method[k] = [listof_content.get("Verification Method") for listof_content in v] print("Verification methods:", verification_method) print("*************") #Applied Voltage List applied = {} for k, v in procedure.items(): applied[k] = [[listof_content.get("Applied Voltage") for listof_content in listof_content["Sub_Tests"]] for listof_content in v] print("Applied voltages:", applied) print("*************") #Expected Results List expected = {} for k, v in procedure.items(): expected[k] = [[listof_content.get("Expected Result") for listof_content in listof_content["Sub_Tests"]] for listof_content in v] print("Expected results:", expected) print("*************") #Tolerance Value List tolerance = {} for k, v in procedure.items(): tolerance[k] = [[listof_content.get("Tolerance") for listof_content in listof_content["Sub_Tests"]] for listof_content in v] print("Tolerance values:", tolerance) # Counting Test Case, Test Step, Subtests test_case_count = test_step_count = test_subtest_count = 0 for test_case_key, test_case in procedure.items(): if test_case_key.startswith("Test Case "): test_case_count += 1 for test_step in test_case: test_step_count += 1 for sub_test in test_step["Sub_Tests"]: test_subtest_count += 1 print("Test case count:", test_case_count, "\nTest step count:", test_step_count, "\nTest subtest count:", test_subtest_count) # Test Cases List cases = list(applied.keys()) print(cases) results = [] for key, value in applied.items(): for i in range(0, 19): input.reset() output.reset(CH1) x = 0 applied_TC = [] expected_TC = [] tolerance_TC = [] print("*********", str(cases[i]), "*********") applied_TC.insert(len(applied.get(cases[i])), applied.get(str(cases[i]))) applied_TC = [float(eleman) for inner_list in applied_TC for middle_list in inner_list for eleman in middle_list] expected_TC.insert(len(applied.get(cases[i])), expected.get(str(cases[i]))) expected_TC = [float(eleman) for inner_list in expected_TC for middle_list in inner_list for eleman in middle_list] tolerance_TC.insert(len(applied.get(cases[i])), tolerance.get(str(cases[i]))) tolerance_TC = [float(eleman) for inner_list in tolerance_TC for middle_list in inner_list for eleman in middle_list] print("Applied values", applied_TC) print("Expected values", expected_TC) print("Tolerance values", tolerance_TC) for j in range(len(applied_TC)): voltage_DC = applied_TC[j] output.nodeFunctionSet(CH1, DwfAnalogOutNode.Carrier, DwfAnalogOutFunction.Square) output.idleSet(CH1, DwfAnalogOutIdle.Initial) output.nodeEnableSet(CH1, DwfAnalogOutNode.Carrier, True) output.configure(CH1, True) output.amplitudeSet(CH1, voltage_DC) read_voltage_CH1 = input.statusSample(CH1) #DOESNT READ THE VOLTAGE expected_voltage_CH1 = expected_TC[j] if ((voltage_DC * (1 - float(tolerance_TC[j]))) <= read_voltage_CH1 <= ( voltage_DC * (1 + float(tolerance_TC[j])))) and ( (expected_voltage_CH1 * (1 - float(tolerance_TC[j]))) <= read_voltage_CH1 <= ( expected_voltage_CH1 * (1 + float(tolerance_TC[j])))): x += 1 print( f"\n Applied voltage:{voltage_DC} and Read voltage:{read_voltage_CH1}, Expected voltage:{expected_voltage_CH1} are equal!") else: print( f"Applied voltage:{voltage_DC} and Read voltage:{read_voltage_CH1}, Expected voltage:{expected_voltage_CH1} are NOT equal!!") if x == 3: print("x:", x) result = "TEST PASSED" print(result) results.append(result) else: if applied_TC == [] and expected_TC == [] and tolerance_TC == []: continue else: print("x:", x) result = "TEST FAILED" print(result) results.append(result) print("Results:", results) """t_stopwatch = 0.0 counter = 0 t0 = time.monotonic() while True: t = time.monotonic() - t0 counter += 1 if counter == 500: for channel_index in (CH1, CH2): duration = (t - t_stopwatch) # pylint: disable=superfluous-parens print("{:8.3f} loops/sec. Press Q to quit.".format(1 + counter / 1 + duration)) print("Giving output for Channel", CH1, "is:", analogOut.amplitudeGet(CH1)) counter = 0 t_stopwatch = t""" def main(): #parser operations must be done in main() parser = argparse.ArgumentParser(description="Demonstrate simple usage of the AnalogOut functionality.") parser.add_argument( "-sn", "--serial-number-filter", type=str, nargs='?', dest="serial_number_filter", help="serial number filter to select a specific Digilent Waveforms device" ) args = parser.parse_args() try: dwf = DwfLibrary() with openDwfDevice(dwf, serial_number_filter=args.serial_number_filter) as device: parse_test_procedure(device.analogOut,device.analogIn) except PyDwfError as exception: print("PyDwfError:", exception) except KeyboardInterrupt: print("Keyboard interrupt, ending demo.") if __name__ == "__main__": main() Best, Öznur :)
  7. Hi @reddish, First of all, thank you for providing us this library, it is very user-friendly! Helps me a lot.. I had just a little problem. Additionally, sorry for the confusion. Actually, my "analogOut" is just a parameter of my own class. I will provide my code to you and I am sure you will get what I am trying to do: #! /usr/bin/env python3 """Demonstrate the simplest way to control the AnalogOut instrument.""" import json import time import math import argparse import keyboard import matplotlib.pyplot as plot from datetime import datetime import numpy as np from matplotlib import pyplot from matplotlib.animation import FuncAnimation from operator import itemgetter #listeden item çekmek için from pydwf import DwfLibrary, DwfAnalogOutNode, DwfAnalogOutFunction, DwfAnalogOutIdle, PyDwfError, DwfAnalogInTriggerLengthCondition, DwfAnalogInTriggerType from pydwf.utilities import openDwfDevice from keyboard import press from GUI import AnalogInSimple def demo_analog_input_instrument_api_simple(analogIn): channel_count = analogIn.channelCount() if channel_count == 0: print("The device has no analog input channels that can be used for this demo.") return analogIn.reset() CH1 = 0 while True: analogIn.status(False) print("analog input", ", ".join("channel {}: {:25.20f} [V]".format( channel_index, analogIn.statusSample(channel_index)) for channel_index in range(channel_count))) print("Offset:", analogIn.channelOffsetGet(CH1)) time.sleep(0.010) class AnalogOut: def __init__(self, procedure, listof_cases, listof_content, applied, expected, tolerance, voltage_DC, verification_method): self.procedure = procedure self.listof_cases = listof_cases self.listof_content = listof_content self.applied = applied self.expected = expected self.tolerance = tolerance self.applied_TC = applied_TC self.expected_TC = expected_TC self.tolerance_TC = tolerance_TC self.voltage_DC = voltage_DC self.verification_method = verification_method def demo_simple_analog_out(analogOut): parser = argparse.ArgumentParser(description="Demonstrate simple usage of the AnalogOut functionality.") parser.add_argument( "-sn", "--serial-number-filter", type=str, nargs='?', dest="serial_number_filter", help="serial number filter to select a specific Digilent Waveforms device" ) args = parser.parse_args() try: dwf = DwfLibrary() with openDwfDevice(dwf, serial_number_filter=args.serial_number_filter) as device: t0 = time.monotonic() """analogOut.signal_type = input("Please select the Signal Type:\n1. Press 1 for Sine\n2. Press 2 for DC\n3. Press 3 for Square\n") print("Type:", analogOut.signal_type, "\n")""" # Reset all channels. analogOut.reset(-1) CH1 = 0 CH2 = 1 for channel_index in (CH1, CH2): analogOut.nodeFunctionSet(channel_index, DwfAnalogOutNode.Carrier, DwfAnalogOutFunction.Square) analogOut.idleSet(channel_index, DwfAnalogOutIdle.Initial) analogOut.nodeEnableSet(channel_index, DwfAnalogOutNode.Carrier, True) analogOut.configure(channel_index, True) # Necessary to give sine wave configured print("Processing...\n") with open("signal_procedure.json", "r") as file: analogOut.procedure = json.load(file) print(type(analogOut.procedure)) print("There are", len([_ for _ in analogOut.procedure.keys() if "Test Case" in _]), "test cases.") #Getting test cases analogOut.listof_cases = [] index = 0 for index in analogOut.procedure.keys(): analogOut.listof_cases.insert(len(analogOut.listof_cases), index) #getting values of the test case dictionary analogOut.listof_content = [] index = 0 for index in analogOut.procedure.values(): analogOut.listof_content.insert(len(analogOut.listof_content), index) analogOut.verification_method = {} for k, v in analogOut.procedure.items(): analogOut.verification_method[k] = [analogOut.listof_content.get("Verification Method") for analogOut.listof_content in v] print("Verification methods:", analogOut.verification_method) print("*************") analogOut.applied = {} for k, v in analogOut.procedure.items(): analogOut.applied[k] = [[analogOut.listof_content.get("Applied Voltage") for analogOut.listof_content in analogOut.listof_content["Sub_Tests"]] for analogOut.listof_content in v] print("Applied voltages:", analogOut.applied) print("*************") analogOut.expected = {} for k, v in analogOut.procedure.items(): analogOut.expected[k] = [[analogOut.listof_content.get("Expected Result") for analogOut.listof_content in analogOut.listof_content["Sub_Tests"]] for analogOut.listof_content in v] print("Expected results:", analogOut.expected) print("*************") analogOut.tolerance = {} for k, v in analogOut.procedure.items(): analogOut.tolerance[k] = [[analogOut.listof_content.get("Tolerance") for analogOut.listof_content in analogOut.listof_content["Sub_Tests"]] for analogOut.listof_content in v] print("Tolerance values:", analogOut.tolerance) test_case_count = test_step_count = test_subtest_count = 0 for test_case_key, test_case in analogOut.procedure.items(): if test_case_key.startswith("Test Case "): test_case_count += 1 for test_step in test_case: test_step_count += 1 print("****", test_step["Test Case"], test_step["Test Step"]) for sub_test in test_step["Sub_Tests"]: test_subtest_count += 1 print(sub_test["Applied Voltage"], sub_test["Expected Result"], sub_test["Tolerance"]) print("test_case_count:", test_case_count, "\ntest_step_count:", test_step_count,"\ntest_subtest_count:", test_subtest_count) cases = list(analogOut.applied.keys()) print(cases) analogOut.results = [] for key, value in analogOut.applied.items(): for i in range(0,19): x = 0 print("*********", str(cases[i]), "*********") analogOut.applied_TC = [] analogOut.applied_TC.insert(len(analogOut.applied.get(cases[i])), analogOut.applied.get(str(cases[i]))) analogOut.applied_TC = [float(eleman) for inner_list in analogOut.applied_TC for middle_list in inner_list for eleman in middle_list] analogOut.expected_TC = [] analogOut.expected_TC.insert(len(analogOut.applied.get(cases[i])), analogOut.expected.get(str(cases[i]))) analogOut.expected_TC = [float(eleman) for inner_list in analogOut.expected_TC for middle_list in inner_list for eleman in middle_list] analogOut.tolerance_TC = [] analogOut.tolerance_TC.insert(len(analogOut.applied.get(cases[i])), analogOut.tolerance.get(str(cases[i]))) analogOut.tolerance_TC = [float(eleman) for inner_list in analogOut.tolerance_TC for middle_list in inner_list for eleman in middle_list] print("Applied values", analogOut.applied_TC) print("Expected values", analogOut.expected_TC) print("Tolerance values", analogOut.tolerance_TC) for j in range(len(analogOut.applied_TC)): analogOut.voltage_DC = analogOut.applied_TC[j] analogOut.amplitudeSet(CH1, analogOut.voltage_DC) read_voltage_CH1 = demo_analog_input_instrument_api_simple(analogIn="") #HERE I AM TRYING TO RECALL STATUS READ FUNC. BUT CANNOT expected_voltage_CH1 = analogOut.expected_TC[j] if ((analogOut.voltage_DC * (1 - float(analogOut.tolerance_TC[j]))) <= read_voltage_CH1 <= (analogOut.voltage_DC * (1 + float(analogOut.tolerance_TC[j])))) and ((expected_voltage_CH1 * (1 - float(analogOut.tolerance_TC[j]))) <= read_voltage_CH1 <= (expected_voltage_CH1 * (1 + float(analogOut.tolerance_TC[j])))): x += 1 print(f"\n Applied voltage:{analogOut.voltage_DC} and Read voltage:{read_voltage_CH1}, Expected voltage:{expected_voltage_CH1} are equal!") else: print(f"Applied voltage:{analogOut.voltage_DC} and Read voltage:{read_voltage_CH1}, Expected voltage:{expected_voltage_CH1} are NOT equal!!") if x == 3: print("x:",x) result = "TEST PASSED" print(result) analogOut.results.append(result) else: if analogOut.applied_TC == [] and analogOut.expected_TC == [] and analogOut.tolerance_TC == []: continue else: print("x:", x) result = "TEST FAILED" print(result) analogOut.results.append(result) print("Results:", analogOut.results) t_stopwatch = 0.0 counter = 0 t0 = time.monotonic() while True: t = time.monotonic() - t0 counter += 1 if counter == 500: for channel_index in (CH1, CH2): duration = (t - t_stopwatch) # pylint: disable=superfluous-parens print("{:8.3f} loops/sec. Press Q to quit.".format(1+counter / 1+duration)) print("Giving output for Channel", CH1, "is:", analogOut.amplitudeGet(CH1)) counter = 0 t_stopwatch = t def main(): """Parse arguments and start demo.""" parser = argparse.ArgumentParser(description="Demonstrate simple usage of the AnalogOut functionality.") parser.add_argument( "-sn", "--serial-number-filter", type=str, nargs='?', dest="serial_number_filter", help="serial number filter to select a specific Digilent Waveforms device" ) args = parser.parse_args() try: dwf = DwfLibrary() with openDwfDevice(dwf, serial_number_filter=args.serial_number_filter) as device: AnalogOut.demo_simple_analog_out(device.analogOut) demo_analog_input_instrument_api_simple(device.analogIn) except PyDwfError as exception: print("PyDwfError:", exception) except KeyboardInterrupt: print("Keyboard interrupt, ending demo.") if __name__ == "__main__": main() So as I said earlier, I cannot get input values analogIn.statusSample(channel_index) because I am already in output mode if I am getting it right ?
  8. Hi everyone, I need to automatize a test procedure. So, I would like to apply a voltage and read it at the same time to decide whether it passed or not. I wrote a code for applied&expected voltage output but can't read the voltage while Analog Discovery's W1&W2 jumpers are connected to the related pin. Are there ways to do it ? I tried this: for j in range(len(analogOut.applied_TC)): analogOut.voltage_DC = analogOut.applied_TC[j] analogOut.amplitudeSet(CH1, analogOut.voltage_DC) read_voltage_CH1 = analogOut.amplitudeGet(CH1) expected_voltage_CH1 = analogOut.expected_TC[j] if ((analogOut.voltage_DC * (1 - float(analogOut.tolerance_TC[j]))) <= read_voltage_CH1 <= (analogOut.voltage_DC * (1 + float(analogOut.tolerance_TC[j])))) and ((expected_voltage_CH1 * (1 - float(analogOut.tolerance_TC[j]))) <= read_voltage_CH1 <= (expected_voltage_CH1 * (1 + float(analogOut.tolerance_TC[j])))): x += 1 print(f"\n Applied voltage:{analogOut.voltage_DC} and Read voltage:{read_voltage_CH1}, Expected voltage:{expected_voltage_CH1} are equal!") else: print(f"Applied voltage:{analogOut.voltage_DC} and Read voltage:{read_voltage_CH1}, Expected voltage:{expected_voltage_CH1} are NOT equal!!") if x == 3: print("x:",x) print("TEST PASSED") else: print("x:", x) print("TEST FAILED") But analogOut.amplitudeGet(CH1) function doesn't read current voltage. (According to my verification activities) I may need to use the analogIn.statusSample(channel_index) from this example: https://github.com/sidneycadot/pydwf/blob/master/source/pydwf-examples/AnalogInSimple.py Bu I couldnt use analogIn while I was using analogOut. Maybe I need to add this function to my AnalogOut class? : def demo_analog_input_instrument_api_simple(analogIn): channel_count = analogIn.channelCount() if channel_count == 0: print("The device has no analog input channels that can be used for this demo.") return analogIn.reset() CH1 = 0 while True: analogIn.status(False) print("analog input", ", ".join("channel {}: {:25.20f} [V]".format( channel_index, analogIn.statusSample(channel_index)) for channel_index in range(channel_count))) print("Offset:", analogIn.channelOffsetGet(CH1)) time.sleep(0.010) Thanks in advance
  9. Hi, I would like to set the voltage from my Python code and then read it. Here is the code (class) I use for reading: class AnalogIn: def __init__(self, analogOut, analogIn, analog_out_channel, analog_in_channel, voltage_in): self.analogOut = analogOut self.analogIn = analogIn self.analog_out_channel = analog_out_channel self.analog_in_channel = analog_in_channel self.voltage_in = voltage_in def measurement(analogIn): # Get analog input voltage. # The easiest way to read a static voltage is by querying the status and using the statusSample() method. analogIn.voltage_in = analogIn.statusSample(analogIn.analog_in_channel) print("Voltage in:", analogIn.voltage_in) time.sleep(0.010) And here I am setting the voltage and try to read it by calling AnalogIn class: elif analogOut.signal_type == "2": # DC # Initialize channel output of analog-out voltage controlled by Python. # We do this by a trick where we keep the channel disabled, and use the first value # of a square wave, which is output in Idle mode. CH1 = 0 CH2 = 1 for channel_index in (CH1, CH2): analogOut.nodeFunctionSet(channel_index, DwfAnalogOutNode.Carrier, DwfAnalogOutFunction.Square) analogOut.idleSet(channel_index, DwfAnalogOutIdle.Initial) analogOut.nodeEnableSet(channel_index, DwfAnalogOutNode.Carrier, True) analogOut.configure(channel_index, True) # Necessary to give sine wave configured print("Processing...\n") # Offset değerini input olarak alır analogOut.voltage_DC = input("Please enter the DC Voltage value:") # V while True: try: analogOut.voltage_DC = float(analogOut.voltage_DC) break except ValueError: analogOut.voltage_DC = input("Please enter a valid number:") continue print("DC Voltage:", analogOut.voltage_DC, "\n") # We now have a valid voltage. Push set the emplitude of the (inactive) square wave. # Since the channel is configured to replicate the first value of the waveform when idle # (disabled), this value will show up on the output. t_stopwatch = 0.0 counter = 0 t0 = time.monotonic() while True: t = time.monotonic() - t0 for channel_index in (CH1, CH2): analogOut.amplitudeSet(channel_index, analogOut.voltage_DC) counter += 1 if counter == 500: for channel_index in (CH1, CH2): duration = (t - t_stopwatch) # pylint: disable=superfluous-parens print("{:8.3f} loops/sec. Press Q to quit.".format(counter / duration)) print("Giving output for Channel", CH1, "is:", analogOut.amplitudeGet(CH1)) print("Giving output for Channel", CH2, "is:", analogOut.amplitudeGet(CH2), "\n") AnalogIn.measurement(analogIn=analogOut.voltage_DC) counter = 0 t_stopwatch = t However, I set the voltage apparently but can't do the reading. So what am I missing if anybody can tell I would be appreciated :) thank you
  10. Hi Reddish, Appreciate your detailed response. I handled the Sine and DC manipulation well, thanks to you. However, I am not sure if I figured this out: When you want to give DC voltage, you set the idle value to initial to give DC more effectively. But when I want to give a square wave not DC, should I set the nodeFunctionSet(channel_index, DwfAnalogOutNode.Carrier, DwfAnalogOutFunction.Square) and idleSet(channel_index, DwfAnalogOutIdle.Offset)? Because I tried it and t behaves like I am giving DC voltage again. elif analogOut.signal_type == "3": # Square CH1 = 0 CH2 = 1 # Gets amplitude value analogOut.amplitude = input("Please enter the Amplitude value:") # V while True: try: analogOut.amplitude = float(analogOut.amplitude) break except ValueError: analogOut.amplitude = input("Please enter a valid number:") print("Amplitude:", analogOut.amplitude, "\n") print("Processing...\n") dwf = DwfLibrary() t_stopwatch = 0.0 counter = 0 t0 = time.monotonic() while True: t = time.monotonic() - t0 # Channel infos for channel_index in (CH1, CH2): analogOut.nodeFunctionSet(channel_index, DwfAnalogOutNode.Carrier, DwfAnalogOutFunction.Square) analogOut.nodeEnableSet(channel_index, DwfAnalogOutNode.Carrier, True) analogOut.amplitudeSet(channel_index, analogOut.amplitude) counter += 1 if counter == 500: for channel_index in (CH1, CH2): duration = (t - t_stopwatch) # pylint: disable=superfluous-parens print("{:8.3f} loops/sec. Press Q to quit.".format(counter / duration)) print("Giving output for Channel", CH1, "is:", analogOut.amplitudeGet(CH1)) print("Giving output for Channel", CH2, "is:", analogOut.amplitudeGet(CH2), "\n") counter = 0 t_stopwatch = t Thanks, Best regards
  11. 0 I am using pydwf library to use it as a Wavegen. For example I want to give a Sine Wave to my microcontroller pin or just DC. I looked into pydwf examples and wrote some code but I cannot change the waves amplitude or offset or anything even though I use nodeAmplitudeSet() or nodeOffsetSet() functions. So what am I missing guys anyone to help me? Thanks in advance. For Sine wave: #Before this line it takes the values (frequency,offset etc.) for channel_index in (CH1, CH2): print("\nChannel Info: CH",channel_index) analogOut.nodeFunctionSet(channel_index, DwfAnalogOutNode.Carrier, DwfAnalogOutFunction.Sine) print("Function info:", analogOut.nodeFunctionInfo(channel_index, DwfAnalogOutNode.Carrier)) analogOut.nodeFrequencySet(channel_index, DwfAnalogOutNode.Carrier, frequency) print("Frequency info:", analogOut.frequencyInfo(channel_index)) analogOut.amplitudeSet(channel_index, amplitude) print("Amplitude info:", analogOut.amplitudeInfo(channel_index)) analogOut.offsetSet(channel_index, offset) print("Offset info:", analogOut.offsetInfo(channel_index)) analogOut.idleSet(channel_index, DwfAnalogOutIdle.Initial) print("Idle info:", analogOut.idleInfo(channel_index)) analogOut.nodeEnableSet(channel_index, DwfAnalogOutNode.Carrier, True) print("Node enable info:", analogOut.nodeInfo(channel_index)) t_stopwatch = 0.0 counter = 0 while True: t = time.monotonic() - t0 vx = 2.5 * math.cos(2 * math.pi * t * float(frequency)) vy = 2.5 * math.sin(2 * math.pi * t * float(frequency)) # To change the output signal on each of the two channels, we just need to change the channel's # amplitude setting. analogOut.nodeAmplitudeSet(CH1, DwfAnalogOutNode.Carrier, vx) analogOut.nodeAmplitudeSet(CH2, DwfAnalogOutNode.Carrier, vy) for channel_index in (CH1, CH2): counter += 1 if counter == 1000: duration = (t - t_stopwatch) # pylint: disable=superfluous-parens print("{:8.3f} loops/sec. Press Control-C to quit.".format(counter / duration)) print("Giving output:", analogOut.amplitudeInfo(channel_index)) counter = 0 t_stopwatch = t For DC: offset_DC = input("Please enter the DC Offset value:") # V while True: try: offset_DC = float(offset_DC) break except ValueError: offset_DC = input("Please enter a valid number:") print("DC Offset:", offset_DC, "\n") for channel_index in (CH1, CH2): analogOut.nodeFunctionSet(channel_index, DwfAnalogOutNode.Carrier, DwfAnalogOutFunction.DC) analogOut.idleSet(channel_index, DwfAnalogOutIdle.Initial) analogOut.nodeEnableSet(channel_index, DwfAnalogOutNode.value, True) t_stopwatch = 0.0 counter = 0 while True: t = time.monotonic() - t0 analogOut.nodeAmplitudeSet(CH1, DwfAnalogOutNode.value, offset) analogOut.nodeAmplitudeSet(CH2, DwfAnalogOutNode.value, offset) counter += 1 if counter == 1000: duration = (t - t_stopwatch) # pylint: disable=superfluous-parens print("{:8.3f} loops/sec. Press Control-C to quit.".format(counter / duration)) counter = 0 t_stopwatch = t
  12. Hi, I would like to measure the phase difference and prove it to be equal to zero. Signals are here: Thank you, Kind regards.
×
×
  • Create New...