Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Using external clocking to implement a frequency divider in .NET

Hi,

 

I've modified one of the example .NET projects to take an external clock over PFI0 and then output half the frequency on PFI1 by writing out a 0,1,0,1 ... waveform clocked by the PFI0.  

 

My code is here:

 

http://pastebin.com/qrtJNYWA

 

This works great, but I have several questions:

 

1)  The arguments to WriteMultiSamplePort are int32, does this mean that I'm changing all the PFI lines everytime I write to this?  So bit 0 is PFI 0, bit 1 is PFI 1?  Sorry for a basic question but I could not locate any documentation about what this function does.

 

2)  When I feed it a small buffer (say 2 words) it fails with a buffer underrun for high external frequencies.  Am I right in thinking that setting ConfigureSampleClock to ContinuousSamples+Rising Edge means that every rising edge it consumes one word from that buffer and copies it over the PFI pins?  And then when the buffer is depleted it starts again from the start?  

 

Finally, does this approach make sense?  It works well enough, but I have a sneaking suspicion that theres a more elegant way to do this using counters or something like that 🙂

 

Thanks,

Mike

0 Kudos
Message 1 of 4
(5,116 Views)

Mike,

 

Please follow this KnowledgeBase to install the appropiate MesaurementStudio Help files for proper documentation:

http://digital.ni.com/public.nsf/allkb/7082CE3F3940540E8625797C007F25B6

 

I don't exactly follow your first question so looking through this should help.

 

As far as underflow errors, you are correct. Underflow occurs with you run out of data on the buffer to write out to the DAQ device. Therefore, making sure you are putting data into the buffer fast enough/making sure there is enough data for finite writes is essential.

Daniel G.
Semiconductor & Wireless
National Instruments
0 Kudos
Message 2 of 4
(5,108 Views)

@AleAlejandro wrote:

Mike,

 

Please follow this KnowledgeBase to install the appropiate MesaurementStudio Help files for proper documentation:

http://digital.ni.com/public.nsf/allkb/7082CE3F3940540E8625797C007F25B6

 


 

Yes I've seen that, but the documentation was not entirely clear for me.  Specifically, the WriteMultiSamplePort prototype used in the example files has the prototype WriteMultiSamplePort(bool, int[]).  The documentation does not include an entry for that overload, hence I'm unclear on how the inputs are interpreted.

 

If you have a link to a more complete set of documentation, that would be helpful.  

 


@AleAlejandro wrote:

As far as underflow errors, you are correct. Underflow occurs with you run out of data on the buffer to write out to the DAQ device. Therefore, making sure you are putting data into the buffer fast enough/making sure there is enough data for finite writes is essential.



Thanks, but I wasn't asking about underflow.  Do you have any insight into how the ConfigureSampleClock function works?  The documention is extremely cryptic.  

0 Kudos
Message 3 of 4
(5,102 Views)

Here is another forum post which talks about it:

http://forums.ni.com/t5/Multifunction-DAQ/usb-2009-Task-Timing-ConfigureSampleClock-fails/td-p/98498...

 

and this paper: http://www.ni.com/white-paper/2835/en/

 

National Instruments
Applications Engineer
0 Kudos
Message 4 of 4
(5,092 Views)