ServoKit.PCA9685.Util (servo_kit v0.0.8) View Source

A collection of functions that are used for the PCA9685 driver.

Link to this section Summary

Functions

Calculates the PWM frequency in Hz based on specified prescale value and reference clock speed.

Calculates the PWM frequency prescale based on the formula in Datasheet 7.3.5.

Calculates 16-bit pulse range from a duty cycle in percent.

Link to this section Functions

Link to this function

frequency_from_prescale(prescale, reference_clock_speed)

View Source

Specs

frequency_from_prescale(integer(), integer()) :: integer()

Calculates the PWM frequency in Hz based on specified prescale value and reference clock speed.

iex> ServoKit.PCA9685.Util.frequency_from_prescale(255, 25_000_000)
24
iex> ServoKit.PCA9685.Util.frequency_from_prescale(121, 25_000_000)
50
iex> ServoKit.PCA9685.Util.frequency_from_prescale(60, 25_000_000)
102
Link to this function

prescale_from_frequecy(freq_hz, reference_clock_speed)

View Source

Specs

prescale_from_frequecy(24..1526, integer()) :: 3..255

Calculates the PWM frequency prescale based on the formula in Datasheet 7.3.5.

# Formula
prescale_value = round(osc_value / (4096 * update_rate)) - 1
iex> ServoKit.PCA9685.Util.prescale_from_frequecy(24, 25_000_000)
253
iex> ServoKit.PCA9685.Util.prescale_from_frequecy(50, 25_000_000)
121
iex> ServoKit.PCA9685.Util.prescale_from_frequecy(100, 25_000_000)
60
iex> ServoKit.PCA9685.Util.prescale_from_frequecy(1526, 25_000_000)
3
Link to this function

pulse_range_from_duty_cycle(percent)

View Source

Specs

pulse_range_from_duty_cycle(float()) :: {0, 0..4095}

Calculates 16-bit pulse range from a duty cycle in percent.

iex> ServoKit.PCA9685.Util.pulse_range_from_duty_cycle(0)
{0, 0}
iex> ServoKit.PCA9685.Util.pulse_range_from_duty_cycle(50)
{0, 2048}
iex> ServoKit.PCA9685.Util.pulse_range_from_duty_cycle(100)
{0, 4095}