13.2.2 PWM Out [T-Series Datasheet] | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver


13.2.2 PWM Out [T-Series Datasheet]



T4 Capable DIO: DIO6, DIO7 (aka FIO6, FIO7)


T7 Capable DIO: DIO0, DIO2, DIO3, DIO4, DIO5 (aka FIO0, FIO2, FIO3, FIO4, FIO5)

Requires Clock Source: Yes

Index: 0

Streamable: No

This PWM Out Extended Feature generates a pulse width modulated wave form.


PWM output will set the DIO high and low relative to the clock source's count. When the count is zero the DIO line will be set high. When the count matches Config A the line will be set low. Therefore Config A is used to control the duty cycle and the resolution is equal to the roll value.

Clock#Frequency = CoreFrequency / DIO_EF_CLOCK#_DIVISOR   // typically 80M/Divisor
PWMFrequency = Clock#Frequency / DIO_EF_CLOCK#_ROLL_VALUE

For the common case of CoreFrequency = 80 MHz we can rewrite output frequency as:


... and for 50% duty-cycle (square wave) simply set:


CoreFrequency is always 80 MHz at this time, but in the future some low-power operational modes might result in different core frequencies.

The valid values for DIO_EF_CLOCK#_DIVISOR are 1, 2, 4, 8, 16, 32, 64, or 256, and a value of 0 (default) equates to a divisor of 1.  For more details about Clock#Frequency and DIO_EF_CLOCK#_DIVISOR, see the DIO-EF Clock Source section.

DIO_EF_CLOCK#_ROLL_VALUE is a 32-bit value for CLOCK0 and a 16-bit value for CLOCK1 & CLOCK2.

PWM Out is capable of glitch-free updates in most situations. A glitch-free update means that the PWM will finish the current period consisting of the high time then the low time before loading the new value. The next period will then have the new duty cycle. This is true for all cases except zero. When setting the duty cycle to zero, the line will be set low regardless of the current position. This means that a single high pulse with duration between zero and the previous high time can be output before the line goes low.

The clock roll value can take up to one PWM period to update and this does not block subsequent commands from being processed. It is possible to finish updating DIO_EF_CONFIG_A to a value greater than the non-updated clock roll value (which is invalid) but less than the updated clock roll value (which is valid) and throw the error 2565: EF_VALUE_GREATER_THAN_PERIOD.
Potential fixes:
  • disable and re-enable the clock line before updating the clock roll value and duty cycle value.
  • Delay for greater than one "non-updated" PWM period between updating the clock roll value and updating the duty cycle value


DIO#_EF_ENABLE: 0 = Disable, 1 = Enable
DIO#_EF_OPTIONS: Bits 0-2 specify which clock source to use ... b000 for Clock0, b001 for Clock1, and b010 for Clock2. All other bits are reserved and should be set to 0.
DIO#_EF_CONFIG_A: When the specified clocks source's count matches this value, the line will transition from high to low.
DIO#_EF_CONFIG_B: Not used.
DIO#_EF_CONFIG_C: Not used.
DIO#_EF_CONFIG_D: Not used.


The duty cycle can be updated at any time. To update, write the new value to DIO#_EF_CONFIG_A. The new value will not be used until the clock source rolls to zero. This means that at the end of the current period, the new value will be loaded—resulting in a glitch-free transition.


No information is returned by PWM Out.


Reset has no affect on this feature.


To generate a 10 kHz PWM starting at 25% DC, first configure the clock source.  The higher the roll value, the greater the duty cycle resolution will be. For the highest resolution, we want to maximize the roll value, so use the smallest clock divisor that will not result in a roll value greater than the clock source's maximum (32-bits or 16-bits). With a divisor of 1, the roll value will be 8000:

80 MHz / (1 * 8000) = 10 kHz

Now set the clock registers accordingly:


Once the clock source is configured, we can use the roll value to calculate CONFIG_A:

DC = 25% = 100 * CONFIG_A / 8000

...So CONFIG_A = 2000. Now the PWM can be turned on by writing the proper registers:


For a more detailed walkthrough, see Configuring a PWM Output.

Applicable Forum Topics

  • LabJack Support assisted a customer with configuring the digital I/O line "FIO0" to output a PWM signal to control a R/C style servo motor and then periodically update the frequency in a forum topic called: T7 PWM Output for Servo Motor Control.

T7 PWM Output Config

Configure settings to generate LJM pseudocode

T4 DIO channels: DIO6 and DIO7
T7 DIO channels: DIO0 and DIO2-DIO5

Desired DIO Channel:
Desired Frequency (Hz):
Desired Duty Cycle (%):
Select Clock Source:
Select Clock Divisor:


        // Compiling Code, if code doesn't appear please enable JavaScript or
        // try using an up to date version of Google Chrome/Mozilla Firefox.
        // Ideally an example of how to configure the T7's PWM functionality
        // will appear here.
Information regarding the functions used in this example are available on LJM's function reference page. Particularly, the generated pseudocode above ignores errors, but real applications should handle errors.

Support - General Psuedocode Compiler

Support - T7 PWM Output Config Script