01-13-2011 01:55 PM
I am trying to use an NI-USB-6221 to implement SPI in a C++ application. When I try configure a digital output task that uses ctr0 as the clock I get an error indicating that 'Sample Clock' is not supported and to use 'On Demand' instead. Should I be able to use the NI-6221 and if so how do I get around this? Thanks.
Solved! Go to Solution.
01-13-2011 07:02 PM
Hi IntAndTest,
Yes, the USB-6221 supports correlated DIO on port0. Are you using port1 or port2? If that's not the problem, please post some code to show what you have already tried.
Brad
01-14-2011 06:34 AM
I am trying to use port 0. When I call
DAQmxCfgSampClkTiming(m_SPIDOTaskHandle,
"Dev1/Ctr0InternalOutput",1000.0,
DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1)
I get
DAQmxCreateDIChan failed line 206 with error -200077, 'Requested value is not a supported value for this property.
Property: DAQmx_SampTimingType
You Have Requested: DAQmx_Val_SampClk
You Can Select: DAQmx_Val_OnDemand
Task Name: DO
Status Code: -200077'.
The code is below:
strName = "CO";
if ((nDAQMxError = DAQmxCreateTask(strName,&m_SPICOTaskHandle)) < 0) {
}
if ((nDAQMxError = DAQmxCreateCOPulseChanFreq(m_SPICOTaskHandle,"Dev1/ctr0",
"",DAQmx_Val_Hz,DAQmx_Val_Low,0.0,1.00,0.50)) < 0) {
}
if ((nDAQMxError = DAQmxCfgImplicitTiming(m_SPICOTaskHandle,DAQmx_Val_ContSamps,1000)) < 0) {
}
strName = "DO";
if ((nDAQMxError = DAQmxCreateTask(strName,&m_SPIDOTaskHandle)) < 0) {
}
if ((nDAQMxError = DAQmxCreateDOChan(m_SPIDOTaskHandle,"Dev1/port0","",
DAQmx_Val_ChanForAllLines)) < 0) {
}
if ((nDAQMxError = DAQmxCfgSampClkTiming(m_SPIDOTaskHandle,
"Dev1/Ctr0InternalOutput",1000.0,
DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1)) < 0) {
}
I also get this error when I try to use MAX and set 'Generation Mode' to anything other than '1 Sample (On Demand)'.
Thanks for the help.
01-14-2011 05:30 PM - edited 01-14-2011 05:31 PM
Hi Int,
It looks like that error is being generated because of the way you are configuring your sample clock timing (DAQmxCfgSampClkTiming). You pass the parameter "DAQmx_Val_FiniteSamps", which means you will not be able to output this pulse train iteratively unless you trigger it somehow. The program will only generate one pulse train for every trigger it receives (whether it be a hardware trigger or a software trigger). If you are looking to do this iteratively, you need to do look into retriggerable operations.
The other side of the coin is if you're looking to simply output a pulse train, and you want it to keep sending the pulse train regardless of what else is going on.
Here is one example you may want to look into if you are looking for triggering:
<...National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Generate Pulse\Dig Pulse Train Cont-Pause Trig>
Here is another example that is just a continuous digital output.
<...National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Generate Pulse\Dig Pulse Train-Cont>
Your DAQmx C Reference Help is your best friend when finding explanations for these functions. You can find it by going to Start>>All Programs>>National Instruments>>NI-DAQ>>Text-Based Code Support>>DAQmx C Reference Help. The descriptions of some of these functions explains how they are used. For example, for the error you were getting, under the DAQmxCfgSampClkTiming description, it distinguishes Finite versus Continuous Samples:
DAQmx_Val_FiniteSamps Acquire or generate a finite number of samples.
DAQmx_Val_ContSamps Acquire or generate samples until you stop the task.
This is why the DAQmx driver is looking for an "On Demand" parameter in the DAQmxCreateDIChan function. I'm assuming you may want to look more into Pause Triggering--but let me know if I'm off-basis here.
So to step back a bit--which are you trying to work with? A pulse train generated by some sort of trigger (hardware or otherwise) or a continuous pulse train output?
-Andrew
01-18-2011 09:49 AM
Thanks for the help. I am trying to implement a SPI bus master as described in the 'Serial Protocol Communication Reference Design for Digital Waveform Devices' (http://zone.ni.com/devzone/cda/epd/p/id/6200) and the 'SPI Digital Waveform Reference Library' (http://zone.ni.com/devzone/cda/epd/p/id/6163) tutorials using the NI-6221 and the DAQMx C api instead of LabView.
The 'Serial Protocol' document describes a SPI implementation for a 62xx device:
The runtime sequence of function calls is nearly identical, except that the CO task must also be managed alongside the DI and DO tasks:
I am trying to implement this using ctr0 as the oversample clock to trigger the discrete input and output tasks. That is what I am trying to do in the
DAQmxCfgSampClkTiming(m_SPIDOTaskHandle,
"Dev1/Ctr0InternalOutput",1000.0,
DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1)
call. I want the DO task to write 1 sample from the wavefrom buffer on the rising edge of the oversample clock, but I can't get past the 'On Demand' error.
I haven't been able to find any C examples of the 'Serial Protocol' document implementation, so I am trying to piece it together. What do you think is happening or what would be a better implementation.
Thanks for your time.
01-18-2011 11:19 AM - edited 01-18-2011 11:20 AM
Hi IntAndTest,
Possibly silly question: are you sure you have a USB-6221 and not a USB-6212? The USB-6221 supports clocked DIO, but the USB-6212 does not.
One problem with your code: when you specify a DAQmx terminal name, it must be either relative to the device (like "Ctr0InternalOutput", "ai/SampleClock", or "PFI0") or contain a slash before the device name (like "/Dev1/Ctr0InternalOutput", "/Dev1/ai/SampleClock", or "/Dev1/PFI0"). This does not apply to physical channel names (like "Dev1/port0" or "Dev1/ctr0").
Is the error returned from code that you haven't posted? Your error message says DAQmxCreateDIChan failed, but the code you posted doesn't call that function. Also, I don't see a call to DAQmxWriteDigitalU8/U16/U32/whatever or DAQmxStartTask.
Also, what version of NI-DAQmx are you using?
Brad
01-24-2011 11:04 AM
Instead of a NI-6221 I have a NI-6212. In some other thread there was an indication that the NI-6212 does not support correlated IO. Is this true? Is this why I am getting the sample clock is not supported error message?
Thanks.
01-24-2011 11:28 AM
That's right, the USB-6212 does not support correlated DIO. The USB-6221 specifications list Digital I/O >> Timing: Hardware, Software. The USB-6212 specifications list Digital I/O >> Timing: Software. This is why you get the sample clock not supported error: to use a sample clock, the device must support hardware timing.
Brad