Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Unusual counter output

Hi all,

 

I'm using a PCI-6221 to generate two pulse trains to control two servos. The servos I'm using are Futabo servos and work off a 1.5 millsecond high pulse, followed by a 20 millisecond low signal. The position of the servo is defined by expanding or reducing the high pulse by 0.5 milliseconds-1 millisecond is fully left, 2 milliseconds is fully right.  I can generate one channel quite easily using my code below, but I am now trying to expand this to control two servos. When I simply copy and paste my code, Instead of getting a constant pulse on the two output channels, the code gives me three high pulses on one channel, followed by three on the other, causing havoc with the servos. I know I should be able to generate two pulse trains using this card, they aren't finite, they are user halted. I've tried all sorts of codings, using case structures, loops and timed sequences, but I always get the same (rather odd) oscilloscope readings. I am fairly sure the card is ok, as the channels work fine independantly.

 

Thanks for your help in advance!

 

Ed.

0 Kudos
Message 1 of 6
(4,596 Views)

Ed,

 

If you just copy and paste you will end up with two differenct counter tasks that fight each other.  You need to create a single task that contains both counters.

0 Kudos
Message 2 of 6
(4,557 Views)

Hey Ed,

 

You're right, with continuous pulse trains you shouldn't have a problem and usually if the HW is bad counters won't work at all.  I'm not sure that I understand the issue though - do the channels just stop generating? If you can grab a screenshot or draw up a timing diagram it would help, I usually end up at a whiteboard when talking about counters. With two counters in parallel, they will start at different times unless you use a start trigger - is this causing the problems? Can you include your completed code so we can test it out?

 

thanks, 

 

Andrew S

0 Kudos
Message 3 of 6
(4,554 Views)
Hi guys, thanks for your help so far. The counters do not have to be synchronised, as they are running independant servos. The code that I was using is below, Is the problem that the code is using the same counter and outputting it to each channel in turn? That is the only explanation I can think of. I'll try and catch a screenshot of the waveforms, at the moment I'm using an external scope, the image I get is attached (although very quickly drawn in paint!).
0 Kudos
Message 4 of 6
(4,546 Views)
Sorry, here is the code.
0 Kudos
Message 5 of 6
(4,545 Views)

Ed,

 

You have gaps in the pulse train because you are doing all the task overhead inside the loop.  You are creating, starting and clearing the task every iteration of the loop.  Code needs to look more like the first vi you posted that had the overhead stuff outside the while loop.

0 Kudos
Message 6 of 6
(4,532 Views)