12-15-2009 06:03 PM
Where can I find sample code for a CTR/TMR channel interrupt so I can create a hardware timed interrupt?
ex. Clock frequency = 1 MHz. Loop period = 100 ms.
1. Start counting.
2. Trigger interrupt when counter = 10000.
3. Reset counter.
4. Execute interrupt code.
5. Repeat steps 2-5.
Thanks!
Solved! Go to Solution.
12-16-2009
06:08 PM
- last edited on
11-21-2025
10:04 AM
by
Content Cleaner
Hi Michael.
I wasn't able to find a direct example to your request but the following should be a good reference
COunter Operations with Measurement Studio DAQ ActiveX Controls
Hardware Reset of a TIO (NI 660x) Counter in Measurement Studio
Count Digital Events with Option to ResetCounter
Keep in mind that some of the above makes references using the T-DAQ driver, and the last example uses LabVIEW with DAQmx, so you would need to reference the vi's to the functions in the DAQmx C Reference Help.
12-21-2009 11:25 AM
12-22-2009 03:04 PM
12-22-2009 05:00 PM
C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DotNET2.0\Counter\Count Digital Events\CountDigEventsBuffContinuous_ExtClk
You specify the number of counts before it calls the callback function. It is not a accurate as I've seen on microcontrollers, but it may be OK. It seems to get more accurate the faster I run the clock, but I might have overrun a variable somewhere because when I try to run the clock at 1,000,000 (I believe) on a PCI 6713 (24 bit counters) and count 100,000 counts it gives me an error stating that I need to divide the signal... I wish I could use the 20 MHzTimeBase rather than having to use another counter to provide the clock. I'll post the exact error tomorrow.
12-23-2009 10:40 AM
The following attachements show the code to configure the tasks to generate a clock signal, count pulses, and toggle a digital channel in order to click the frequency of the interrupt as well as an error that I get when I try to run at 1 MHz or higher using a PCI-6713. If I need a 10 Hz interrupt using a 1 MHz clock, I have to count 100 kPulses. It does not like this for some reason.
I'm running a test right now to count the interrupts over a known period of time to determine the error in the system. The frequency of the interrupt bounces between 9.992 and probably 10.008 (actually half of that due to the fact that each interrupt toggles the digital channel so the frequency is cut in half). I can handle small errors. Our tests can be anywhere from 20 minutes to 4 days. I just need to determine how many extra seconds I end up running if the frequency is slightly less than 10 Hz.
Thoughts on the whole idea?
12-23-2009 01:53 PM
I ran it for around 2.5 hours and these are my results:
Incrementing a counter each time the interrupt is called:
Start time: 11:09:26
End time: 13:49:58
Elapsed seconds: 9512
Counter value / 10 = 9511.9
I will run 16+ hours next Monday and see what I get, but I can live with these results!
12-30-2009 04:04 PM
Why would I get that error if I disconnect the clock from the input pin? I'm trying to put some checks into the code just in case the loop stops firing, but when I disconnect the wire that jumps from the counter output to the counter input I immediately get an error. It is the same error I posted above.
Thanks.
12-31-2009 02:36 PM
12-31-2009 02:42 PM