Jump to content
  • 0

Quad08 Quaderature Mode Question


mick1221

Question

For the Quad08 Is Quadrature Mode set through CounterMode.Encoder or CounterMode.Totalize?

I have an encoder wheel attached to a rail car for measuring distance and I need to know when it's moving forward or backward.

Everything I have read tells me that CounterMode.Encoder is the method for using Quadrature but I have only been able to get the card to count both up and down when using CounterMode.Totalize specifically 

CounterMode mode = CounterMode.Bit32 | CounterMode.Totalize | CounterMode.ModuloNOn | CounterMode.UpDownOn;

When using Counter.Encoder I'm using

CounterMode mode = CounterMode.Encoder | CounterMode.EncoderModeX1 | CounterMode.EncoderModeBit32;

I did read the Edge Detection section in the docs but it seems to describe the methods for the UL and not the UL for .Net, I am using C#.

Any insight is appreciated, Thanks.

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 1

Only channel 0 is set to quadrature encoder mode. 

Depending on how the encoder is mounted, the count will either increase or decrease when turned clockwise. Therefore, you can determine if the direction changed by monitoring the count direction. For example, if the counter value stopped increasing and is now decreasing, the encoder changed direction.

Link to comment
Share on other sites

  • 1

The following demonstrates how to use CConfigScan to configure two counter inputs: one for encoder and the other for modulus counting. Please take a look at the attached example.

          //set counter 0 to encoder mode
            mode = CounterMode.Encoder | CounterMode.EncoderModeBit32 | CounterMode.EncoderModeX4;
            IsError(daq.CConfigScan(0,
                                        mode,
                                        CounterDebounceTime.Debounce500ns,
                                        CounterDebounceMode.TriggerAfterStable,
                                        CounterEdgeDetection.RisingEdge,
                                        CounterTickSize.Tick208pt3ns, //ignored
                                        0));

            //set counter 1 to totalize mode with Modulus operation
            mode = CounterMode.Totalize | CounterMode.Bit32 | CounterMode.ModuloNOn;
            IsError(daq.CConfigScan(1,
                                        mode,
                                        CounterDebounceTime.Debounce500ns,
                                        CounterDebounceMode.TriggerAfterStable,
                                        CounterEdgeDetection.RisingEdge,
                                        CounterTickSize.Tick20pt83ns, //ignored
                                        1));

            ////load register1 with modulus number
            IsError(daq.CLoad32(CounterRegister.MaxLimitReg1, 2000));

Program.cs

Link to comment
Share on other sites

  • 0

Final Question hopefully, CLoad32() using one of the CounterRegister.Load registers doesn't set the register to anything. If I set CounterMode.EncoderModeModuloNOn it treats The CounterRegister.Load registers like it's the CounterRegister.MaxLimit register and it will roll over on that value. Am I missing anything? There doesn't seem to be anything in the documentation relating to this

Link to comment
Share on other sites

  • 0

CounterMode.ModuloNOn sets the encoder input to modulus counting and MaxLimitReg is the max count. For example, if you set MaxLimitReg to 1000 it will count to 1000 repeatedly.  However, it behaves slightly different in that it will count 1 to 1000 in one direction and 1000 to 1 in the other direction. 

Link to comment
Share on other sites

  • 0
private const string DeviceName = "QUAD08";
        private const int Axis = 0;

        static void Main(string[] args)
        {
            MccBoard board = new MccBoard(0);
            Console.WriteLine(board.BoardName);
            CounterMode mode = CounterMode.Encoder | CounterMode.EncoderModeX2 | CounterMode.EncoderModeBit32 | CounterMode.EncoderModeModuloNOn;
            ErrorInfo err = board.CConfigScan(Axis, mode, CounterDebounceTime.Debounce500ns, CounterDebounceMode.TriggerAfterStable, CounterEdgeDetection.RisingEdge , CounterTickSize.Tick208pt3ns, 0);
            Console.WriteLine(err.Message);

                for (int i = 0; i < 500000000; i++)
                {
                    Console.WriteLine("Reseting...");
                    board.CLoad32(CounterRegister.LoadReg0, 4000);

                    Thread.Sleep(100);
                    err = board.CIn32(Axis, out int test);
                    Console.WriteLine(test.ToString());
                    Thread.Sleep(100);
                    err = board.CIn32(Axis, out test);
                    Console.WriteLine(test.ToString());
                    Thread.Sleep(100);
                    err = board.CIn32(Axis, out test);
                    Console.WriteLine(test.ToString());;

                }
        }

Here is the test code I'm running, I have not set the max limit Register, only the Load Register...

 

 

It Outputs this

Quote

USB-QUAD08
No error has occurred.
Reseting...
176
352
527
Reseting...
704
879
1054
Reseting...
1231
1407
1582
Reseting...
1758
1934
2109
Reseting...
2286
2480
2657
Reseting...
2834
3009
3185
Reseting...
3364
3542
3718
Reseting...
3896
74

 

Counting up to 4000 then resetting when I set the load Regsiter

 

When I Remover the CounterMode.EncoderModeModuloNOn The CLoad32() Has no effect on the value read from the encoder

Quote

USB-QUAD08
No error has occurred.
Reseting...
209
399
588
Reseting...
780
970
1157
Reseting...
1356
1543
1729
Reseting...
1918
2105
2292
Reseting...
2483
2670
2858
Reseting...
3048
3237
3425
Reseting...
3615
3804
3993
Reseting...
4183
4370

Is setting the counter not allowed when using Countermode.Encoder?

Link to comment
Share on other sites

  • 0

The USB-QUAD08 doesn't use load registers. ((CounterRegister.LoadReg0, 4000)) Valid registers are MaxLimitReg0 - 7. 

If you want the count to restart, use the CClear() function.

board.CClear(CounterNum);

 

 

Link to comment
Share on other sites

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...