Driver Development Kit (DDK)

Showing results for 
Search instead for 
Did you mean: 

NI PCI-6602 driver under RTX - Encoder counting mode: X4



We are using NI PCI-6602 under RTX for Relative Position Measurement.

Encoder counting mode: X4

We are using Gate0,Gate1,Gate2,Gate3.

We would like to know if the following code in functions configDecoder() ,readDecoder() should be performed in the exact same way for every Gate (0,1,2,3)?

In the example Below we are referring to Gate 2 .

The function readDecoder below will be performed every 3 milliseconds.

Do we need to perform any action (Disarm ) between the calls ?

Is it below code OK ?



#include "stdio.h"
#include "osiBus.h"
#include "tTIO.h"


tTIO *board;

int main()
 iBus* bus;

 tAddressSpace  Bar0;
 u32 physicalBar1;

 //Each PCI card has an identifying 32bit PCI ID number.
 //0x10930000 is the manufacturer ID number for all National Instruments cards
 //0x00001310 is the device ID number for the PCI-6602
 //0x00001360 is the device ID number for the PXI-6602
 //0x00002DB0 is the device ID number for the PCI-6608
 //0x00002CC0 is the device ID number for the PXI-6608

 bus = acquireBoard("PXI0::0::INSTR");

 if(bus == NULL){
  printf("Error accessing the PCI device.  Exiting.\n");
  return 1;

 //Skip MITE initialization for PCMCIA boards
 //(which do not have a MITE DMA controller)
 if(!bus->get(kIsPciPxiBus,0)) return;
 Bar0 = bus->createAddressSpace(kPCI_BAR0);

 //Get the physical address of the DAQ board
 physicalBar1 = bus->get(kBusAddressPhysical,kPCI_BAR1);



/ ***** 6602/6608 specific MITE initialization *****
 // Hit the IO Window Base/Size Register 1 (IOWBSR1) in the MITE.  We set the 
 // address, enable the window and set the size of the window:
 Bar0.write32(0xC4, (physicalBar1 & 0xffffff00L) | 0x8C);

 // Write to the IO Window Control Register 1 (IOWCR1) to make the IO window 
 // go to RAM memory space instead of the config space
 Bar0.write32(0xF4, 0);
 // ***** End of 6602/6608 specific code *****




 return 0;



void configDecoder(iBus *bus)



 tAddressSpace  cardSpace;
 cardSpace = bus->createAddressSpace(kPCI_BAR1);
 board = new tTIO(cardSpace);




 //load initial value of 0


 //set the counting mode to quadrature encoding X4

 //set source to the internal timebase (20 MHz)
 //set gate
 //set counting direction to Gate IO connector

 //arm counter
 printf("counter value is 0x%08lx\n",






Void readDecoder(){


Bool canRead = board->G23_Status_Register.readG2_Save_St();



 counterValue1 = board->G2_Save_Registers.readRegister();
 counterValue2 = board->G2_Save_Registers.readRegister();
 if(counterValue1 != counterValue2)
  counterValue1 = board->G2_Save_Registers.readRegister();
 printf("counter value is now 0x%08lx\n",counterValue1);




Best Regards,

Efrat Gur

0 Kudos
Message 1 of 3

Your approach looks sound, although I haven't tested your code with hardware. I would do some validation testing before putting this in a production system. One note about reading an armed counter is that you may need to read from the register multiple to get the correct value as stated in the 660x RLP manual:


Screen Shot 2015-03-24 at 5.35.40 PM.png

Steven K.
National Instruments
Software Engineer
0 Kudos
Message 2 of 3



Thank you for your reply.

Is there a possibility to use a "Retrigger able Single Pulse Generation" for source (5) and in addition, use Encoder counting mode: X4 for Gate0, Gate1,Gate2 and Gate3 ?


Best Regards,

Efrat Gur


0 Kudos
Message 3 of 3