Driver Development Kit (DDK)

cancel
Showing results for 
Search instead for 
Did you mean: 

Quadrature encoder with PCI-6259 DAQ board (driver for QNX)

where can I find any example for connecting Quadrature Encoders with M Series DAQ Boards ?
The only more or less suitable example I found in nimseries DDK, is
"Count pulses from an external source using an external signal to control
the count direction" (nimseries\Examples\gpctex2.cpp).
But this example is not working correctly with Quadrature Encoders
(encoders with  two shifted on 90 degrees phases A&B).
i.e. in case of using this example code I get some extra count while encoder is on vibrant motor

what means enums
typedef enum {
    ...
       kG0_Up_DownHardware          = 2,
       kG0_Up_DownHardware_Gate     = 3,
    ...
} tG0_Up_Down;
and
typedef enum {
    ...
       kG0_Encoder_Counting_ModeId          = 1,
    ...
} tId;
in (nimseries\ChipObjects\tTIO.h) ?
What initalization procedure I need to work with Quadrature Encoders?

I have PCI-6259 DAQ device
and I'm writing programm under QNX6 operating system
0 Kudos
Message 1 of 5
(9,019 Views)
Hello alexey_3269,
If you want to read a quadrature encoder start with gpctex1.cpp and follow the thread.
 
I give you my code:
 
BEGIN CODE
==========
 
boardGpct->G0_Mode.writeG0_Load_Source_Select(tTIO::tG0_Mode::kG0_Load_Source_SelectLoad_A);
boardGpct->G0_Load_A.writeRegister(InitialCount);
boardGpct->G0_Command.writeG0_Load(1);
boardGpct->G0_Load_B.writeRegister(0);
boardGpct->G0_Load_A.writeRegister(0);
boardGpct->G0_Input_Select.setG0_Source_Select(9); //see above for choices, PFI8=9, 100 kHZ=18
boardGpct->G0_Input_Select.setG0_Source_Polarity(1); //0=CCW, 1=CW
    
//If using 80 MHz timebase
boardGpct->G0_MSeries_Counting_Mode.writeG0_MSeries_Alternate_Synchronization(1);
boardGpct->G0_MSeries_Counting_Mode.setG0_MSeries_Encoder_Counting_Mode(3);  //3 for X4 encoder counting
boardGpct->G0_MSeries_Counting_Mode.flush();
 
//Enable Input Pins
boardGpct->G0_MSeries_ABZ.setG0_A_Select(9);  //PFI8=9,
boardGpct->G0_MSeries_ABZ.setG0_B_Select(21); //PFI10=21
boardGpct->G0_MSeries_ABZ.setG0_Z_Select(10); //PFI9=10 
boardGpct->G0_MSeries_ABZ.flush();
 
boardGpct->G0_Mode.setG0_Gate_Polarity(1); //invert=1
boardGpct->G0_Mode.setG0_Output_Mode(tTIO::tG0_Mode::kG0_Output_ModePulse);
boardGpct->G0_Mode.setG0_Loading_On_Gate(tTIO::tG0_Mode::kG0_Loading_On_GateNo_Reload);
boardGpct->G0_Mode.setG0_Loading_On_TC(tTIO::tG0_Mode::kG0_Loading_On_TCRollover_On_TC);
boardGpct->G0_Mode.setG0_Gating_Mode(tTIO::tG0_Mode::kG0_Gating_ModeLevel_Gating); //kG0_Gating_ModeGating_Disabled
boardGpct->G0_Mode.setG0_Gate_On_Both_Edges(tTIO::tG0_Mode::kG0_Gate_On_Both_EdgesBoth_Edges_Disabled);
boardGpct->G0_Mode.setG0_Trigger_Mode_For_Edge_Gate(tTIO::tG0_Mode::kG0_Trigger_Mode_For_Edge_GateGate_Starts_TC_Stops);
boardGpct->G0_Mode.setG0_Stop_Mode(tTIO::tG0_Mode::kG0_Stop_ModeStop_On_Gate);
boardGpct->G0_Mode.setG0_Counting_Once(tTIO::tG0_Mode::kG0_Counting_OnceNo_HW_Disarm);
boardGpct->G0_Mode.setG0_Reload_Source_Switching(tTIO::tG0_Mode::kG0_Reload_Source_SwitchingAlternate);
boardGpct->G0_Mode.flush();
 
boardGpct->G0_Command.setG0_Up_Down(tTIO::tG0_Command::kG0_Up_DownHardware); //kG0_Up_DownSoftware_Down
boardGpct->G0_Command.setG0_Bank_Switch_Enable(tTIO::tG0_Command::kG0_Bank_Switch_EnableBank_X);
boardGpct->G0_Command.setG0_Bank_Switch_Mode(tTIO::tG0_Command::kG0_Bank_Switch_ModeGate);
boardGpct->G0_Command.flush();
 
boardGpct->Interrupt_G0_Enable.setG0_TC_Interrupt_Enable(0);
boardGpct->Interrupt_G0_Enable.setG0_Gate_Interrupt_Enable(0);
boardGpct->Interrupt_G0_Enable.flush();
 
END CODE
========
 
I hope this code is appropriate to you.
 
FV1234
Message 2 of 5
(8,947 Views)
When this example is run on Linux with a 6221 card, A/B encoding works fine, but Z signal seems to be ignored. Is there anybody that can shed some light on this?


0 Kudos
Message 3 of 5
(8,726 Views)

Hi Anders-

You might need to adjust the Z-index phase settings to match those provided by your encoder.  This is accomplished using the bitfield

G0_Counting_Mode.writeG0_Index_Phase()

where valid values for phase are:

0: A low, B low
1: A low, B high
2: A high, B low
3: A high, B high

Tom W
National Instruments
0 Kudos
Message 4 of 5
(8,720 Views)
Nope, but G0_MSeries_Counting_Mode.setG0_MSeries_Index_Enable(1) seems to do the trick....

0 Kudos
Message 5 of 5
(8,711 Views)