09-23-2009 03:38 AM
09-23-2009 05:08 AM - edited 09-23-2009 05:16 AM
whitenoiz wrote:
... my ChangeDetectionCallback goes off several times ...
Does it go off while the drawer is stationary or while it is being pulled out/pushed in?
If the latter is true, it may be so due to switch debounce.
But anyway, it should give a correct value after the drawer switch is completely opened/closed.
Do you get the sporadic -200284 error from your code, from the sample or both?
Use DAQmxGetErrorString to see the explanation. Did you take that message into account?
There is no trigger/timing related calls in your DAQmx code. Maybe you should add?
Did you try using NI-MAX's sample panels? How do they behave?
09-23-2009 05:59 AM
>Does it go off while the drawer is stationary or while it is being pulled out/pushed in?
The ChangeDetectionCallback() is called due to interference caused by measurements running in parallel on our external board, not by drawer movement. Verified that with a scope.
>But anyway, it should give a correct value after the drawer switch is completely opened/closed.
You are right, that's what I would expect, too and that's actually my problem here. The value detected in ChangeDetectionCallback() does not correspond to the drawer position, while the DAQmxReadDigitalU8 is identical to the DAQmxReadDigitalU8 in is_drawer_open(), which works reliably.
>Do you get the sporadic -200284 error from your code, from the sample or both?
Mostly from the sample in ChangeDetectionCallback(), however now I haven't seen it for a while.
>There is no trigger/timing related calls in your DAQmx code. Maybe you should add?
That's the actual code I use to register the ChangeDetection:
DAQmxCreateTask("BackgroundSwitchMonitor",&gTaskHandle));
DAQmxCreateDIChan(gTaskHandle,latchChan,"",DAQmx_Val_ChanPerLine));
DAQmxCfgChangeDetectionTiming(gTaskHandle,latchChan,NULL,DAQmx_Val_ContSamps,1));
DAQmxRegisterSignalEvent(gTaskHandle,DAQmx_Val_SampleCompleteEvent,0,ChangeDetectionCallback,NULL));
I tried something like
DAQmxCfgDigEdgeStartTrig(gTaskHandle,"/Dev3/PFI0",DAQmx_Val_Rising));
DAQmxCfgSampClkTiming(gTaskHandle,"",10,DAQmx_Val_Rising,DAQmx_Val_HWTimedSinglePoint,1));
was not successful however. What would be a valid trigger/timing in my case? Can I trigger on port0/line0 which I'm also trying to measure afterwards? The NI example sure did let me do ChangeDetection and measurement on the same line without any errors. I'm lacking a bit of experience here.
> Did you try using NI-MAX's sample panels? How do they behave?
Just like NI's "single-shot" examples they behave well. However my overall program "architecture" registers the above ChangeDetectionCallback() at the start of a callback routine that reacts to a "Run" button and applies various voltages/states to the Voltage Converter followed by analog measurements. So ChangeDetectionCallback() goes off in parallel to analog data acquisition which runs in a separate (long running) callback. Not to mention Multithreading issues that may arise here...
Thanks for your input so far.
09-23-2009 06:10 AM
Of course, you must use port0/line0 both for triggering and reading.
What's the point in triggering from another -PFI0- line?
Is it connected to the switch also? If it is a floating pin, it sure will fluctuate.
09-23-2009 08:03 AM
>What's the point in triggering from another -PFI0- line?
/port0/line0 never showed up in code completion so I gave PFI0 a shot. No matter which one I use, I get error 200452 saying this property cannot be set with this task or my 6220 board. This is how I currently try to set it up:
DAQmxCfgDigEdgeStartTrig(gTaskHandle,"/Dev3/port0/line0",DAQmx_Val_Rising));
DAQmxCreateTask("BackgroundSwitchMonitor",&gTaskHandle));
DAQmxCreateDIChan(gTaskHandle,latchChan,"",DAQmx_Val_ChanPerLine));
DAQmxRegisterSignalEvent(gTaskHandle,DAQmx_Val_SampleCompleteEvent,0,ChangeDetectionCallback,NULL));
Still it would be far more appealing to read the line properly in the ChangeDetectionCallback...
Thank you.
09-23-2009 03:38 PM
Is this the true order function calls in your code?
If yes, then your task handle is invalid.
You should use DAQmxCfgDigEdgeStartTrig after you create the task.
If you are using PFI for triggering you have to connect it to the switch output also along with port0/line0.
On top of all your hardware has to support the trigger-on-change capability.