12-08-2019 01:43 PM
Greetings everyone.
I've made a program for controling motor that has three digital inputs: pulses, external control (basically, turnes on program control) and rotation direction. I tested it on USB-6251 (BNC) hardware, and it works, but I find it too messy and rough. So maybe there is a more simple and delicate way to make a program?
I need to make a finite pulse train of given frequency with duty cycle of 10%.
And btw, because of specific motor cable connectors structure I'm, unfortunately, restricted to digital outputs.
12-09-2019 07:26 AM
I'm surprised that it "works", it doesn't look like it would.
- the step task is never started, and the "auto-start" input for a waveform DO Write is False by default (and unwired)
- you're trying to generate a waveform output on port 1. Only port 0 supports hw clocking on your M-series device
- you haven't defined a hw clock signal for sampling. The M-series only supports "correlated DIO", and cannot internally derive a sample clock for itself. It needs help from elsewhere.
- you haven't set up any kind of timing or sequencing relationship between when you set your direction bit and when you generate your pulse(s).
It would be more straightforward to use a counter task to generate the step pulses. You would still need proper sequencing between these pulses and the other 2 digital signals.
-Kevin P
12-09-2019 01:04 PM
Thank you for ideas.
However, as I mentioned previously, I'm restricted to port 1 digital output because of specific motor cable connector. I'm awared that some outputs can work with clock signal, but, unfortunately, it's not my case.
And I haven't completely got the idea of sequensing signals generating from different lines. Two other bits have to be constantly generated during the work with step motor, otherwise it would be impossible to control the latter.
12-09-2019 01:44 PM
You've now mentioned the following key words: messy, rough, step motor, port 1. To deal with the messy and rough part, you really need hardware timing for the steps. When restricted to port 1, you can't get hardware timing from a DO task. So you really need to approach this as a counter pulsetrain task.
Many (if not all) the digital lines on port 1 can also be used as a PFI pin for a counter output signal, solving your physical cabling issue.
The sequencing idea is not as tricky as you seem to think. The external control bit and direction bit won't need to be rewritten with every step pulse. For a given test run with a bunch of step sequences, you would:
1. Write the digital bit to take "external control" just once. Once written, the digital state will be held until or unless you write something different. So don't.
2. Write the digital bit for direction.
3. Run the finite pulse train counter task at the desired freq & duty cycle.
4. Repeat steps 2 & 3 as many times as you want. (If you aren't changing direction, you won't have to re-write the same direction bit value. But the code is probably simplest if you simply always write it, even if redundant.)
5. Write the digital bit to release "external control" when done making step sequences.
-Kevin P