Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I implement SPI using the NI-6221? When I try to generate DO using ctr0 I get an error indicating that 'Sample Clock' is not a supported option.

Solved!
Go to solution

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.

0 Kudos
Message 1 of 8
(5,050 Views)

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

---
Brad Keryan
NI R&D
0 Kudos
Message 2 of 8
(5,046 Views)

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.

0 Kudos
Message 3 of 8
(5,037 Views)

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

National Instruments
0 Kudos
Message 4 of 8
(5,023 Views)

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:

 

  1. A Counter Output (CO) task is created and configured for pulse generation with continuous timing.
  2. M-series devices do not generate a Data Active event. Fortunately, the DI and DO tasks will be sampling with a clock source that is not free-running -- the CO task -- so they will not start until the clock does. This fact can be used to ensure a simultaneous start without the need for a trigger signal.

The runtime sequence of function calls is nearly identical, except that the CO task must also be managed alongside the DI and DO tasks:

  1. The counter/timer's internal output signal ("CtrXInternalOutput") is specified as the source of the oversample clock.
  2. The DI and DO tasks must be started prior to starting the CO task.
  3. Stop the CO task when stopping the DI and DO tasks (in any order).

 

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.

 

 

0 Kudos
Message 5 of 8
(4,985 Views)
Solution
Accepted by topic author IntAndTest

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

---
Brad Keryan
NI R&D
Message 6 of 8
(4,983 Views)

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.

0 Kudos
Message 7 of 8
(4,921 Views)

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

---
Brad Keryan
NI R&D
Message 8 of 8
(4,918 Views)