Skip to main content
Skip table of contents

Configuring a PWM Output

T-series devices have various configurable clock sources as part of the Digital I/O Extended Feature (DIO-EF) system. In this example we will use the Kipling Register Matrix to configure an output for a PWM signal. For this example we use clock 0 with default settings. The clock source is the base for configuring PWM output. In this example we will set the frequency to 100 Hz and the duty cycle to 25%.

Before you begin

This example uses FIO0 (aka DIO0) which supports PWM output on the T7. For the T8 use FIO2 (DIO2) instead. For the T4 use FIO6 (DIO6) instead.

1. Go to the Register Matrix in Kipling and type "dio0" in the search box to narrow the list of registers. Add the ENABLE and CONFIG_A registers to the active list as shown.

2. Change the search term to "clock0" and add the DIO_EF_CLOCK0_ENABLE and the DIO_EF_CLOCK0_ROLL_VALUE to the active list. The base clock frequency varies by device. On the T8 it is 100 MHz, on the T7 and T4 it is 80 MHz.

To get 100 Hz on the T4 and T7, we need to divide by 800000. Since our divisor is 1 (default), our roll value is 800000.
80 MHz / (1 * 800000) = 100 Hz

To get 100 Hz on the T8, we need to divide by 1000000. Since our divisor is 1 (default), our roll value is 1000000.
100 MHz / (1 * 1000000) = 100 Hz
To configure the duty cycle: 25% = 100 * Config_A / Roll_Value, so CONFIG_A is 200000 on the T4 and T7 or 250000 on the T8.

3. Write your configuration values, replacing DIO# with the DIO number you are configuring the feature on:
DIO#_EF_ENABLE = 0 // Cannot change index if enabled

DIO_EF_CLOCK0_ENABLE = 0 // Disable the clock for config
DIO_EF_CLOCK0_ROLL_VALUE = 800000 // On the T4 and T7. 1000000 on the T8

DIO#_EF_INDEX = 0 // PWM out index
DIO#_EF_CONFIG_A = 200000 // On the T4 and T7. 250000 on the T8.
DIO_EF_CLOCK0_ENABLE = 1 // Enable the clock
DIO#_EF_ENABLE = 1 // Enable the PWM

4. At this point the LabJack is outputting PWM on FIO0 at 100Hz with 25% duty cycle. To see the output, see the section below titled "Displaying PWM output in LJStreamM"


5. To save the configuration, so the PWM will be configured at boot-up, go to the Power-Up Defaults tab and click Configure Power-up Defaults. Make sure that Current Device Settings option is selected. This is suggested if using LJLogM or LJStreamM, or other simple polling programs, but not needed if your software will do the configuration.

Troubleshooting

Touching a conductor to the top of the screw head of an un-clamped screw terminal is rarely a valid connection.  The screw head is usually valid when the terminal is clamped, but the only guaranteed valid connection is to securely clamp a conductor inside the screw terminal.

Displaying PWM in LJLogM

Once the PWM output is enabled (above), you can read FIO0 using any row in LJLogM. Change the interval to 1ms and the number of displayed results to 500. The graphed result should show a PWM graph with 25% duty cycle. To see the outputted waveform better, use LJStreamM.

Displaying PWM in LJStreamM

Once the PWM is enabled (above), you can read FIO0 using any row in LJStreamM. Set the scan rate to 10000Hz and the graph history to 1000 scans to see the PWM more clearly. Once the stream is started you should see the outputted PWM in the waveform output.

Configuring PWM in DAQFactory

To configure the counter you can use steps 1-5 above or write to the previously mentioned registers in DAQFactory. See "Device Configuration" on the DAQFactory for LJM page.

Configuring PWM in Your Program

A very handy tool that is available is the PWM pseudocode generator on the PWM extended feature page. Otherwise, to configure PWM check the registers above that need to be written to. You can do this with a few calls to eWriteName or a single call to eWriteNames. When using eWriteNames you need to be sure to configure them according to the order specified above.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.