Jump to content

Read counter on signal change of digital input - DAQmx


Wim

Recommended Posts

Hi LAVA,

I need some help.

I have a motor that moves a tray.

During the movement of the tray, 2 switches will change value.

I want to read out the counter value / motor position when the signal of the switches changes. (rising and falling edges)

At this moment the only thing I can think off is a loop vi that reads the value of the swicthes and motorposition and evaluate the swicth states... But i'd rather have the position reading triggered by the digital lines.

I'm running LV2010SP1, DAQmx 9.4

Hardware:

cDAQ chassis: 9178

NI 9401 module => encoder signals are connected to this one.

NI 9403 module=> 2 digital inputs(so the switches) are connected here.

Thanks in advance for your help.

Best regards,

Wim

Link to post

I'm not familiar with those modules, but I would suggest looking at the DAQmx Timing VI(Change Detection). Using the switches as your source, you should be able to acquire the motor position when the switches transition. I have done what with USB-63xx series.

Link to post

Have a look at DAQmx Trigger, you probably want to use the Reference Digital Edge mode. You may need to have trigger lines on the same card as the counter task, but even if you're using quadrature encoders you should have a couple lines left over on the 9401.

Link to post

Can't say I know the hardware, but I just finished an application that had to do much the same, only I was doing an SPI read rather than an counter read after a digital edge is received.

All I can say is I had zero luck with any form of digital edge detection in DAQmx (the mode where you set up an event structure to get signaled upon a digital edge transition). Everything seemed to work as no errors would ever be generated, but nothing would ever cause my blocked code to wake up. The example VI didn't work either. I'd watch the pulses go by on my scope, meanwhile the DAQmx driver was on a coffee break or something. I know the mode works though, as I have used them in the past, all I can say is there seems to be something going on where some hardware just silently refuses to work in this mode. This was on an X-series USB device for what it's worth.

I could poll the line and things would work...

Ultimately I ended up configuring the digital line as a clock source for a timed event structure and I do the read when the loop wakes up. No idea why the digital edge can be detected as a clock source but not a digital edge. Maybe it's just not...edgy enough? One of those mysteries of the NI universe I guess.

/shrug

Link to post

Hey Wim,

Definitely using the digital input as a clock is easiest. Don't think it will do rising and falling edge natively though but I remember seeing schematics for a basic circuit which can take care of this.

Cheers,

James

(null)

Link to post

All,

thanks for the help.

My customer does not allow any hardware changes at this point because it is a shared system and a polling implementation gave good results so far... so i just keep the polling method for now.

Cheers,

