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 =0whileTrue:
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 +=1if counter ==1000:
duration =(t - t_stopwatch)# pylint: disable=superfluous-parensprint("{: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:")# VwhileTrue:try:
offset_DC = float(offset_DC)breakexceptValueError:
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 =0whileTrue:
t = time.monotonic()- t0
analogOut.nodeAmplitudeSet(CH1,DwfAnalogOutNode.value, offset)
analogOut.nodeAmplitudeSet(CH2,DwfAnalogOutNode.value, offset)
counter +=1if counter ==1000:
duration =(t - t_stopwatch)# pylint: disable=superfluous-parensprint("{:8.3f} loops/sec. Press Control-C to quit.".format(counter / duration))
counter =0
t_stopwatch = t
Question
Oznur Caliskan
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:
For DC:
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now