Driver Development Kit (DDK)

cancel
Showing results for 
Search instead for 
Did you mean: 

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

Hello,

 

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 *****

 

 bus->destroyAddressSpace(Bar0);

 

configDecoder(bus);
 releaseBoard(bus);
 return 0;
}

 

 

void configDecoder(iBus *bus)

{

 

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

 

 //Reset
 board->G23_Joint_Reset_Register.writeG2_Reset(1);

 //Disarm
 board->G2_Command_Register.writeG2_Disarm(1);

 //load initial value of 0
 board->G2_Load_A_Registers.writeG2_Load_A(0x00000000);
 board->G2_Command_Register.writeG2_Load(1);

 

 //set the counting mode to quadrature encoding X4
 board->G2_Counting_Mode_Register.writeG2_Encoder_Counting_Mode(3);
 board->G2_Counting_Mode_Register.writeG2_Index_Phase(3);


 //set source to the internal timebase (20 MHz)
 board->G2_Input_Select_Register.writeG2_Source_Select(0);
 
 //set gate
 board->G2_Input_Select_Register.writeG2_Gate_Select(2);
 board->G2_Mode_Register.writeG2_Gate_Polarity(0);
 board->G2_Mode_Register.writeG2_Gating_Mode(2);
 board->G2_Mode_Register.writeG2_Trigger_Mode_For_Edge_Gate(3);
 
 //set counting direction to Gate IO connector
 board->G2_Command_Register.writeG2_Up_Down(2);

 //arm counter
 printf("counter value is 0x%08lx\n",
 board->G2_Save_Registers.readRegister());
 board->G2_Command_Register.writeG2_Arm(1);

 

 

}

 

 

Void readDecoder(){

 

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

 

If(canRead){

 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
(6,329 Views)

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
(6,314 Views)

Hi,

 

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
(6,297 Views)