Skip to main content

Module pca9685

Module pca9685 

Source
Expand description

NXP PCA9685 16-channel, 12-bit PWM controller.

The PCA9685 drives sixteen independent PWM outputs at one shared frequency, which is what makes it the usual way to run a bank of servos, dimmable LEDs, or the speed and direction inputs of motor drivers from a single I2C device. This module builds the values that program it: the prescaler that sets the output frequency, the address of each channel’s registers, and the 12-bit on/off word that sets a channel’s phase and duty, with the full-on and full-off encodings the datasheet defines.

It is pure logic: a caller writes the bytes to the device over whatever performs the I2C transfers.

Modules§

mode1
Bit masks for the MODE1 register.
register
The PCA9685 register addresses.

Structs§

Pwm
A channel’s PWM setting: when in the period it turns on and when it turns off.

Constants§

CHANNELS
The number of PWM channels.
COUNTS
The number of counts in one PWM period (12-bit resolution).
INTERNAL_OSC_HZ
The frequency of the internal oscillator, 25 MHz.
MODE1_RESET
The power-on value of MODE1 (0x11): sleeping, responding to the All Call address.
PRE_SCALE_RESET
The power-on value of the PRE_SCALE register (0x1E), about 200 Hz at 25 MHz.

Functions§

channel_register
Returns the address of a channel’s first register (its on-count low byte).
frequency_for_prescale
Computes the PWM frequency a PRE_SCALE value produces.
prescale_for_frequency
Computes the PRE_SCALE value for a desired PWM frequency.