# PWM Out
[Libraries]

The PWM Out subsystem underlies the DC Motor subsystem and controls the 4 PWM signals on the SAM7X. More...

## Functions
int | PwmOut_SetActive (int index, int state)
| Sets whether the specified PWM device is active.
int | PwmOut_GetActive (int index)
| Returns the active state of the LED.
int | PwmOut_SetDuty (int index, int duty)
| Set the speed of a PWM device.
int | PwmOut_GetDuty (int index)
| Read the current duty of a PWM device.
int | PwmOut_SetInvertA (int index, char invert)
| Set whether the A channel associated with a PWM out should be inverted.
int | PwmOut_GetInvertA (int index)
| Read whether the A channel of a PWM device is inverted.
int | PwmOut_SetInvertB (int index, char invert)
| Read whether the B channel of a PWM out is inverted.
int | PwmOut_GetInvertB (int index)
| Read whether the B channel of a PWM device is inverted.
int | PwmOut_SetInvert (int index, char invertA, char invertB)
| Set whether the 2 channels of a PWM device are inverted.
int | PwmOut_SetAll (int index, int duty, char invertA, char invertB)
| Set the duty and the inversion of both channels of a PWM device.
int | PwmOut_SetDividerAValue (int val)
| Set the divider A value.
int | PwmOut_GetDividerAValue ()
| Read the divider A value.
int | PwmOut_SetDividerAMux (int mux)
| Set the divider A mux value.
int | PwmOut_GetDividerAMux ()
| Read the divider A mux value.
int | PwmOut_SetDividerBValue (int val)
| Set the divider B value.
int | PwmOut_GetDividerBValue ()
| Read the divider B value.
int | PwmOut_SetDividerBMux (int mux)
| Set the divider B mux value.
int | PwmOut_GetDividerBMux ()
| Read the divider B mux value.
int | PwmOut_SetWaveformAlignment (int index, int val)
| Set the alignment of a channel's waveform.
int | PwmOut_GetWaveformAlignment (int index)
| Read the configured waveform alignment for a given PWM channel.
int | PwmOut_SetWaveformPolarity (int index, int val)
| Set the Waveform Polarity for a PWM channel.
int | PwmOut_GetWaveformPolarity (int index)
| Read the waveform polarity for a given channel.

## Detailed Description

The PWM Out subsystem underlies the DC Motor subsystem and controls the 4 PWM signals on the SAM7X.

Each PWM device 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).

The A and B channels of a PWM device can be set independently to be inverted, or not, from one another in order to control motors, lights, etc.

The simplest way to get started is simply with a call to PwmOut_SetActive() and then to PwmOut_SetDuty() - this will allow you to control simple dimming and motors. If you need to adjust timing, inversion or other parameters, delve a bit deeper into the API above.

PwmOut relies on the internal PWM (Pulse Width Modulation) system. See that page for more info on the timing issues involved with the PWM Out system.

## Function Documentation

int PwmOut_GetActive | ( | int | index | ) |

Returns the active state of the LED.

Parameters:

  | index | An integer specifying which PWM device (0-3).

Returns:
  Zero on success.

Definition at line 114 of file pwmout.c.

int PwmOut_GetDividerAMux | ( | void |  | ) |

Read the divider A mux value.

Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Returns:
  the divider A mux value (0 - 10)

See also:
  PwmOut_SetDividerAMux( )

Definition at line 511 of file pwmout.c.

int PwmOut_GetDividerAValue | ( | void |  | ) |

Read the divider A value.

Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Returns:
  the divider A value (0 - 255)

See also:
  PwmOut_SetDividerAValue( )

Definition at line 479 of file pwmout.c.

int PwmOut_GetDividerBMux | ( | void |  | ) |

Read the divider B mux value.

Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Returns:
  the divider B mux value (0 - 10)

See also:
  PwmOut_SetDividerBMux( )

Definition at line 577 of file pwmout.c.

int PwmOut_GetDividerBValue | ( | void |  | ) |

Read the divider B value.

Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Returns:
  the divider B value (0 - 255)

See also:
  PwmOut_SetDividerBValue( )

Definition at line 544 of file pwmout.c.

int PwmOut_GetDuty | ( | int | index | ) |

Read the current duty of a PWM device.

Parameters:

  | index | An integer specifying which PWM device (0-3).

Returns:
  The duty (0 - 1023).

Definition at line 147 of file pwmout.c.

int PwmOut_GetInvertA | ( | int | index | ) |

Read whether the A channel of a PWM device is inverted.

Parameters:

  | index | An integer specifying which PWM device (0-3).

Returns:
  The inversion - 1/non-zero (inverted) or 0 (normal).

Definition at line 195 of file pwmout.c.

int PwmOut_GetInvertB | ( | int | index | ) |

Read whether the B channel of a PWM device is inverted.

Parameters:

  | index | An integer specifying which PWM device (0-3).

Returns:
  The inversion - 1/non-zero (inverted) or 0 (normal).

Definition at line 248 of file pwmout.c.

int PwmOut_GetWaveformAlignment | ( | int | index | ) |

Read the configured waveform alignment for a given PWM channel.

Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Parameters:

  | index | The PWM channel (0-3) you'd like to read from.

