Driver Development Kit (DDK)

cancel
Showing results for 
Search instead for 
Did you mean: 

setting 6602 registers to latch encoder values on RTSI trigger

Greetings,

I am currently using the 6602, comedi driver, and  real time linux to read 6 quadrature encoders.  I would like to add some functionality to the comedi driver that would latch the encoder values from a RTSI trigger.  I have the register programming manual for the 6602; However, I am not quite sure how I should set up the registers for this task.  Any help would be greatly appreciated.

Thanks,
Greg
0 Kudos
Message 1 of 6
(8,849 Views)
 

Hi Greg-

As David mentioned in your other thread, NI does not maintain or support the Comedi driver directly.  That being said, a buffered event counting example is provided in the NI MHDDK examples for 660X boards.  This should be a good starting point to add external clocking via RTSI to your encoder app. 

 

Hopefully this helps-

Tom W
National Instruments
0 Kudos
Message 2 of 6
(8,819 Views)
Thanks Tom and David for your help.

I have looked over the examples that Tom listed and I think I understand the necessary register settings.  Just in case I missed something I have includded an example configuration and read function for your review.  The configuration is a combination of gpct_ex7.cpp and gpct_ex8.cpp.  Also, am I correct in assuming that if using a RTSI signal to latch the encoder values that the encoder index can not be used to reset the counter?  It seems they would both need access to the gate.   Thanks again for your help,

Greg

// configuring 6602...
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);
 
    //set source to the internal timebase (20 MHz)
    board->G0_Input_Select_Register.writeG0_Source_Select(0);
    
    //set gate to latch encoder value on rising edge of RTSI 0
    board->G0_Input_Select_Register.writeG0_Gate_Select(11);
    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);

    //use the DMA registers as a two element FIFO
    //The TIO will alternate save locations between the HW save and SW
    //save registers.
    board->G0_DMA_Config_Register.writeG0_DMA_Enable(1);
    board->G0_DMA_Config_Register.writeG0_DMA_Int_Enable(1);
 
    //arm counter
    board->G0_Command_Register.writeG0_Arm(1);
}


// reading the counter value would go something like this...
void generic_read(tTIO *board)
{
    int HWsaveOrSWsave;
    
    //the DMA Read register tells us where the most recent sample was saved:
    // 1 for SW save register, 0 for the HW save register
    HWsaveOrSWsave = board->G0_DMA_Status_Register.readG0_DMA_Read_Register();
 
    if(HWsaveOrSWsave == 1)
        printf("SW Save Register is 0x%08lx\n",
            board->G0_Save_Registers.readRegister());
    else
        printf("HW Save Register is 0x%08lx\n",
            board->G0_HW_Save_Registers.readRegister());
}

0 Kudos
Message 3 of 6
(8,803 Views)

Message Edited by Elijah K on 11-03-2006 02:02 PM

Elijah Kerry
NI Director, Software Community
0 Kudos
Message 4 of 6
(8,789 Views)

Hi Greg,

I noticed one issue you might encounter with your code.  When you merged this section of code from gpct_ex7.cpp

    //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);

you removed the second line:

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

The first line relies on the second to actually write the value to hardware.  "Set" only writes the value to the softcopy and doesn't transfer it to the hardware, as described in KnowledgeBase 2REGTNPG:  How to Use a ChipObject .

You should probably change it to

board->G0_Counting_Mode_Register.writeG0_Encoder_Counting_Mode(3);

so it actually gets written to hardware.

 

Have you encountered any problems with the code?

 
Robert Mortensen
Software Engineer
National Instruments
0 Kudos
Message 5 of 6
(8,708 Views)
Hi Robert,

Thanks for pointing that out.  I have not implemented the code yet, but hopefully will get to it next week.  I am currently working through a small issue with the PCI-6733, which is in the same system as the PCI-6602.  I am getting ready to post a question under this forum entitled "PCI-6733 acting strange after a reboot".  If you get a chance please take a look.

Thanks again,
Greg
0 Kudos
Message 6 of 6
(8,684 Views)