LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reaching 125 [kHz] sampling on NI-9263

Solved!
Go to solution

Hello,

 

I'm developing a press machine (it presses soil samples) at slow speed. I'm using a stepper motor, which I control through an NI-9263. The press should work at very slow speed, and this is working fine. But for the set up, before the test starts (or after it finishes), it's necessary to move the press quite a bit faster.

 

So, the motor receives instructions by 2 parameters: direction and step. The direction is quite easy, just positive or negative. The step requires a square wave, where every full period translates as one (1) step. From this point on it's quite obvious that I only need to control the frequency of the square wave.

 

I've tried 2 methods this far, and I have not been able to increase the frequency above 1 [kHz].

 

1.1) A loop with high resolution polling wait, it went as far as ~1 [kHz]. The loop changed the value of the reference voltage in every loop count (instruction is writing a channel at 8 [V], multiplied by (-1)^i, so it jumps from 8 to -8 [V] each loop count).

 

1.2) A timed loop doing the same, just the maximum resolution is 1 [kHz].

 

2) Building a square wave with higher frequency, and writing it periodically to the NI-9263, which should send it forward to the motor's drive. This way the motor behaves as if every wave sent was just one (1) pulse, and gives one (1) step, and then it waits for the next wave to hit.

 

I'm out of ideas to write the data, and I think there has to be a way, since the NI-9263 has capacity to write at 125 [kHz]. I also tried to step the motor at higher frequencies with a Raspberry Pi, and I had no problem to set frequencies up to 10 [kHz] (afterwards, the motor faulted, but that's for another forum).

 

I attached the VI's for the three cases, I hope it illustrates what I'm trying to do. I apologize for the mess, there's still options that I'm trying to get to work.

0 Kudos
Message 1 of 10
(2,643 Views)

Hi MatiMarin,

 


@MatiMarin wrote:

I'm using a stepper motor, which I control through an NI-9263. The press should work at very slow speed, and this is working fine. But for the set up, before the test starts (or after it finishes), it's necessary to move the press quite a bit faster.


Which chassis do you use to hold your NI9263 module?

Do you use a cRIO? (Which one?)

Do you use a cDAQ? (Which one?)

 

You seem to use some RT (Realtime) functions (like creating a 1MHz clock for a TWL), but on the other hand there are comments about Windows computer capabilities in your block diagram…

 

Generic advice: you should NEVER use the "x channels 1 sample" mode with DAQmxRead/Write when you want to reach samplerate larger than ~200Hz…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(2,627 Views)

Hi, GerdW,

 

I use a cDAQ 9171.

 

Yes, I tried to use RT functions, but as I developed the idea, I found comments about MS Windows not being able to work with those functions. I don't understand why, really.

 

Thanks for your advice (about x channels 1 sample), I'll modify my practice taking it.

 

MatiMarin

0 Kudos
Message 3 of 10
(2,602 Views)

@MatiMarin wrote:

Yes, I tried to use RT functions, but as I developed the idea, I found comments about MS Windows not being able to work with those functions. I don't understand why, really.

 


In Windows environments, the OS is multithreaded and it decides when things run based on its internal best guess as to how to multitask.  So when a program tells Windows "sleep for X milliseconds", windows will sleep for at least X milliseconds, but it could be any amount more.  

 

Here's a simple example:

Kyle97330_0-1641326855269.png

My PC runs this anywhere from 1470 to 1520, when you'd expect to see 1000 or 1001 if everything was perfect.

 

If I switch to running a timed loop, it does much better because it has settings to dedicate to priority, processor, etc:

Kyle97330_1-1641327119045.png

However, it's still not exactly 1000 or 1001 because it's Windows.  If it was run on a real-time system (which is what the timed loop structure is usually used on) then it would get it exactly (if there was nothing in the loop taking over 1 ms to run).

0 Kudos
Message 4 of 10
(2,599 Views)
Solution
Accepted by MatiMarin

I made a few minor mods to a shipping example for finite AO to demonstrate a way to get faster step pulse output.   Your code seems to want to toggle between +8V and -8V for the steps, so I did the same.

 

This example fills task buffer with the AO data to be generated *before* starting the task.  This is the key change needed to support faster output rates.  Once the task is started, DAQmx works behind the scenes to deliver the data to the DAQ device.

 

Give it a try, you should be able to achieve the full rated sample rate of your device.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 5 of 10
(2,594 Views)

Yeah, using continuous multi-sample writing with Kevin's method is definitely the way to go. And unless you have a really bizarre stepper motor driver, you just need to go high-low. You shouldn't need a sine wave. With 125 kHz sampling you should be able to get 62.5 kHz step rates (since each step needs to be low to high transition).

 

However, let me give you an alternate solution- just get an off-the-shelf Gcode stepper controller. You can get an Arduino clone for like $11 and flash it with GRBL (free) then send serial commands, which can get you to 100+ kHz. Of course if you need to synchronize data with motion then your method isn't bad, but you could also use the output of the stepper driver as your sample clock to sample an analog input on each step.

0 Kudos
Message 6 of 10
(2,569 Views)

Hi, Kevin,

 

Thank you for your VI, it allowed me to go quite faster (I reached the motor's limit!). I'm working on the details to use it with my solution, I have great hopes for this.

 

Thanks a lot!

 

MatiMarin

0 Kudos
Message 7 of 10
(2,541 Views)

Hi Bert,

 

Thanks for the idea. I actually started with a RPi 4 as prototype. I got some trouble with the signal's stability, as I increased the frequency above 4 [kHz] the motor would fault. I haven't tried Arduino, I'll keep it in mind.

 

Kind regards,

 

MatiMarin

0 Kudos
Message 8 of 10
(2,538 Views)

There's literally zero coding if you use Arduino. Load the GRBL firmware on there and then configure it. You then send commands like "G1 X5" to move your axis to 5 inches (or mm or whatever). Then send "G1 X10" to move it to 10 inches. It's incredibly simple to use once you get the hang of Gcode.

0 Kudos
Message 9 of 10
(2,528 Views)

I know this has been solved, but along the same lines as using an Arduino, you can build a simple circuit out of an 555 timer IC.   Similar to this: http://www.learningaboutelectronics.com/Articles/Adjustable-square-wave-generator-circuit-with-a-555...  Instead of using a potentiometer to control the frequency output, you can apply an analog voltage controlled by your DAQ.  I have successfully used this method to control stepper motors with an inexpensive and slow DAQ system.

Message 10 of 10
(2,015 Views)