Wim

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By paulofelora
      I have a requirement that I thought would be SIMPLE, but can't get it to work.  I have a 9205 card in a little 9174 cDAQ USB chassis.
      My *intended* behavior is to wait (block) at the DAQmx Trigger/Start Analog Edge on, say channel ai1, until I get a falling edge thru, say, -0.050V.  So I have a little vi (that contains 2 parallel loops) that I want to sit & wait for the trigger to be satisifed.  I'm doing "routine" voltage measurements in another AI loop on a different channel.  I want this vi to run separately from my "routine" voltage measurements because I want the app to respond "instantly" to input voltage exceeding a limit to prevent expensive damage to load cells.  I was afraid that if I used either Finite or Continuous sampling to "catch" an excessive voltage, I might miss it while I'm doing something else.  Yes, yes, a cRIO real-time setup would be better for this, but this is a very cost-sensitive task... I just want to "Arm & Forget" this process until it gets triggered, whereupon it fires an event at me.  SO... I'm also reading the same voltage on channel ai0 for regular-ole voltage measurements, and just jumpering them together.  I did this because I read somewhere that you can't use the same channel for multiple DAQ tasks - I *thought* I would need to set up the tasks differently.  {but now that think about it, the setups can be the same...}.
      I've set up the DAQmx task the same as shipping examples and lots of posts I've seen.  I'm supplying a nice clean DC voltage to a 9205 card using a high quality HP variable power supply.  Using NI-MAX, I've verified that my 9174 chassis & 9205 are working properly.
      THE PROBLEM - When I run it, the vi just sails right through to the end, with no error, and an empty data array out.  No matter WHAT crazy voltage I give the "DAQmx Trigger.vi" (set up for Start Analog Edge), it never waits for the trigger to be satisfied, just breezes on through as if it weren't there.  If I set the Sample Clock for "Finite Samples", the DAQmx Read fails with timeout - makes sense, since the trigger wasn't satisfied.  What could I possibly be doing wrong with such a simple task???????
      So my fundamental misunderstanding still vexes me - does the DAQmx Trigger vi not block and wait for the trigger condition to be satisfied, like the instructions state - "Configures the task to start acquiring or generating samples when an analog signal crosses the level you specify"?
      I stripped my requirement down to the bare essentials - see the 1st snippet, the 2nd is my actual vi.  Any ideas, anybody?


    • By roberto1719
      Hi Everyone!
      I started with LabVIEW in last year. I have a short question for you with my little trouble. In first of all my VI must counting up and down in the range 45 to 145. On first program step, two case structures will stop count, if we get number out of range. In case of we writes a good number, last procedure will launch counting from zero to number on input, but I want to start incresing/decreasing from last number on output not from zero like in this case. Have anyone problem like me ever? Thanks for respond and support.

      http://fotowrzut.pl/STCFT0EJXI
    • By neunited
      Dear All, 
      I'm new to this forum and I'm really glad I became a member.
      I am currently in the phase of designing a simple program which can control all the DAQmx channels using a configuration file (.ini) which is capable of change voltage range during mid-simulation. 
      At the moment my .ini file reads as follows: 
      [AO Channel 1] 
      Name = T2
      Physical Channel = cDAQ1Mod1/ao0
      Max Value = 10 
      Min Value = 0 
      [AO Channel 2] 
      Name = T3
      Physical Channel = cDAQ1Mod1/ao1
      Max Value = 10 
      Min Value = 0 
      [AO Channel 1] 
      Name = T2
      Physical Channel = cDAQ1Mod1/ao0
      Max Value = 5 
      Min Value = 0 
      [AO Channel 2] 
      Name = T3
      Physical Channel = cDAQ1Mod1/ao1
      Max Value = 10 
      Min Value = 0 
      My LabVIEW VI for the .ini script  is attached. I'm relatively new to using configuration file functions and I don't really understand where "Get Key Names" section should be wired to. I have placed a constant on it for now which reads the "AO Channel 1" but how can I get it to read all the channels in the .ini file.
      I am welcome to all suggestions here, I just want to make sure that I don't cause any problems to any of the channels and use best practice methods. All constructive criticism welcome!
      Thank you. 
       
       

      Read Configuration (INI) File (1).vi
    • By A Scottish moose
      Hello all,
      My question is: what is your preferred non-volatile way of storing daqmx task configurations? 
      Backstory: For a long time I've used ini files to maintain task configurations between executions of a program. This has worked for primarily static DAQmx configurations but I'm looking at creating a test executive with some degree of flexibility, which means daqmx task configurations start to get more complicated.
      If you use MAX for storing your tasks:  Do you run into problems accessing and maintaining these tasks even though you don't have direct access to the file?  Or is there an unlisted storage location for these files?
      If you use ini/text based files:  How do you keep things orderly?  I'm running into all kinds of limitations with the format.
      If you use XML: Where did you find your schema?  Did you write it?  I know NI saves tasks as XML files, and so therefore the schema exists, but I haven't been able to figure out how to use it.  I've created a task in my project and then dug through the XML of the project to find the attached image.  I believe this would be the ideal solution, but a little bit of digging in around NI.com (I know...) and google (actually useful) has resulted in no answers.
       
      I know there is an elegant answer to this question, I've just not found it yet.  Thanks in advance for your comments. 
       
      Cheers,
      Tim M


    • By cpipkin
      Hello,
      I'm using the 9229 and borrowed a community example to log 4 voltage inputs to TDMS. I need to output RMS voltage on channels 1&2 and the wavform on channels 3&4.
      Essentially what I've done is averaged channels 3&4 using the same # of samples that the RMS is averaged, that way I'm able to make sure they are time synchronized (see code attached). Another advantage doing averaging the samples is that I am reducing the amount of data to analyze later.
      When i compare the TDMS read results to the # of samples in the TDMS file there seems to be a discrepancy in time. I tried to add a time stamp to the logged TDMS file but couldn't get it to work. besides using time stamps, Is there an easy way to confirm that I am saving all of the data I am capturing? Eventually i will be logging data at 30min-40min intervals so I want to make sure that i'm not losing data.
       
      TDMS_Logging_Simple_4chan.vi

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.