Returns:
  the waveform alignment - see PwmOut_SetWaveformAlignment( )

Definition at line 612 of file pwmout.c.

int PwmOut_GetWaveformPolarity | ( | int | index | ) |

Read the waveform polarity for a given channel.

Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Parameters:

  | index | The PWM channel (0-3) that you'd like to read from.

Returns:
  The configured polarity for that channel.

See also:
  PwmOut_SetWaveformPolarity( )

Definition at line 652 of file pwmout.c.

int PwmOut_SetActive | ( | int | index,
|  | int | state |
| ) |  |  |

Sets whether the specified PWM device is active.

Parameters:

  | index | An integer specifying which PWM device (0-3).
  | state | An integer specifying the active state - 1 (active) or 0 (inactive).

Returns:
  Zero on success.

Definition at line 98 of file pwmout.c.

int PwmOut_SetAll | ( | int | index,
|  | int | duty,
|  | char | invertA,
|  | char | invertB |
| ) |  |  |

Set the duty and the inversion of both channels of a PWM device.

This is a convenience function to set all the properties of a PWM device in a single call.
It is equivalent to separate calls to PwmOut_SetInvert() and PwmOut_SetDuty().

Parameters:

  | index | An integer specifying which PWM out.
  | duty | An integer specifying the duty (0 - 1023).
  | invertA | A character specifying the inversion of the A channel - 1/non-zero (inverted) or 0 (normal).
  | invertB | A character specifying the inversion of the B channel - 1/non-zero (inverted) or 0 (normal).

Returns:
  Zero on success

Definition at line 310 of file pwmout.c.

int PwmOut_SetDividerAMux | ( | int | mux | ) |

Set the divider A mux value.

Parameters:

  | mux | The mux value (between 0 and 10) Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Returns:
  0 on success.

Definition at line 490 of file pwmout.c.

int PwmOut_SetDividerAValue | ( | int | val | ) |

Set the divider A value.

Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Parameters:

  | val | The value (between 0 and 255)

Returns:
  0 on success.

Definition at line 457 of file pwmout.c.

int PwmOut_SetDividerBMux | ( | int | mux | ) |

Set the divider B mux value.

Parameters:

  | mux | The mux value (between 0 and 10) Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Returns:
  0 on success.

Definition at line 555 of file pwmout.c.

int PwmOut_SetDividerBValue | ( | int | val | ) |

Set the divider B value.

Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Parameters:

  | val | The value (between 0 and 255)

Returns:
  0 on success.

Definition at line 522 of file pwmout.c.

int PwmOut_SetDuty | ( | int | index,
|  | int | duty |
| ) |  |  |

Set the speed of a PWM device.

Parameters:

  | index | An integer specifying which PWM device (0-3).
  | duty | An integer (0 - 1023) specifying the duty.

Returns:
  Zero on success.

Definition at line 127 of file pwmout.c.

int PwmOut_SetInvert | ( | int | index,
|  | char | invertA,
|  | char | invertB |
| ) |  |  |

Set whether the 2 channels of a PWM device are inverted.

This is a convenience function, and is equivalent to making separate calls to PwmOut_SetInvertA() and PwmOut_SetInvertB().

Parameters:

  | index | An integer specifying which PWM device (0-3).
  | invertA | A character specifying the inversion of the A channel - 1/non-zero (inverted) or 0 (normal).
  | invertB | A character specifying the inversion of the B channel - 1/non-zero (inverted) or 0 (normal).

Returns:
  Zero on success.

Definition at line 277 of file pwmout.c.

int PwmOut_SetInvertA | ( | int | index,
|  | char | invert |
| ) |  |  |

Set whether the A channel associated with a PWM out should be inverted.

Parameters:

  | index | An integer specifying which PWM device (0-3).
  | invert | A character specifying the inversion - 1/non-zero (inverted) 0 (normal).

Returns:
  Zero on success.

Definition at line 168 of file pwmout.c.

int PwmOut_SetInvertB | ( | int | index,
|  | char | invert |
| ) |  |  |

Read whether the B channel of a PWM out is inverted.

Parameters:

  | index | An integer specifying which PWM device (0-3).
  | invert | A character specifying the inversion - 1/non-zero (inverted) 0 (normal).

Returns:
  Zero on success.

Definition at line 221 of file pwmout.c.

int PwmOut_SetWaveformAlignment | ( | int | index,
|  | int | val |
| ) |  |  |

Set the alignment of a channel's waveform.

Valid values are:

- 0 = Left Aligned (default)
- 1 = Center Aligned

Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Parameters:

  | index | The PWM channel (0-3) that you'd like to configure.
  | val | The alignment value, as described above.

Returns:
  0 on success.

Definition at line 593 of file pwmout.c.

int PwmOut_SetWaveformPolarity | ( | int | index,
|  | int | val |
| ) |  |  |

Set the Waveform Polarity for a PWM channel.

Valid values are:

- 0 = Start Waveform Low
- 1 = Start Waveform High (default)

Contributed by TheStigg - http://www.makingthings.com/author/thestigg

Parameters:

  | index | The PWM channel (0-3) that you'd like to configure.
  | val | The value, as described above.

Returns:
  0 on success.

Definition at line 632 of file pwmout.c.