Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Finite PWM on M-series

Hi ni world!

 

 I am an owner of a NI PCI-6289 (with two counters) and I work on with Labview 8.5. In a few words my problem is the application of Pulse Width Modulation (PWM) control through a Counter Output (CO) on a mechanic system. System excitation is a sinusoid or a stochastic one and is applied through an Analog Output (AO) channel to the system exciter. The system response is the acceleration and is collected to system hard disk through an Analog Input (AI) channel. Now, when the acceleration response reaches a preselected acceleration value, then the CO starts to work in order to apply the PWM control. But, when the acceleration response is under the preselected acceleration value then the CO stops to work until the next time the acceleration response value reaches again the preselected acceleration response value and the CO starts again and so on... (for my application I need two counters but for simplicity reasons I have put in the attached vi only one) 

 In the attached test.vi, the CO starts only for one time when the vi starts working. Only the AI and AO works properly. Any ideas are very welcomed and respectful!

 

Best regards!

 

 greg

Download All
0 Kudos
Message 1 of 6
(7,245 Views)

Hi Greg,

 

Do you receive an error at the counter for other iterations of the while loop?  I would try breaking it into a smaller example looking only at the counter sequence with a dummy control to toggle between the cases of the case structure.  Also shift registers to pass the task and error wire to each iteration of the while loop would probably be a good idea.  Hopefully this helps!

 

 

Regards,


h_baker
National Instruments
Applications Engineer
0 Kudos
Message 2 of 6
(7,220 Views)

Hi Greg,

 

Once you start a continuous counter output task it will run until stopped.  What you're doing now with DAQmx Write is changing the values any time the AI is above your threshold.

 

 

You should either:

1)  Explicitly start/stop the CO task when needed in accordance with the value from the AI channel.

 

2)  Implement a Pause Trigger on the CO task.  You can use the boolean result that you are already computing to write to a digital line to be used for the pause trigger for the CO task (any of the PFI lines).

*You can also use the Analog Comparison Event to have a completely HW-Timed Pause Trigger.  However, you cannot adjust the threshold on-the-fly as you are now with your SW approach.

 

I personally like the Pause Trigger, but either option should be viable.  If you need any help with either approach be sure to let us know!

 

 

Best Regards,

John Passiak
0 Kudos
Message 3 of 6
(7,197 Views)

Hello h_baker and John P!!

 

First of all I would like to thank you for you interest about my problem and for your time replying me!

h_baker, I don’t receive any error at the counter for oyher iterations of the while loop. The AI and AO tasks work perfect but the counter works once at the beginning of the VI and nothing else. In addition adding shift registers doesn’t make any progress.

John P, about your first way by explicitly start/stop the CO task when needed in accordance with the value from the AI channel, how can I do that? That is my main target! About the second way, the Pause Trigger is the DAQmx Trigger and applying the Boolean result of Basic Level Trigger Detection backwards of the While Loop? Please, could you make any change in my vi and send me back? Best Regards 

Greg

0 Kudos
Message 4 of 6
(7,184 Views)

Hi Greg,

 

Here's a small example showing one way to implement the counter portion.  It just starts or stops the task in the loop depending on the value of the boolean control--it also keeps track of the current state of the task so it can avoid starting the task multiple times which would result in an error.

 

You can try it out independently and then integrate it into your own code by removing the Enable button and wiring the result of the comparison function from your Analog Input.

 

 

Best Regards,

John Passiak
0 Kudos
Message 5 of 6
(7,164 Views)

Hi John!

 

 Thank you very much for your kind help! Your vi sent me works perfect as a base into my main problem! For one more time I express you my deepest regards!

 

 With best regards from sunny Hellas  Smiley Happy

 

 Greg

0 Kudos
Message 6 of 6
(7,142 Views)