06-03-2015 03:56 AM
Hi,
We are using NI PCI-6602 under RTX . Encoder counting mode: X4
We are using Incremental Shaft Encoder HENGSTLER RI 58-D/3600 AH 37RB
1. we are using it as RS422 +Alarm.
2. The encoder type is not a push pull type.
3. The Voltage supply is 5 Volt.
4. We have connected channel (A)+ to the channel A input of PCI-6602 and channel (B)+ to the channel B input of PCI-6602.
We have tested this card in two separate systems, and in both systems , we were able to read the counting for gates G0,G1,G3 but not for G2.
The pinout is the following :
Gate 0:
Channel_A(0) -----> pin2
Channel_B(0) -----> pin40
Gate 1:
Channel_A(1) -----> pin7
Channel_B(1) -----> pin6
Gate 2:
Channel_A(2) -----> pin34 ------------------- Not working
Channel_B(2) -----> pin66
Gate 3:
Channel_A(3) -----> pin31
Channel_B(3) -----> pin63
Do you have any idea why this happens?
We used G0,G1,G2,G3 in kPCI_BAR1.
Is there a way to use G0,G1,G2,G3 in kPCI_BAR0 ?
How can it be done ?
Best Regards,
Efrat Gur
In the example Below we are referring to Gate 2 .
--------------------------------------------------------------------------------------------------------------------------
#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
06-23-2015 04:04 PM
Efrat,
Looks like you're using a slightly modified version of example 7 (gpct_ex7.cpp). Running example 7 on my machine, I was unable to reproduce your issue as I got non-zero counts for G0, G1, G2, and G3.
The only differences I see between your code and example 7 is that you moved the read code to its own function, removed the delay, and changed the code to use counter 2 instead of counter 0. Does your problem still occur when running example 7?