Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

PCI-6561 Dynamic Generation with external trigger. How to ramp signal at the rate of the external trigger?

I am attempting to write a routine that increments a counter and generates the (10 bits) parallel output. It is changing the ramp at the rate of the sample clock when I would like it to update the ramp at rate of the trigger signal. How can the following code snippet be modified to do this?

//Initialize generation session
    checkErr(niHSDIO_InitGenerationSession(deviceID,VI_FALSE,VI_FALSE,VI_NULL,&vi));
    
    /* Reset HSDIO Card */
    niHSDIO_ResetDevice (vi);
    
   //Assign channels for dynamic generation
    checkErr(niHSDIO_AssignDynamicChannels(vi,channelList));
    
    /* Configure clocking parameters */
   checkErr(niHSDIO_ConfigureSampleClock(
            vi, NIHSDIO_VAL_ON_BOARD_CLOCK_STR, sampleClockRate));
   /* Set generation mode to repeat */
   checkErr(niHSDIO_ConfigureGenerationRepeat (vi, NIHSDIO_VAL_CONTINUOUS, 1));
    //Configure clocking parameters
    checkErr(niHSDIO_ConfigureInitialState(vi,channelList,initialState));
    //Configure hardware start trigger
    checkErr(niHSDIO_ConfigureDigitalEdgeStartTrigger(vi,triggerTerminal,NIHSDIO_VAL_RISING_EDGE));
    //Query the Data Width Attribute
    checkErr(niHSDIO_GetAttributeViInt32(vi,VI_NULL,NIHSDIO_ATTR_DATA_WIDTH,&dataWidth));
    //populate waveforms
    for(i =0; i< nMaxValue; i++)
    {
        waveformDataU8[i]=nMaxValue-i-1;
        waveformDataU16[i]=nMaxValue-i-1;
    }
    //write waveform to device
    //The datawidth parameter is used to determine which write function to use
    if(dataWidth == 1)
    {
        checkErr(niHSDIO_WriteNamedWaveformU8(vi,waveformName,nMaxValue,waveformDataU8));
    }
    else
    {
        checkErr(niHSDIO_WriteNamedWaveformU16(vi,waveformName,/*nMaxValue*/1024,waveformDataU16));
    }
   
        //Initiate generation
        checkErr(niHSDIO_Initiate(vi));
       

Thanks

Brian B

0 Kudos
Message 1 of 9
(5,571 Views)

Hi Brian EE,

 

Can you elaborate a bit more on your overall application?  What is the trigger signal that you're using, and what is nMAXValue in your code below? 

 

In your below code, you configure the sample clock to have a clock source of the on board clock. When generation occurs, it's set up to generate at the rate of the on board clock.

 

It sounds like you're trying to generate a new bit on the channel each time there's a rising edge on your trigger signal. If the trigger signal is routed into the external clock input, the next set of bits would be generated on the rising edge of this clock signal. This way everytime you get a pulse on the trigger signal, the output will generate the next set of bits.

 

Lea D.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 9
(5,559 Views)

Hi Lea,

Thanks for the quick reply. The function of the application is to output a parallel word starting at the nMAXValue - 1, in this case (nMAXValue - 1)=1023. Then it would change the data output at detection of the rising edge of the trigger by decrementing it by 1.. so essentially it would ramp from 1023 to 0 and do this continuously. As for using the external clock, the signal I am using for the triggering is a LVDS single so the external clock doesn't seem like it will work. Also, there may be at times where the duty cycle may be less than 25 % which is outside the range of the external clock specifications. Is it possible to be configured(data output) in the static generation mode and monitor the "triggering signal" in aquisition mode.

 

Thanks again

Brian EE

0 Kudos
Message 3 of 9
(5,556 Views)

Hey Brian,

 

Thanks for the follow-up information. Connecting the trigger line tot he external clock was a pretty simple solution that wouldn't require you to change much of your code. One of the other ideas that I had involves scripting.

 

