From: Ben on 2 Mar 2010 13:25 so far as i can tell, the DAQ toolbox does not support callbacks (or interrupts, whatever you want to name them) to monitor the value of a digital input line. NI-DAQmx seems to do so though, with its "Change Detection Event", as detailed here: http://zone.ni.com/devzone/cda/tut/p/id/4102. can anyone confirm the lack of this feature in matlab? must i really stoop so low as to write a while loop which polls a bit?
From: Gautam Vallabha on 4 Mar 2010 09:43 "Ben " <bja28(a)cornell.edu.removethis.com> wrote in message <hmjl6h$5i$1(a)fred.mathworks.com>... > so far as i can tell, the DAQ toolbox does not support callbacks (or interrupts, whatever you want to name them) to monitor the value of a digital input line. NI-DAQmx seems to do so though, with its "Change Detection Event", as detailed here: http://zone.ni.com/devzone/cda/tut/p/id/4102. can anyone confirm the lack of this feature in matlab? must i really stoop so low as to write a while loop which polls a bit? I don't think digital change detection is supported in Data Acquisition Toolbox (as of R2009b). However, don't stoop to writing a while loop just yet ... there are a couple of alternatives: Option 1) Use a timer function to periodically check the state of the digital input, e.g., di = digitalio('nidaq','Dev7'); addline(di,0,'in') di.TimerPeriod = 0.1; % call TimerFcn every 0.1 seconds di.TimerFcn = @myTimerFcn; start(di); % -------------------- function myTimerFcn(obj, eventdata) persistent lastInput if isempty(lastInput) lastInput = 0; end currentInput = getvalue(obj); if (lastInput ~= currentInput) disp('hey, something happened!'); end lastInput = currentInput; % -------------------- Option 2) Feed the digital input into an analog input channel, and set up an analoginput trigger for values > 2.2 (logical 1), or values < 1.5 (logical 0), assuming 0 - 3.3V TTL levels. Gautam
From: Joost on 1 Apr 2010 13:56 Hi, I just did the same thing (trigger an event on digital input), using a while loop: it works perfect and it's very easy! Why do you think it's better not to use while loops? thanks, Joost
From: Gautam Vallabha on 5 Apr 2010 10:58 "Joost " <jmaier(a)brandeis.edu> wrote in message <hp2mnk$9qm$1(a)fred.mathworks.com>... > I just did the same thing (trigger an event on digital input), using a while loop: > it works perfect and it's very easy! Why do you think it's better not to use > while loops? There is nothing intrinsically wrong with WHILE loops -- it's just that they tie up MATLAB, so you can't do anything else while waiting for your digital events. For example, you might want your program to run some analysis while also counting the number of digital events received. Or, you might be waiting for two separate digital events, where event 1 should invoke a long-running function1 and event2 should invoke function2. Gautam
|
Pages: 1 Prev: Report Generator IO Documentation Next: Report Generator IO Documentation |