LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Generate a Finite number of Pulses with a Digital Trigger

Hi!

 

I need to generate an N number of pulses based when I receive a storbe from my rate table. As I had my code before I was only generating 1 pulse and it was working fine, but now i tried to change it to be a variable number of pulses and now it gives me a Run-time error (-50103) saying that the specified resource is reseved when I try to start task gCTR5taskHandle which measures the time between rate table pulses (period counter). Could someone tell me how to fix it???

 

Anyw help would be much appreciated. ..Here's a snippet of the relevant code.

 

// Setup CTR-0 as DATA REQUEST CLOCK. Free Running Clock.

   DAQmxErrChk(DAQmxCreateTask("",&gCTR0taskHandle)); // I create my task

 

/*I want to create the data request based on the rate table strobe. So, I create a channel which will generate a pulse on counter 0 with the _test_data_req (1024Hz) frequency. Instead of the _test_data_req variable the parameter Value used to be 1e6, now is 1024Hz set via the configuration file.*/

  DAQmxErrChk(DAQmxCreateCOPulseChanFreq(gCTR0taskHandle, "/Dev1/ctr0","",DAQmx_Val_Hz,DAQmx_Val_Low, DELAY,_test_data_req ,DUTY)); 

   DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(gCTR0taskHandle,  "/Dev1/PFI19",DAQmx_Val_Falling )); //I want to trigger the generation of the pulses by the falling edge of the rate table strobe (available in PFI19)

   DAQmxErrChk(DAQmxSetTrigAttribute(gCTR0taskHandle,DAQmx_StartTrig_Retriggerable,1)); //It’s retriggerable based on if the task is running and if the strobe is obtained

/*The number of pulses I want to generate each time the strobe is obtained used to be 1, but now we need to generate 32 pulses (32 data requests) per each RT strobe(now defined through the configuration file)*/

   DAQmxErrChk(DAQmxCfgImplicitTiming(gCTR0taskHandle, DAQmx_Val_FiniteSamps, _test_int_num));

 

 

 

// Setup CTR-5 as TIMESTAMP STROBE timer

   DAQmxErrChk (DAQmxCreateTask("",&gCTR5taskHandle));

   DAQmxErrChk (DAQmxCreateCIPeriodChan(gCTR5taskHandle,"/Dev1/ctr1","",0.000001,25,DAQmx_Val_Seconds,DAQmx_Val_Falling,DAQmx_Val_LowFreq1Ctr,0.000001,4,"")); //This task I want to measure the period of the RT strobe ( the time between falling edges of the strobes)

   DAQmxErrChk(DAQmxSetChanAttribute(gCTR5taskHandle, "", DAQmx_CI_Period_Term, "/Dev1/PFI19", 1)); //My strobe for axis 1 comes in on PFI19

   DAQmxErrChk(DAQmxSetChanAttribute(gCTR5taskHandle, "", DAQmx_CI_CtrTimebaseSrc, "/Dev1/PFI0", 1));//My 10MHz clock comes in at PFI0

   DAQmxErrChk(DAQmxSetChanAttribute(gCTR5taskHandle, "", DAQmx_CI_CtrTimebaseRate, 1e7, 1));//My clock if 10MHz

   DAQmxErrChk(DAQmxSetChanAttribute(gCTR5taskHandle, "", DAQmx_CI_DupCountPrevent, TRUE));//This is set in the event where no clock ticks are measured between the RT strobe pulses, to use the internal 80MHz to measure the time (0) instead of having it give me a timeout(receiving an exception that no click pulses were detected between RT strobes

0 Kudos
Message 1 of 6
(4,404 Views)

Hi mrebemp!

 

First, I'd like to ask what hardware you are using, and what DAQmx driver version you are using (functionality can vary between devices).

 

Next, have you used breakpoints to find out at which line your code causes an error? This will narrow down the search. If you could post a screenshot of the error code and message, that would be great. 

 

 

Keep us posted!

Derek B. (esoDerek)
Product Marketing Engineer
National Instruments
0 Kudos
Message 2 of 6
(4,360 Views)

Hi! I was able to find the problem although I'm not sure of the reason behind it. Apparently since I was using ctr 0 to generate the 32 pulses, for some reason that was reserving counter 1 as well. This didn't happen when I just sent 1 pulse though. So, by changing the counter used to get the time between rate table pulses to counter 2 instead of 1 now it works. Can anyone expalin to me why this is so? Thanks!

0 Kudos
Message 3 of 6
(4,347 Views)

Hi mrebemp,

 

Glad to hear it's working! I can't say for sure why switching to counter 2 worked - it might be something to do with the internal routing of your particular device, but without knowing what hardware you're using I can't be sure. I don't see anything noteworthy in your code - could you have reserved counter one in another section of your code, or have test panels open in MAX? I'd also still like to know which specific lines of code were generating the error, and what the error code said exactly - these could help us narrow down where it went wrong. 

 

Thanks!

Derek B. (esoDerek)
Product Marketing Engineer
National Instruments
0 Kudos
Message 4 of 6
(4,332 Views)

Hi! My device is a NI-6602. I wasn't using counter 1 elsewhere in the code at all, and the error occured when starting the task involving that counter 1 ("(DAQmxErrChk (DAQmxStartTask(gCTR5taskHandle));"). The specific error was the following.

 

Library function error (return value == -50103. NI Platform Services: The specified resource is reserved. The operation could not be completed as specified.

 

 

0 Kudos
Message 5 of 6
(4,326 Views)

Hey again mrebemp!

 

Still can't confirm what might be causing the issue, but I have a couple guesses! First, take a look at the 6602 device pinout, and make sure you haven't used any of the PFI lines reserved for the ctr1 - even if you never explicitly mentioned ctr1, these could cause your counter to become reserved!

 

This could also be related to your PFI19 - you're using your strobe input as both a source for your ctr1 and as the trigger for your ctr0, but trying to read off the same line might be throwing that error. You should be able to pass the ctr1 source to the designated ctr1 source PFI line (see your device pinout for details) - using this PFI line might solve your reserved resource error! See the manual entry on passing ctrNsource to PFI lines for more details (linked below):

http://www.ni.com/pdf/manuals/372119c.pdf#page=33

 

(Of course, don't feel obligated to change your code if it's working already! This might just help us understand why it wasn't working). 

 

I've been looking through the routing options for the 6602 and still can't find anything that would explain why counter 1 would return an error and counter 2 would not. If you could post your working code (so we can compare) this might help us narrow down the issue.

 

Thanks very much!

 

Derek B. (esoDerek)
Product Marketing Engineer
National Instruments
0 Kudos
Message 6 of 6
(4,319 Views)