Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

vbnet counter input channel read

The connection is via ethernet.

So now that I am able to actually get values, how do I go about determining which type of values to get?

I want to determine position, my encoder does 20,000 ticks per rev or ppr. I want to determine where the encoder is in ticks using the counters.

So I set the the pulse generation example per your instructions and the Buffered Angular position example also per your instructions.
This is giving me values, but I now need to know if they are the values that I want.

So because I want ticks, do I need to generate tick instead of a time cycle?
    If not, how do I determine how many hz I want to generate?
    Either way, would I set up the angular example to look for 20000 pulses per revolution?
   
So the 6052E card can take a maximum sampling of 333K x sec (1 analog channel), how do I configure the settings to determine where my encoder is positioned for each of those samples collected? - This is my end goal...

Thanks again for your patience and assistance,
CM


0 Kudos
Message 11 of 35
(2,550 Views)

Hi Chris,

If you want ticks you could set up your encoder task like so:

myTask.CIChannels.CreateAngularEncoderChannel(counterComboBox.Text, _

"", encoderType, zIndexEnable, zIndexValue, encoderPhase, pulsePerRev, _0.0, CIAngularEncoderUnits.Ticks)

If you use degrees, it will take the 20,000 as the pulse per revolution and calulate that each tick is 360/20000, and return the resulting degrees. If you want the counter readings to be correlated with your AI samples, you're going to need to find a way to share some timing signals between the AI card (6052e) and the counter (6602). If you're in a PXI system, you can just share over the backplane. If you're in a PC, you'll need a RTSI cable, or a trigger to start both acquisitions off of. There are a few options.

With PXI/RTSI, you can use the AI sample clock from the 6052E as the sample clock source for the angular position measurement. For each AI sample, you will get the position. You may not be able to do buffered event counting at 333 kHz - the counter input has a tiny buffer and probably will not be able to run at that rate. You may have to tweak the acquistion rate.

Depending on how tight of synchronization you need, instead of using a RTSI connector you could use a start trigger and start both acquistions (AI and CI). For the counter, you would want to use an arm start trigger - 

myTask.Triggers.ArmStartTrigger.ConfigureDigitalEdgeTrigger(source, DigitalEdgeArmStartTriggerEdge.Rising);

For the AI you would just use a start trigger - check out the ContAcqVoltageSamples_ExtClkDigStart example, but specify the onboard clock (for some reason we dont have an internal clock example). This would start both acquisitions at the same time. This would give you the advantage of being able to control the Counter's clock independent of the AI sample clock. You could use another counter to generate a pulse train at a divide down of the AI sample clock - so for every 10th or 4th ai samples you would get a position measurement. This would be good synchronization, but the trigger delays could introduce a little bit of constant delay.

Hope this helps,

Andrew S  

 

Message Edited by stilly32 on 05-02-2007 05:42 PM

0 Kudos
Message 12 of 35
(2,542 Views)
Andrew,
Thanks for your reply. I have tried your suggestion, but have had some problems implementing it.

Yes, I found that I could switch the encoder units to ticks, but I wasn't getting the values back out of the Counter Input that match my 20000 ppr. So I didn't trust the reading.
I am not sure I understand how to set up the counter channel to generate a pulse that will syncronize up everything so that I can determine what is happening at a specific point in time.

Any further explanation of the pulse generation would be helpful on how to match it to what I am doing with the encoder.

