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.
mode2
The MODE2 register bits.
register
The PCA9685 register addresses.
sim
A PCA9685 that is not there.

Structs§

Output
One channel’s setting, the command a Pca9685 takes as an [Actuator].
Outputs
How the sixteen outputs are wired, the MODE2 register.
Pca9685
A PCA9685 on an I2C bus, driving up to sixteen PWM outputs.
Pwm
A channel’s PWM setting: when in the period it turns on and when it turns off.

Constants§

ALLCALL_ADDR_RESET
The power-on value of ALLCALLADR (0xE0), the LED All Call address.
CHANNELS
The number of PWM channels.
COUNTS
The number of counts in one PWM period (12-bit resolution).
DEFAULT_I2C_ADDRESS
The I2C address with the six address pins low.
INTERNAL_OSC_HZ
The frequency of the internal oscillator, 25 MHz.
LED_OFF_H_RESET
The power-on value of every channel’s LEDn_OFF_H (0x10): the full-off bit set, so each output starts off. The channel’s other three registers start at zero.
MODE1_RESET
The power-on value of MODE1 (0x11): sleeping, responding to the All Call address.
MODE2_RESET
The reset value of MODE2: totem-pole outputs, not inverted, change on STOP.
OSCILLATOR_STARTUP_MICROS
How long the oscillator takes to run after the SLEEP bit is cleared, in microseconds; channel timing is not guaranteed inside this window and the RESTART bit must not be written before it has passed.
PRE_SCALE_MIN
The smallest value the part loads into PRE_SCALE; a smaller write loads this.
PRE_SCALE_RESET
The power-on value of the PRE_SCALE register (0x1E), about 200 Hz at 25 MHz.
SOFTWARE_RESET_ADDRESS
The general-call address the software reset is sent to.
SOFTWARE_RESET_BYTE
The one data byte the software reset carries; any other byte is not acknowledged.
SUBADR1_RESET
The power-on value of SUBADR1 (0xE2), the first programmable subaddress.
SUBADR2_RESET
The power-on value of SUBADR2 (0xE4).
SUBADR3_RESET
The power-on value of SUBADR3 (0xE8).

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.