Driver Development Kit (DDK)

cancel
Showing results for 
Search instead for 
Did you mean: 

how to use pci-6230 as position measure

Can i use the following method to realiate position measure function?

/*
*  gpct_ex7.cpp
*
*  Quadrature encoding
*
*  Read a quadrature encoder using counter 0.  The counter is configured for X4 mode
*  The initial value is loaded into the counter from the Load A register.
*
*  Attach the quadrature encoder's A signal to pin 2 (PFI 39) and the B signal to
*  pin 40 (PFI 37).
*
*  $DateTime: 2006/07/27 23:51:45 $
*
*/

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

void test(iBus *bus);
void initMite(iBus *bus);

int main()
{
 iBus* bus;

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

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

 //Intitialise Mite Chip.

 initMite(bus);

 //Calling test function

 test(bus);


 releaseBoard(bus);
 return 0;
}

//Tell the MITE to link the  BAR1 address to the DAQ Board
//You must initialize the MITE before you write to the rest of the PCI board
void initMite(iBus *bus)
{
  tAddressSpace  bar0;
 u32 physicalBar1;
 
 //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);
 //Tell the MITE to enable BAR1, where the rest of the board's registers are
 bar0.write32(0xC0, (physicalBar1 & 0xffffff00L) | 0x80);
    //bar1 = bus->createAddressSpace(kPCI_BAR1);
 
 bus->destroyAddressSpace(bar0);

}


void test(iBus *bus)
{
 tAddressSpace  cardSpace;
 tTIO *board;
 
 cardSpace = bus->createAddressSpace(kPCI_BAR1);
 board = new tTIO(cardSpace);

 //Reset
 board->G01_Joint_Reset_Register.writeG0_Reset(1);

 //Disarm
 board->G0_Command_Register.writeG0_Disarm(1);

 //load initial value of 0
 board->G0_Load_A_Registers.writeG0_Load_A(0x00000000);
 board->G0_Command_Register.writeG0_Load(1);

 //set the counting mode to quadrature encoding X4
 board->G0_Counting_Mode_Register.setG0_Encoder_Counting_Mode(3);
 board->G0_Counting_Mode_Register.writeG0_Index_Phase(3);


 //set source to the internal timebase (20 MHz)
 board->G0_Input_Select_Register.writeG0_Source_Select(0);
 
 //set gate
 board->G0_Input_Select_Register.writeG0_Gate_Select(2);
 board->G0_Mode_Register.writeG0_Gate_Polarity(0);
 board->G0_Mode_Register.writeG0_Gating_Mode(2);
 board->G0_Mode_Register.writeG0_Trigger_Mode_For_Edge_Gate(3);
 
 //set counting direction to Gate IO connector
 board->G0_Command_Register.writeG0_Up_Down(2);

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

 //delay long enough for the quadrature encoder to turn a few times
 {
  long int i,j;
  printf("waiting...\n");
  for(i=0;i<1000000;i++)
   for(j=0;j<3000;j++)
    ;
 }

 //read counter value
 //Use this method to read the value of an armed counter
 //during non-buffered counting.  Since the value of the counter may
 //change during the read, we make sure that the value is stable.
 unsigned long counterValue1, counterValue2;
 counterValue1 = board->G0_Save_Registers.readRegister();
 counterValue2 = board->G0_Save_Registers.readRegister();
 if(counterValue1 != counterValue2)
  counterValue1 = board->G0_Save_Registers.readRegister();
 printf("counter value is now 0x%08lx\n",counterValue1);

 //Disarm
 board->G0_Command_Register.writeG0_Disarm(1);
 
 delete board;
 bus->destroyAddressSpace(cardSpace);
}

 

when this sentence  "board->G0_Load_A_Registers.writeG0_Load_A(0x00000000);" is excute i cannt use AO function again,can anybody tell me why? and there is another question

0 Kudos
Message 1 of 1
(6,410 Views)