Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI USB 6343 Digital / Analog Output

Good morning, 

I'm working with a USB 6343 with Python3 and nidaqmx lib.

I want to  control a continuous motor and is it correct to control it's speed, rotation direction and of/off like that ? 

(I can set its speed from 0 to 10V) 

Spoiler
def control_digital():
    with nidaqmx.Task() as task:
        task.do_channels.add_do_chan("Dev1/port0/line0"# control ON / OFF
        task.do_channels.add_do_chan("Dev1/port0/line1"# control rotation direction
        task.write([TrueTrue]) #ON / Direction True
        time.sleep(1)
        task.write([FalseTrue]) #OFF / Direction True
        time.sleep(1)
        task.write([TrueFalse]) #ON / Direction False
        time.sleep(1)
        task.write([FalseFalse]) #Off / Direction False
        time.sleep(1)

# Write DO value False / True
def control_analog(voltage😞
    if voltage < 0 or voltage > 10:
        print(f"Incorrect voltagespecified ({voltage}) limits ar 0-10V")
        return False
    with nidaqmx.Task() as task:
        task.ao_channels.add_ao_voltage_chan("Dev1/ao3"# control motor speed (0-10 V)
        task.write([voltage])
        print(f"Voltage set to ({voltage})")
    return True


if __name__ == '__main__':
    for i in range(0,111😞
        if control_analog(i😞
            control_digital()

Now i've got a second question, i want to control another type of motor which can be controlled with sinus waves. 

I can set its frequency and amplitude by sending it a sin waves with frequency/amplitude as paramters. 

 

I want it to have to following behaviour:

i send it a sin waves, and it keep the parameters untill i decided to send another to sin wave. 

 

Do you have some clues to help me ? 

Thank's a lot ! 

 

0 Kudos
Message 1 of 2
(1,021 Views)

Hi, sorry for posting again but i've find a partial solution:

 

 

import nidaqmx
import numpy as np
import time
from nidaqmx.constants import AcquisitionType, TaskMode

Fs = 8000
f = 300
sample = 8000
x = np.arange(sample)
y = np.sin(2 * np.pi * f * x / Fs)

with nidaqmx.Task() as task:
    task.ao_channels.add_ao_voltage_chan('Dev1/ao1')

    task.timing.cfg_samp_clk_timing(8000,sample_mode=AcquisitionType.CONTINUOUS)

    print('Generation is started')
    task.write(y)
    task.control(TaskMode.TASK_COMMIT)
    task.start()
    
    while True:

        print("Generating")
        time.sleep(1)

 

 

This solution is okay, it's working fine. 

I've got two questions about it: 

I can change the frequency by changing the "f" var.

How can i change the amplitude ? 

And why Fs / sample should be setted to 8000 is it for precision ? I can change those values but the comportment of my motor is'nt the same can someone explain me why ? 

Thank's a lot !

0 Kudos
Message 2 of 2
(957 Views)