Jump to content
  • 0

USB-1808X using a counter to count pulses from an encoder


Question

Posted

In the example program DaqInScan02, analog input, digital input and a counter input are used simultaneously in a continuous, background mode using DaqBoard.DaqInScan().

I have an requirement to use three analog inputs for reading voltage values and one counter to count the number of pulses per second from an encoder.

To configure the counter, can I use DaqBoard.CConfigScan() so I can count the number of pulses per second?

I'm passing the following arguements to DaqBoard.CConfigScan():

MccDaq.CounterMode Mode = MccDaq.CounterMode.Totalize;
MccDaq.CounterDebounceTime DebounceTime = MccDaq.CounterDebounceTime.DebounceNone;
MccDaq.CounterDebounceMode DebounceMode = 0;
MccDaq.CounterEdgeDetection EdgeDetection = MccDaq.CounterEdgeDetection.RisingEdge;
MccDaq.CounterTickSize TickSize = 0;
int MapCounter = 1;

Will these values work?

The parameter MapCounter participates with the input signal by gating the counter or decrementing the counter. Can you elaborate?

12 answers to this question

Recommended Posts

  • 0
Posted

Your settings should work for totalizing. The map counter is used with the devices whose counters lack a gate input. They sacrifice a counter to be used as the gate. For instance, counter zero would use counter one input as its gate. Long story short, the map counter is ignored when using the USB-1808X.

Program.cs

  • 0
Posted

If I'm using a counter input and specifying MccDaq.CounterMode.Totalize to count the pulses, the data coming from the encoder will be a sequence of increasing numbers?

Example: 1 1 1 1 2 2 2 2 3 3 3 3 ...

Four data samples create a pulse. The number will eventually rollover to 0 when it reaches the limit for a 32 bit number.

  • 0
Posted

In the program I provided, change the following

CounterMode CMODE = CounterMode.Encoder | CounterMode.Totalize;

to

CounterMode CMODE = CounterMode.Totalize;

It will start at zero and increase to 2^32 before rolling over. 

 

   

  • 0
Posted

Your suggestion solved the problem.

The next problem. In your exmaple application called ClsScan03 a quadrature encoder input is used (Counters.clsCounters.CTRQUAD)

The following arguments are passed to DaqBoard.CConfig():

MccDaq.CounterMode Mode = MccDaq.CounterMode.Encoder | MccDaq.CounterMode.EncoderModeX1;
MccDaq.CounterDebounceTime DebounceTime = MccDaq.CounterDebounceTime.DebounceNone;
MccDaq.CounterDebounceMode DebounceMode = 0;
MccDaq.CounterEdgeDetection EdgeDetection = MccDaq.CounterEdgeDetection.RisingEdge;
MccDaq.CounterTickSize TickSize = 0;
int MapCounter = 2;

Am I correct to believe that MccDaq.CounterMode.EncoderModeX1 counts the pulses (rising edges) per second on input A?

Quadrature enocder input allows you to count the pulses and the direction (clockwise counter clockwise). Clockwise is channel A leading channel B. Counter clockwise is channel B leading channel A.

How do I determine if the pulses are clockwise or counter clockwise with your software library?

Quadrature Encoder.JPG

  • 0
Posted

Correct, X1 counting is on the lead edge of Phase A. 

The only method to determine direction is to look for the count to reverse. For example, a count of 4000 that then drops to 3900 indicates the direction reversed. 

 

 

 

  • 0
Posted

//Encoder configuration for counter #2

daq.CConfigScan(  2,
                   CounterMode.Encoder | CounterMode.EncoderModeX1,
                   CounterDebounceTime.DebounceNone,
                   CounterDebounceMode.TriggerAfterStable,
                   CounterEdgeDetection.RisingEdge,
                   CounterTickSize.Tick20ns,
                   0);

  • 0
Posted

The USB-1808X encoder input determines which phase A or B is leading, and either increments or decrements the count. It would be nice if there were a status register that indicated direction, but there was no such thing. 

  • 0
Posted

You are correct to say that it would be nice if there was a status register that indicated direction.

I have a situation where a conveyor belt has ONE speed (pulses per second = 392) and can go forward (clockwise) or backwards (counter clockwise).

1. From a stopped position (pulses per second = 0), the conveyor belt moves forward and the pulses per second is 392

2. From a stopped position (pulses per second = 0), the conveyor belt moves backward. Will the pulses per second be -392 since the USB-1808X decrements the pulse count from 0?

  • 0
Posted

The encoder input channel measures distance. Let's say your conveyor is 10' long, and the encoder has a resolution of 1200 / ft. If it moved forward 10', the count would increase to 12,000. If the conveyor moved halfway back, the count would decrease to 6,000. When it returns to where it started, it should return to zero. If the conveyor moved 600 counts, it moved 6 inches. 

 

  • 0
Posted

The online help for CConfigScan() and the only example program for counter type Counters.clsCounters.CTRQUAD (ClnScan03) indicate that the input channel counts pulses. In your last post, you indicate that the input channel measures distance. You mention a resolution of 1200. What is the 1200? Does your software need to know the length of the conveyor belt? You mentioned a length of 10 feet in your last post.

How would you configure CConfigScan() with the values in your last post?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...