Measurement Computing   Easy to Use | Easy to Integrate | Easy to Support catalog banner

How to reset or clear a USB-QUAD08 Encoder Channel

Expand / Collapse
 

How to reset or clear a USB-QUAD08 Encoder Channel


The example program below demonstrates (using C++) how to configure and clear a USB-QUAD08 channel for quadrature encoder input. To use the cbCClear function, you must read the counter input asynchronously using cbCIn32.

 At the bottom of this article you will find a Zip file that contains the Visual Studio 2008 project.

// VC_2008_USB_QUAD08_AsynchronousReadClear.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


/* Include files */
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "cbw.h"

#define MAXNUMDEVS 100

void main ()
   {
   /* Variable Declarations */
   int i=0;
 
   int ULStat = 0;



   int numberOfDevices = MAXNUMDEVS;
   DaqDeviceDescriptor inventory[MAXNUMDEVS];
   DaqDeviceDescriptor DeviceDescriptor;

   int BoardNum = -1;
 
   float Rev = (float)CURRENTREVNUM;
   ULStat = cbDeclareRevision(&Rev);
   cbErrHandling(PRINTALL, STOPALL);

   printf ("Demonstration of cbConfigScan() in BACKGROUND mode\n\n");

//Ignore InstaCal device discovery
cbIgnoreInstaCal();

//locate USB devices
ULStat = cbGetDaqDeviceInventory(USB_IFC, inventory, &numberOfDevices);
for( i = 0; i < numberOfDevices; i++)
{
DeviceDescriptor = inventory[i];
 
//Product ID for USB-QUAD08 = 0xCA   
//Product IDs can be found in ULProps.txt located in 
// C:\Program Files (x86)\Measurement Computing\DAQ
if(DeviceDescriptor.ProductID == 0xCA)
{
BoardNum = i;
ULStat = cbCreateDaqDevice(BoardNum, DeviceDescriptor);
printf("Device Name: %s\n", DeviceDescriptor.ProductName);
break;
}
}

   if(BoardNum < 0)
   {
   printf("USB device not found...press any key to exit\n");
   getch();
   return;
   }





   ULStat = cbCConfigScan(BoardNum,
   0,
   ENCODER|ENCODER_MODE_X1|ENCODER_MODE_BIT_32,
   CTR_DEBOUNCE500ns,
   CTR_TRIGGER_AFTER_STABLE,
   CTR_RISING_EDGE,
   CTR_TICK208PT3ns,
   0);
   if(ULStat != 0)
printf("Error Code %d\n",ULStat);
    unsigned long encoderValue;
    int clearCounter = 0;
    while(!_kbhit())
    {
       //this loop reads the low half of the buffer then the upper half continuously.
       //it uses a NextReadUpper flag so that each half of the buffer is read once

        ULStat = cbCIn32(BoardNum,0,&encoderValue);
    printf("%d\n",encoderValue);

        Sleep(100);

        //test clear counter input every 10 seconds 
        clearCounter++;
        if(clearCounter >100) 
        {
            clearCounter = 0;
            cbCClear(BoardNum,0);
        }
    }



cbReleaseDaqDevice(BoardNum);

printf("Completed...press any key to exit\n"); 
getch();
}




Rate this Article:

Attachments



Add Your Comments


For comments email [email protected].

Details
Article ID: 50792

Last Modified:11/5/2019 1:20:41 PM

Article has been viewed 2,283 times.

Options