Published on *LabJack* (https://labjack.com)

Requires firmware V1.1 or higher. This command creates pulses on any/all of D0-D7. The desired D lines must be set to output using another function (DigitalIO or AOUpdate). All selected lines are pulsed at the same time, at the same rate, for the same number of pulses.

Execution time for this function is about 20 milliseconds plus pulse output time.

This function commands the time for the first half cycle of each pulse, and the second half cycle of each pulse. Each time is specified by sending a value B & C, where the time is:

1st half-cycle microseconds = ~17 + 0.83C + 20.17BC

2nd half-cycle microseconds = ~12 + 0.83C + 20.17BC

... both of which can be approximated as:

microseconds = 20BC

So, if lowFirst is 0 (false), then 20B1C1 is the high time and 20B2C2 is the low time. If B1=C1=B2=C2=10, that would mean the low time is 2ms and the high time is 2ms, which means the period is 4ms, the frequency is 250Hz, and the duty-cycle is 50%.

For best accuracy when using the approximation, minimize C. B and C must be between 1 and 255, so each half cycle can vary from about 38/33 microseconds to just over 1.3 seconds.

If you have enabled the LabJack Watchdog function, make sure it's timeout is longer than the time it takes to output all pulses.

The timeout of this function, in milliseconds, is set to: 5000+numPulses((B1C1*0.02)+(B2C2*0.02))

PWM Output:

Wanting to output PWM? Other LabJacks are much better at PWM, but you can use these PulseOut functions on the U12 to create PWM. To simplify things we will use the 20BC approximation and will set C1=C2, so we can just call it C. That means:

Period = 20B1C + 20B2C = 20C * (B1 + B2)

First, get the frequency you want. Say you want 200 Hz, which is a period of 5000us. That means:

5000 = 20C * (B1 + B2)

B1 + B2 = 250/C

We want to choose C such that it is as small as possible to help with the accuracy of the approximation, but we want to keep B1 + B2 <= 255 so we can get the full range of duty cycle. We will choose C=1 for this example, so:

B1 + B2 = 250

Now we know that with C1=C2=1, and B1 + B2 = 250, we will get a frequency of about 200Hz. If lowFirst is 0, then 20B1C2 is the high time and thus the duty cycle is:

DutyCycle = B1 / (B1 + B2) = B1 / 250

So, if B1=50, B2=200, C1=C2=1, we get a frequency of about 200 Hz and duty cycle of about 20%.

Declaration:

```
long PulseOut ( long *idnum,
long demo,
long lowFirst,
long bitSelect,
long numPulses,
long timeB1,
long timeC1,
long timeB2,
long timeC2)
```

Parameter Description:

Returns: LabJack errorcodes or 0 for no error.

Inputs:

***idnum**– Local ID, serial number, or -1 for first found.**demo**– Send 0 for normal operation, >0 for demo mode. Demo mode allows this function to be called without a LabJack.**lowFirst**– If >0, each line is set low then high, otherwise the lines are set high then low.**bitSelect**– Set bits 0 to 7 to enable pulsing on each of D0-D7 (0-255).**numPulses**– Number of pulses for all lines (1-32767).**timeB1**– B value for first half cycle (1-255).**timeC1**– C value for first half cycle (1-255).**timeB2**– B value for second half cycle (1-255).**timeC2**– C value for second half cycle (1-255).

Outputs:

***idnum**– Returns the local ID or –1 if no LabJack is found.