# PWM Out - OSC
[OSC]

Generate PWM signals with the Application Board via OSC. More...

Generate PWM signals with the Application Board via OSC.

## Devices

There are 4 PWM controllers available on the Application Board, numbered 0 - 3.

Each PWM Out controls a pair of Digital Outs - an A and a B channel:

- PwmOut 0 - Digital Outs 0 (A) and 1 (B).
- PwmOut 1 - Digital Outs 2 (A) and 3 (B).
- PwmOut 2 - Digital Outs 4 (A) and 5 (B).
- PwmOut 3 - Digital Outs 6 (A) and 7 (B).

Each channel can also be set to invert the given PWM signal.

## Properties

Each PWM Out has the following properties:

- duty
- invA
- invB
- active
- dividerAValue
- dividerAMux
- dividerBValue
- dividerBMux
- clockSource
- alignment
- polarity

### Duty

The duty property corresponds to the duty at which a load connected to the output is being driven. This value can be both read and written. The range of values expected by the board is from 0 - 1023.

To generate a 75% on PWM signal, send a message like

    /pwmout/1/duty 768

Leave the argument value off to read the duty:

    /pwmout/1/duty

### invA

The invA property corresponds to the inversion of the A channel of a PWM Out. This value can be both read and written, and the range of values expected is simply 0 or 1. 1 means inverted and 0 means normal. 0 is the default.

To set the A channel of the second PWM Out as inverted, send the message

    /pwmout/1/invA 1

Note that the A channel of PWM Out 1 is Digital Out 2.

### invB

The invB property corresponds to the inversion of the B channel of a PWM Out. This value can be both read and written, and the range of values expected is simply 0 or 1. 1 means inverted and 0 means normal. 0 is the default.

To set the B channel of the fourth PWM Out back to normal, send the message

    /pwmout/1/invB 0

Note that the A channel of PWM Out 1 is Digital Out 7.

### Active

The active property corresponds to the active state of the PWM Out. If the device is set to be active, no other tasks will be able to use its 2 digital out lines. If you're not seeing appropriate responses to your messages to the PWM Out, check the whether it's locked by sending a message like

    /pwmout/0/active

If you're no longer using the PWM Out, it's a good idea to free the 2 Digital Outs by sending the message

    /pwmout/0/active 0

## Period adjustment of the PWM unit

The below values allow you to adjust the period length to all possible values as supported by the physical limits of the Make Controller. Before altering the values, it is good to understand a little about the subsustem of the PWM module. Please see the general introduction in the PWM (Pulse Width Modulation) section.

### DividerBValue

The dividerXValue property corresponds to the linear divider value within clock divider module X of the PWM Out. This value can be between 0 and 255, and linearly divides the clock that is fed into it. You can change the incomming clock value by altering the DividerAMux parameter. Higher linear divider values mean a longer period.

Default value of DividerA is 4. Default value of DividerB is 0.

### DividerAMux & DividerBMux

The dividerAMux and dividerBMux properties select the incoming clock value for divider module A or B (respectively) of the PWM Out. This value ranges between 0 and 10. This is similar to the clock source value, eg. a DividerAMux value of 5 = a clock rate of MasterClock/(2^5)

Increasing this value will substantially increase the period of the PWM. Use the DividerXValue parameter to more finely tune the value of the period.

Default value of MuxA is 4. Default value of MuxB is 0.

### ClockSource

The clockSource property selects the incoming clock value for the specified PWM channel. A clock source of 0-10 represents the Master clock divided by 2 to the power of the Clock Source Value, eg. a clock source value of 5 = a clock rate of MasterClock/(2^5). A value of 11 sets the Clock source to be generated by clock Divider A. A value of 12 sets the Clock source to be generated by clock Divider B

The default value is 11 (Divider A).

### WaveformAlignment

The waveformAlignment property chooses whether the channel is left aligned or center aligned. The following values are valid:

- 0 = Left aligned
- 1 = Center aligned

A left aligned channel counts up to the maximum duty cycle, then resets the counter. A center aligned channel counts up to the maximum duty cycle, then counts down to zero, etc. The default is left aligned.

### WaveformPolarity

The polarity property chooses whether the channel begins its period high or low. The following values are valid:

- 0 = Normal Polarity
- 1 = Inverted Polarity

Normal polarity starts low, then goes high. Inverted polarity starts high, then goes low. The default is inverted polarity.