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
Pca9685takes 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.
- SUBAD
R1_ RESET - The power-on value of SUBADR1 (0xE2), the first programmable subaddress.
- SUBAD
R2_ RESET - The power-on value of SUBADR2 (0xE4).
- SUBAD
R3_ 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.