Skip to main content
Skip table of contents

13.2.2 PWM Out [T-Series Datasheet]

Overview

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

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

T8 Capable DIO: DIO2, DIO3, DIO4, DIO5, DIO6, DIO7, DIO8, DIO11, DIO12 (aka FIO2, FIO3, FIO4, FIO5, FIO6, FIO7, EIO0, EIO3, EIO4)

Requires Clock Source: Yes

Index: 0

Streamable: No

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

Operation

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
PWMFrequency = Clock#Frequency / DIO_EF_CLOCK#_ROLL_VALUE
DutyCycle% = 100 * DIO#_EF_CONFIG_A / DIO_EF_CLOCK#_ROLL_VALUE

See the DIO-EF Clock Source section for more information about your device core frequency and DIO_EF clock source settings.

DIO_EF_CLOCK#_ROLL_VALUE is a 32-bit value for CLOCK0 and a 16-bit value for CLOCK1 & CLOCK2. A value of 0 corresponds to the max roll value of 232 for the 32-bit clock or 216 for 16-bit clocks.

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

Configure

DIO#_EF_ENABLE: 0 = Disable, 1 = Enable
DIO#_EF_INDEX: 0
DIO#_EF_CLOCK_SOURCE (formerly DIO#_EF_OPTIONS): Specify which clock source to use. 0 for Clock0, 1 for Clock1, or 2 for Clock2.
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.

Update

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.

Read

No information is returned by PWM Out.

Reset

Reset has no effect on this feature.

Example

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, you must maximize the roll value, so use the smallest clock divisor that will not result in a roll value greater than the clock source's size (32-bits or 16-bits). For a more detailed walkthrough, see Configuring a PWM Output.

T4/T7 Pseudocode

With a divisor of 1, the roll value will be 8000:

80 MHz / (1 * 8000) = 10 kHz

Set the clock registers accordingly:

DIO_EF_CLOCK0_ENABLE = 0
DIO_EF_CLOCK0_DIVISOR = 1
DIO_EF_CLOCK0_ROLL_VALUE = 8000
DIO_EF_CLOCK0_ENABLE = 1

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

DC = 25% = 100 * CONFIG_A / 8000

CONFIG_A = 25 * 8000 / 100 = 2000

Now the PWM can be turned on by writing to the proper registers (use DIO4 on the T4):

DIO0_EF_ENABLE = 0
DIO0_EF_INDEX = 0
DIO0_EF_CONFIG_A = 2000
DIO0_EF_ENABLE = 1

T8 Pseudocode

With a divisor of 1, the roll value will be 10000:

100 MHz / (1 * 10000) = 10 kHz

Set the clock registers accordingly:

DIO_EF_CLOCK0_ENABLE = 0
DIO_EF_CLOCK0_DIVISOR = 1
DIO_EF_CLOCK0_ROLL_VALUE = 10000
DIO_EF_CLOCK0_ENABLE = 1

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

DC = 25% = 100 * CONFIG_A / 10000

CONFIG_A = 25 * 10000 / 100 = 2500

Now the PWM can be turned on by writing to the proper registers:

DIO0_EF_ENABLE = 0
DIO0_EF_INDEX = 0
DIO0_EF_CONFIG_A = 2500
DIO0_EF_ENABLE = 1

JavaScript errors detected

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

If this problem persists, please contact our support.