Here we have an example of retriggerable HSDIO generation using a script.you could connect scriptTrigger 0 to be tied to one of the PFI lines. We have a couple similar examples already in the HSDIO driver. If you go to your start menu » Programs » National Instruments » NI-HSDIO » Examples » c, there's examples in there for Dynamic Generation with script and two examples in that folder (one for a hardware script trigger and one for a software script trigger). Check out the hardware one if you want to go on this route.

 

The hardware script trigger could cause the script to get the card to generate a subset of data. I think in your application this would be a subset of the first 10 bits. 

 

Lea D.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 9
(5,540 Views)

Hi Lea,

I have been looking at the scripting examples and I think I have a solution, but I am not sure how to implement it in the script.Here is the pseudo script:

script myScript1
  Repeat forever

   if startposition > 1023

       then startposition =0

       else startposition=startposition + 1
   Wait until scriptTrigger0
   Generate mywfm subset (startposition, 1)    
  end repeat
end script

 

I could create 1024 different waveforms and do something like this:

script myScript1
  Repeat forever

   Wait until scriptTrigger0
   Generate mywfm1

   Wait until scriptTrigger0
   Generate mywfm2

   Wait until scriptTrigger0
   Generate mywfm3

   Wait until scriptTrigger0
   Generate mywfm..

   Wait until scriptTrigger0
   Generate mywfm1024
  end repeat
end script

 

I would think there would be something more programatic that could be done though.

Thanks again,

Brian

0 Kudos
Message 5 of 9
(5,531 Views)

Hi Brian,

 

I don't think that scripting is the way to go in your case.  I do have a few questions about your appliation to clarify how best to implement your code:

 

1.  Does your trigger signal have a constant time interval (i.e. can it act as a clock signal)?

2.  On assertion of the trigger, would you like to output:

A.  a static value held constant until the next trigger

B.  a dynamic value output once for a specified time.

 

 

Brian G.

Applications Engineer

 

Brian G.
0 Kudos
Message 6 of 9
(5,512 Views)

Hi Brian,

 

To answer your questions:

 

1.  Does your trigger signal have a constant time interval (i.e. can it act as a clock signal)? It is not a constant clock signal, the duty cycle varies.

The triggering signal is a pulse that is a handshaking signal that generated when a specified word is sampled in a PCM frame. In some instances it may be very periodic though. The duty cycle at times will be less than 25 % though. The signal is a LVDS signal and I am using the SMA-2164 accessory so it would be nice to stick with channels accessible through this interface. The rate of this signal could be as high as 2.5 MHz depending on how this channel is configured in the PCM frame.

2.  On assertion of the trigger, would you like to output:

A.  a static value held constant until the next trigger

B.  a dynamic value output once for a specified time.

(A) a static value held at a constant value until next trigger, and then increment the output by a fixed value each trigger event.

 

Thanks again for the input,

Brian

0 Kudos
Message 7 of 9
(5,501 Views)

Hi Brian,

 

My last post was incorrect in saying that scripting may not be needed for this case.  To write waveforms at a trigger rate of 2.5 MHz, you will need to programatically load multiple scripts (or a single script with all of your values) into the PCI-6561 onboard memory.  I would write a single waveform to memory that contains all of your values (0 to 1023 or whatever), then use a for loop to create a script that looks as follows using various string manipulation functions.

 

script countUp
  repeat until scripttrigger0
    generate countUp subset (0, 1)

  end repeat

  repeat until scripttrigger0
    generate countUp subset (1,1)

  end repeat

  repeat until scripttrigger0

    generate countUp subset (2,1)

  end repeat

  ...

  repeat until scripttrigger0

    generate countUp subset (1023,1)

  end repeat

end script

 

As far as I can tell, this will be the best way to accomplish the task.  For more information on scripting instructions please see NI Digital Waveform Generator/Analyzer Help>>Programming>>Reference>>Scripting Instructions.

 

 

Brian G.

Applications Engineer

 

 

Brian G.
Message 8 of 9
(5,486 Views)

Hi Brian,

Thanks for the input on this. I was able to update the software using the script trigger. I had to modify the script "subset (0, 1)" to "subset (0, 8)"..etc.. Also, I had to update the waveform as well.

 

Thanks again,

Brian EE

0 Kudos
Message 9 of 9
(5,439 Views)