Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How to verify a counter is operating properly?

Myself and my lab buddy are tasked to create a software PI controller to control a DC motor through via an PWM-driven H-bridge.

We are currently using a 6036E board, LabWindows/CVI and chose to use DAQmx.

The board itself has two counters, CTR0 and CTR1.  CTR0 has been configured to drive our PWM signal and operates perfectly fine.  It's when we place an encoder on CTR1 where things start to go wrong.  For one, even with nothing connected the counter continues to count non-stop when viewing the counter from MAX.

Since I'm the programmer of the group, I'm not totally sure what's going on here.  I've worked with counters before and I did verify that the encoder was operating properly, TTL logic, using a PIC18F4550.  We know it's not the encoder itself because it works as it should.  We've even tried to see if the counter and encoder had to have common ground.  Counter didn't seem to care.  Snce it continues to simply count my guess is we have to connect up other lines?  I'm not sure if we need to fiddle with the GATE and SRC lines or anything.  Again, there really isn't all that much documenation.

Shouldn't we simply be able to connect the encoder output to the CTR1 pin (pin 40 I believe) and it should it not simply act as a simple edge-triggered counter?  It seems odd we can get the PWM to work but not a simple counter...

Here is what we have (basically, I'm not posting the ENTIRE file):

    // Create the task.
    DAQmxCreateTask("",&counterH);
    DAQmxCreateCICountEdgesChan (counterH, "Dev1/ctr1, "", DAQmx_Val_Rising, 0, DAQmx_Val_CountUp);
    DAQmxStartTask(counterH);

    // To read the counter, we're using:
   DAQmxReadCounterU32 (counterH, DAQmx_Val_Auto, 10.0, &count, 1, &sample, 0);

Now that I look at this last command, I'm not sure what this "10.0" is...
0 Kudos
Message 1 of 3
(4,007 Views)
I should also mention that digital I/O and analog DAQmx tasks work fine as well.

There's something basic we're missing when it comes to counter input I guess.
0 Kudos
Message 2 of 3
(4,003 Views)
A few suggestions/comments:
 
What kind of pulse train are you generating: finite or continuous? A finite pulse train will use both counters, a continuous will use one. So if you have you PWM going on a finite task and try to read off of counter 1, you could see some signals on that counter. Is this the case, or do you see the count even when the PWM is not running?
 
Counter 0 source input is pin 42 on that card. Pin 40 is the counter output, for use in generation. You want to hook your encoder up to source if you want to count edges.  If you hook your encoder up to pin 42 and do a simple edge count in MAX, do you see things count up correctly? 
 
The "10" in that last command is the default 10 second timeout.
 
Hope this helps, don't hesitate to post back if you have additional questions or none of these suggestions work.
 
cheers,
Andrew S
National Instruments
0 Kudos
Message 3 of 3
(3,979 Views)