Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Setting 6250 counter threshold

I have a power supply that provides a voltage signal that is proportional to the current draw.  I need to detect a short current spike of around 70 amps.  The baseline voltage varies from .2 to around .5 volts and the spike is around around 7 volts.  Is there a way to set the threshold  of the counter to say 4 volts?

These are the two functions I am starting with.

 

INT32 CDAQCounter::StartCounting()
{
   DAQmxErrChk (DAQmxCreateTask("",&m_TaskHandle));
   DAQmxErrChk (DAQmxCreateCICountEdgesChan(m_TaskHandle,m_CardID/*"Dev1/ctr0"*/,"",DAQmx_Val_Rising,0,DAQmx_Val_CountUp));
   DAQmxErrChk (DAQmxSetArmStartTrigType(m_TaskHandle, DAQmx_Val_DigEdge));
   DAQmxErrChk (DAQmxSetDigEdgeArmStartTrigSrc(m_TaskHandle,m_SourceID/* "/Dev1/PFI0"*/));
   DAQmxErrChk (DAQmxSetDigEdgeArmStartTrigEdge(m_TaskHandle, DAQmx_Val_Rising));
   DAQmxErrChk(DAQmxStartTask(m_TaskHandle))
}

 

INT32 CDAQCounter::GetCount()
{
   uInt32 data = 0;
   DAQmxErrChk (DAQmxReadCounterScalarU32(m_TaskHandle,10.0,&data,NULL));
   return (INT32)data;
}

 

I am going to be polling the GetCount() function while I programatically increase an output frequency.  When I get back a value, (I should get back a one), that will be the end of the test.

 

0 Kudos
Message 1 of 13
(7,041 Views)

Hi AiR_GuNNeR,

 

Unfortunately, you will not be able to change the threshold of the digital counter on your 6250, since it is implemented in hardware and is not a configurable setting. That being said, you may consider trying to implement something along the lines of the method in this KnowledgeBase article.

 

I realize the example in the KB is for LabVIEW and that you are using a text-based program, but the general concepts it discusses should be applicable in your situation as well, especially since you are counting a single spike. If that specific KB does not provide a good solution, consider looking through the related links.

 

 

Best Regards,

Thomas B.
National Instruments
Applications Engineer
0 Kudos
Message 2 of 13
(7,021 Views)

If you have the analog input available solely for this purpose then you could configure an analog start trigger (configurable threshold and hysteresis) which will generate a TTL "analog comparison event" that can be routed to the hardware counter.  Even after the task has been started the comparison event will still continue to be generated based on the analog input signal.  If it were me I'd probably do this as it is less work that the software has to do.

 

Thomas's suggestion is fine too though.

 

 

Best Regards,

John Passiak
0 Kudos
Message 3 of 13
(6,974 Views)

Thanks John, and Thomas,

Will either of these solutions work in the background?  My problem is that I am in a loop, changing the frequencey of a frequency generator.  At a certain frequencey, th hardware will trigger causing the spike.  After each frequencey change, I am taking a sample and looking for the spike.  Sometimes teh spike happens after the sampling, and before the next frequency increase.  Ideally, I would want to setup a 5 second sample, then sweep through my frequency increases, then retrieve the sample data and analyze for the spike.

TIA

Eric

0 Kudos
Message 4 of 13
(6,946 Views)

If I understand your question correctly, then either suggestion would work in the background--if you configure a sample clock, once you start your task the DAQ card will acquire and buffer the data until you read it back in at a later time.  If you are acquiring using a continuous input task, you might need to configure the input buffer size to something larger than the default (use DAQmxCfgInputBuffer).

 

 

Best Regards,

John Passiak
0 Kudos
Message 5 of 13
(6,940 Views)

Thanks for the quick reply John,

 

Let me know if I'm doing this correctly.  So if I perform the following code, this will start the sampling running the the background:

 

 

  DAQmxErrChk(DAQmxCfgSampClkTiming(m_TaskHandle,"",1000,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,5000))
  DAQmxErrChk(DAQmxStartTask(m_TaskHandle))

Then, after my ramp up, I can gather up the data like this?

 DAQmxErrChk(DAQmxReadAnalogF64(m_TaskHandle,5000,10.0,DAQmx_Val_GroupByChannel,dataBuffer,5000,&read,NULL))

Ideally, I want to figure out how to implement your suggestion as is seems that I can then query the counter after every frequency ramp up and not have to go though the full ramp up, (i.e. I can quite once I have detected the spike).

 

Eric

0 Kudos
Message 6 of 13
(6,935 Views)

Sorry, one other question John,

In your alternative method, is this using the 6250 for the anolog input, or a separate analog input card, (which I have available).

I looked at the Measurement & Automation test panel for the 6250.  There are quite a few cryptic options available.  Can I use the test panel to prototype this provided I performed the hard wiring as well?

Eric

0 Kudos
Message 7 of 13
(6,930 Views)

Yeah, in the code you posted you have configured the task to acquire 5 seconds of AI starting with when you call DAQmxStartTask.  You then execute whatever ramp up code you needed to do and read back the data at the end (you could add a trigger to the analog input task if you want to synchronize the acquisition with the actual start of your ramp up).

 

My alternative suggestion does use the AI on the 6250, it would look something like this (meant as an example, I didn't actually test the code below):

 

//Configure Counter Task
DAQmxCreateTask("",&ciTaskHandle); DAQmxCreateCICountEdgesChan(ciTaskHandle,"Dev1/ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp);
DAQmxSetCICountEdgesTerm(ciTaskHandle,"","/Dev1/AnalogComparisonEvent");
//Configure Analog Task
DAQmxCreateTask("",&aiTaskHandle);
DAQmxCreateAIVoltageChan(aiTaskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL);
DAQmxCfgSampClkTiming(aiTaskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);
DAQmxCfgAnlgEdgeStartTrig(aiTaskHandle,"Dev1/ai0",DAQmx_Val_Rising,<insert trigger level here>);
DAQmxSetAnlgEdgeStartTrigHyst(aiTaskHandle, <insert trigger hysteresis here>); //Start Tasks in Order DAQmxStartTask(ciTaskHandle);
DAQmxStartTask(aiTaskHandle);


//Body of code goes here. When you want to read back the number of edges detected call the following line
//DAQmxReadCounterScalarU32(ciTaskHandle,1.0,&data,NULL)


//When done, stop and clear your tasks:
DAQmxStopTask(aiTaskHandle);
DAQmxStopTask(ciTaskHandle);
DAQmxClearTask(aiTaskHandle);
DAQmxClearTask(ciTaskHandle);

 

For me this is easier since you don't have to actually read in the analog input or do any sort of processing in software to figure out where you have crossed the threshold.

 

 

Best Regards,

John Passiak
0 Kudos
Message 8 of 13
(6,922 Views)

Man, I owe you a beer! (or two, or three...),

Thank you so much for taking the time to reply.  I'm new to the Ni stuff, and find the learning curve to be pretty sharp.

I'll do some rewiring and give this method a whirl.

Eric

 

0 Kudos
Message 9 of 13
(6,915 Views)

Hi John,

I guess the one head-scratcher I am still having is how is the counter linked to the analog input ai0?  In other words, how does it know to count off of ai0 rather than say ai1?  I would have thought there would be some code there to tell the counter which signal is its input.

TIA

Eric

 

0 Kudos
Message 10 of 13
(6,899 Views)