As to syncing the samples,
In my AITask I am
stopping a task that might have been running (aitask.control(stop))
setting the timing as such( aitask.timing.configuresampleclock( "pfi24", 1000, rising, continuous, 1000))
and set the trigger  aitask.trigger.starttrigger(configuredigitaledgetrigger("pfi24", rising)
verifying (aitask.control(verify)

in my Counter Inputs
stopping task
setting the armtrigger (citask.triggers.armtrigger.configuredigialedge("pfi24", rising)
verifing task

the counter output channel (pfi24) or channel 3 on the 6601
is set to
duty cycle = .9999
frequency = 1000
initial delay = 0
idlestate = low
samplequalitymode = continous samples
samples per channel = 1000


I have a routine that when I want to start, I call it and it starts my tasks. The counter input times out.

So have tried to point everything back to the counter output channel (not sure why that wouldn't work...). I have the same setting everywhere, I am generating a signal, the counters timeout (I think that the armstarttrigger, never gets started, but I don't see in the documenation how to start it after it is armed.) If the armstarttrigger is waiting for a sensor to tell it to go, then I am using the wrong thing. i want to just use the software to tell it to go.

I haven't been able to tell why you use one trigger over another?

Any enlightenment would be appreciated,
CM
0 Kudos
Message 13 of 35
(2,533 Views)

Hi,

In resonse to some of your questions:

"...I wasn't getting the values back out of the Counter Input that match my 20000 ppr. So I didn't trust the reading."  - what kind of reading were you getting? If you use the Angular position example clocked with the pulse train generation example and move your encoder half a turn, what value do you read? One thing to note, if you're using X4 encoding and read in ticks, the reading will be 4 times what you would expect.

"I am not sure I understand how to set up the counter channel to generate a pulse that will syncronize up everything so that I can determine what is happening at a specific point in time." - You just need to generate a continuous pulse train. This pulse train will be used as a clock, for both your AI and your counter reads. One thing to note, you should start both the AI task and the Counter Input Task before you start the counter generation task (clock). That way, both tasks are waiting on the clocking signal before they start acquiring. If you use a shared clocking signal like this, you don't need to worry about triggers - both will wait on the clock so this will simplify your code.  

Please try this and post back.

Andrew S

 

Message Edited by stilly32 on 05-07-2007 06:40 PM

0 Kudos
Message 14 of 35
(2,511 Views)
Hello,

The values I wasn't getting out of the Couter Inputs might have been fine, but since the number of samples differed from the number of samples I was getting out of my Analog Inputs, this is why I didn't trust those numbers.
    So if I have the sample configured as mytask.cichannels.createangularencoderchannel("dev2/ctr0", "", x4, false, 0, ahighbhigh, 20000, 0, ticks)
        and the sample clock set as mytask.timing.configuresample.clock("/dev2/pfi24", 1000, rising, continioussamples, 1000)
        and the generator set to "dev2/ctr3" with a freq of 1000 and duty cycle of .999
I get a count of 20000 for an approx full rotation by hand of my encoder (that is what I should see, correct?)

I modified my code to make sure that the AnalogInputs, then the CounterInputs were configured and started before the CounterOutput was started. This did produce the same number of samples for both the Analog and Counter Inputs. Yea!
    Can you tell me what the Minimum/Maximum - Frequency/Samples per channel I can have is using this pulse train?
    Do I need to set the task = nothing and recreate before I can make changes to frequency or samples per channel settings?

If I wanted to take 1 sample every 10 minutes, would I have to adjust the pulse train output or the analog and counter inputs?

If a task errors out for any reason, does the task recover gracefully or does it need to be destroyed and recreated?

Thanks again,

cm



0 Kudos
Message 15 of 35
(2,500 Views)
Hi Chris,
 
You should see ~20,000 ticks for a full revolution. Thats great that the AI and Counters are now synch'ed, we've come a long way since the original post. For your questions:
 
Can you tell me what the Minimum/Maximum - Frequency/Samples per channel I can have is using this pulse train? The max is going to be limitted by your buffered counter operation. The counters have a 2 sample fifo which will overwrite and throw an error if your system cannot pull samples fast enough. This rate is system dependent, with my m-series card I got an error just below 100k. If you need to take your AI at a higher rate we caould take counter samples at a divide down of the AI sample rate, let me know if you need that. The min rate is on the order of hour, check out the 6602 Specifications . One limitation will be the timeout in the AI and CI reads - the default is 10 seconds.

Do I need to set the task = nothing and recreate before I can make changes to frequency or samples per channel settings? - you can change the frequency of your counter output on the fly (without stopping/starting the task). You can either set the rate using a Write or by setting the property -

myTask.COChannels.All.PulseFrequency = 5000

I wanted to take 1 sample every 10 minutes, would I have to adjust the pulse train output or the analog and counter inputs? If you wanted to just take a sample every 10 minutes, I would consider creating another task for single point reads and just use Windows timing to control when the acuisition takes place. As long as you don't have both tasks (the single point and the HW timed AI and CI) running at the same time, you can have both configured and ready to run. You can start and stop each task without reconfiguring as long as you dont clear/dispose of the task.
 
If a task errors out for any reason, does the task recover gracefully or does it need to be destroyed and recreated?-  if the task errors out due to a bad setting, then you'll want to reconfigure the task to the correct settings. If it's due to a HW error, then you can start the task right back up again but it will probably throw the error again, unless it was caused by an OS event (ie opening a new program which interupts a data acquisitions and causes a buffer to overflow).
 
Hope this helps,
Andrew S

0 Kudos
Message 16 of 35
(2,490 Views)
Andrew,

The channels do now appear synced.
       I am currently starting and starting/stopping my data collection using a button. I start my pulse train and then start doing asyc reads to gather my data. When I stop, I stop the pulse train and I almost always get an error from the counter channel saying that it timed out getting a sample. Error 200284 Same or all of the requested samples  have not yet been aquired.

      I have noticed that if I have an 2 of the 3 counter input channels enabled, the second one complains if the configure timing is set to use continuoussamples for both. Error 200251, not DMA or USB bulk endpoints, this only seems to happen if using async multiplesample reads. Non async reads do not seem to be affected...

     When I finish a test, should I stop the tasks, before I stop the pulse generator, does it matter?
     Should I be using continioussamples as the sample quality mode?

    If I configre an analog task and don't set the timing, I am assuming that it is using its internal clock, is that correct? Is that sycronized in any way to the counter card (I have a RTSI cable connecting the two cards and I can that both devices are connected in the max display).

     I don't understand how to input the current angle when I create a counter input angular channel. createangularencoderchannel("dev2/ctr0", "", x4, false, 0, AhighBhigh, 20,000, ?, ticks) I have tried putting back in the last value I got out and tried to take my current postion x 20000 and put that in, niether appeared to work correctly. How is this determined?

    Currently I have everything configured the same way, timing, samples, same sampleclock etc... Should I configure things differently?
    If I change the freq of the pulse generation, do I need to modify the timing rate of the other analog and counter input channels that also have the previous timing configuration? If not will I start missing samples?

    Yes, I like to know how to divide it properly - doesn't seem like I get get much faster than 1000 freq and 1000 samples per second otherwise.

Thanks again,
CM

 

0 Kudos
Message 17 of 35
(2,487 Views)

Hi,

For error 200251, check out this KB - Error -200251, No DMA Channels Available, When Using Multiple Counters. You can find this by searching for "200251" from www.ni.com.

For the rest of these:

When I finish a test, should I stop the tasks, before I stop the pulse generator, does it matter? - You'll want to stop the acquisitions before your clock, otherwise you'll stop latching in values, which can result in error 200284.

Should I be using continioussamples as the sample quality mode? - If you don't know how many samples you want to acquire, you'll want to use continuous. If you have a predetermined set amount of samples you want, finite would be easiest.

    If I configre an analog task and don't set the timing, I am assuming that it is using its internal clock, is that correct? Is that sycronized in any way to the counter card (I have a RTSI cable connecting the two cards and I can that both devices are connected in the max display). - If you don't configure timing at all, I believe it defaults to a 1 Khz rate with an internal clock. If you use the configure timing, set the rate and don't specify a source it will use the internal AI Sample clock.  

For your starting postion, this should just be in terms of ticks. If your encoder has a Z index, you could also make use of that. 

If I change the freq of the pulse generation, do I need to modify the timing rate of the other analog and counter input channels that also have the previous timing configuration? If not will I start missing samples? - You don't need to change the rate and you won't miss samples. When using an external clock (a clock other than the AI sample clock) you are effectivly onlt influencing the Buffer size. Check out the "How is Buffer Size Determined" section of the DAQmx Help for more info on this.

Yes, I like to know how to divide it properly - doesn't seem like I get get much faster than 1000 freq and 1000 samples per second otherwise.

The easiest way to do this is to use the AI sample clock for the AI task. For the counter task, use a divide down of the AI Sample clock as the clock for the Counter input. The Divide down is generated from another counter output task. For example, from the counter generation example that we've been using, create a ticks channel instead of a frequency channel:

myTask.COChannels.CreatePulseChannelTicks()

and use the AI Sample clock as the "Source Terminal" - this will get automatically routed across the RTSI line. The Ticks will control how large the divide down is.

Hope this helps, 

Andrew S 

0 Kudos
Message 18 of 35
(2,479 Views)
Hey Andrew,

Error 200251 - LabWindows/cvi or labview vi (I don't think I have either of these). Can I change this property setting via Max or some other way?

So if the AI is configured without timing, does that syncronize in any way with my counter channel? As in if run continous samples for 30 seconds at 10,000 samples per second, with the counter on and counting, but the AI isn't tied to the pulse train. Is there any internal correlation to the AI samples returned in relatioon to the counter samples returned or are these completly independently returning samples even though they are connected to each other via the RTSI cable?

Z Channel, do I need to use that? If I just put in ticks that are output back in if I re-create the channel, I should be at the same position, correct?

So in order to divide down, then I would need to sacrifice another counter channel to keep track of the division count between AI sample clock and the pulse train count? Am I interpreting this correctly?

Thanks again,
CM
0 Kudos
Message 19 of 35
(2,463 Views)

Hi,

You can change the transfer method to IRQ in .NET - check out some of the links in the KB I referenced.

Signals are not synchronized across the RTSI cable unless you explicitly route them - ie use AI sample Clock from your MIO card as the source on a counter task on your 6601.

Z channel will give you the zero point on your encoder. If you specify the "initialAngle" in your create counter task, the units should be in the units you specify (ticks or degrees). So I have a 24 ppr encoder. I give it an initial angle of 12, and my units are in ticks. Any movement on the encoder counts up/down from that position. What behavior are you seeing?

You would need to use a counter to divide down your AI sample clock, just as you are using a counter to generate a clock for both right now.

Andrew S 

Message Edited by stilly32 on 05-17-2007 02:30 PM

0 Kudos
Message 20 of 35
(2,441 Views)