MityDSP Documentation Index

tcDspCounter

Introduction

The tcDspCounter class is used to count the occurances of some external event. Up to 16 counters are provided, each capable of counting from zero to (2^30 - 1). The actual depth of each counter may be configured to any value fro 1 to 2^30, and an interrupt may be enabled which is triggered whenever a counter rolls over.

The application may register a routine to be run in ISR context to provide specific functionality for each counter rollover.

In addition, utility routines are provided which allow any pair of counters to be used as quadrature (i.e. rotational) counters. It is assumed that one counter is configured to measure clockwise rotation, and the other CCW rotation.

There is no limit to the number of instances of tcDspCounter that may be created.

An instance of the tcDspCounter class is created by specifying the firmware base address of the core and the interrupt level used. This core supports specifying a level of gnAutoLevel, which automatically installs a vectored interrupt.

See also:
MityDSP::tcDspInterruptDispatch Class Reference
MityDSP::tcDspCounter Class Reference

Example

This is a simple example of tcDspCounter creation and usage:

 {
     SEM_handle   MyClass::mySem[gnNumCounters];
     SEM_handle   MyClass::myMasterSem;
     tcDspCounter *MyClass::myCounter;

     static void MyClass::myIsrCallback(int counter)
     {
         SEM_post(mySem[counter]);
         SEM_post(myMasterSem);
         return;
     }

     void MyClass::doSomething(void)
     {
         int i;
         unsigned int my_base_addr = 0xB0000200;
 
         // initialize semaphores
         for (i=0; i<gnNumCounters; i++) mySem[i] = SEM_create(0, NULL);
         myMasterSem = SEM_create(0, NULL);

         // create a Counter interface
         myCounter = new tcDspCounter((void *)my_base_addr);

         // register callback for all counters
         for (i=0; i<gnNumCounters; i++) 
             myCounter->registerIsrHandler(i, myIsrCallback);

         // setup counters to rollover every 1K counts and reset them
         for (i=0; i<gnNumCounters; i++) 
             myCounter->setDepth(i, 1024, true);

         // enable rollover interrupts for this counter
         for (i=0; i<gnNumCounters; i++) 
             myCounter->setInterruptEnable(i, true);

         // wait for ISR to trigger master semaphore
         SEM_pend(myMasterSem, SYS_FOREVER);

         // master semaphore triggered, determine who set it
         for (i=0; i<gnNumCounters; i++) 
         {
             if (SEM_pend(mySem[i], 0) != 0)
             {
                 // do something application-specific
                 :
                 :
             }
             :
         }
         :
     }
 
  } 

  
Generated on Fri Sep 23 16:33:44 2011 for MityDSP Core by  Doxygen Version 1.6.1
Copyright © 2009, Critical Link LLC, All rights reserved.