Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>According to the <a href="http://www.mathworks.com/products/daq/supportedio14004.html" rel="nofollow noreferrer">Supported Hardware documentation</a>, version 2.8 or greater of the <a href="http://www.mathworks.com/access/helpdesk/help/toolbox/daq/daq_product_page.html" rel="nofollow noreferrer">Data Acquisition Toolbox</a> is needed to support a Measurement Computing USB-1024HLS device. Assuming you have version 2.8 or newer, the following should come close to a solution for you...</p> <p>The first step would be to get the hardware ID for the device. The function <a href="http://www.mathworks.com/access/helpdesk/help/toolbox/daq/daqhwinfo.html" rel="nofollow noreferrer">DAQHWINFO</a> should help with this:</p> <pre><code>deviceInfo = daqhwinfo('mcc'); </code></pre> <p>The hardware ID gotten from the structure <strong>deviceInfo</strong> can then be used to create a Digital I/O Object (DIO) using the <a href="http://www.mathworks.com/access/helpdesk/help/toolbox/daq/digitalio.html" rel="nofollow noreferrer">DIGITALIO</a> function:</p> <pre><code>dio = digitalio('mcc',hardwareID); </code></pre> <p>Next, you have to add two output lines (for a clock signal and a pulse-width modulation (PWM) signal) using <a href="http://www.mathworks.com/access/helpdesk/help/toolbox/daq/addline.html" rel="nofollow noreferrer">ADDLINE</a>:</p> <pre><code>addline(dio,0:1,'out'); </code></pre> <p>Then, you have to set a few DIO properties.</p> <pre><code>set(dio,'TimerPeriod',0.000002); % i.e. 500 kHz set(dio,'TimerFcn',@update_outputs); </code></pre> <p>The function <strong>update_outputs</strong> is called once every timer period and should set the output pins to the appropriate values. The <a href="http://en.wikipedia.org/wiki/Clock_signal" rel="nofollow noreferrer">clock signal</a> is simply going to switch back and forth between 0 and 1 every timer period. The <a href="http://en.wikipedia.org/wiki/Pulse-width_modulation" rel="nofollow noreferrer">PWM signal</a> will likely alternate between 0 and 1 as well, but it will not change every timer period, remaining in each state for a set amount of time based upon the sort of pulse-width modulation you want. Here's what your <strong>update_outputs</strong> function may end up looking like:</p> <pre><code>function update_outputs(obj,event) currentValues = getvalue(obj); clockValue = ~currentValues(1); pwmValue = pwm_compute(); putvalue(obj,[clockValue pwmValue]); end </code></pre> <p>Note that this uses <a href="http://www.mathworks.com/access/helpdesk/help/toolbox/daq/putvalue.html" rel="nofollow noreferrer">PUTVALUE</a> and <a href="http://www.mathworks.com/access/helpdesk/help/toolbox/daq/getvalue.html" rel="nofollow noreferrer">GETVALUE</a> to set/get the values of the output pins. You will have to write the function <strong>pwm_compute</strong> such that it computes a new PWM value for each time period. Since <strong>pwm_compute</strong> will likely have to know how many values have been output already (i.e. how many times it has already been called), you can track that using a <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/persistent.html" rel="nofollow noreferrer">persistent variable</a>:</p> <pre><code>function newValue = pwm_compute persistent nValues; if isempty(nValues) nValues = 0; else nValues = nValues+1; end ... % Compute the new value for the (nValues+1) time period ... end </code></pre> <p>This is just one possible solution. You could potentially precompute the PWM signal and pull the value for each timer period from a vector or data file, or you could potentially use the <a href="http://www.mathworks.com/access/helpdesk/help/toolbox/daq/timerfcn.html" rel="nofollow noreferrer"><strong>event</strong> data structure</a> passed to <strong>update_outputs</strong> to get the time of the timer event (relative to the DIO timer start, I believe).</p> <p>Finally, you have to start the DIO:</p> <pre><code>start(dio); </code></pre> <p>...and, once you're finished using it, delete it and clear it from memory:</p> <pre><code>delete(dio); clear dio; </code></pre> <h2>One potential stumbling block...</h2> <p>Generating a 500 kHz signal could be difficult. It's such a high frequency that you <em>may</em> run into problems, specifically with the 'TimerFcn', which is called once every timer period. If the 'TimerFcn' takes longer than 0.000002 seconds to run, <a href="http://www.mathworks.com/access/helpdesk/help/toolbox/daq/timerfcn.html" rel="nofollow noreferrer">some timer events may not be processed</a>, leading to an output that is actually of a lower frequency. I have a feeling you may have to use a lower signal frequency for things to work properly, but I could be wrong. =)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload