The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Device::Chip::PCA9685 - A Device::Chip implementation for the PCA9685 chip

DESCRIPTION

This class implements a Device::Chip interface for the PCA9685 chip, a 12-bit 16 channel PWM driver.

SYNOPSIS

    use Device::Chip::PCA9685;
    use Device::Chip::Adapter;

    my $adapter = Device::Chip::Adapter->new_from_description("LinuxKernel");

    my $chip = Device::Chip::PCA9685->new();
    # This is the i2c bus on an RPI 2 B+
    $chip->mount($adapter, bus => '/dev/i2c-1')->get;
    
    $chip->enable()->get;
    $chip->set_frequency(400)->get; # 400 Hz
    
    $chip->set_channel_value(10, 1024)->get; # Set channel 10 to 25% (1024/4096)
    
    $chip->set_channel_full_value(10, 1024, 3192)->get; # Set channel 10 to ON at COUNTER=1024, and OFF at COUNTER=3192 (50% duty cycle, with 25% phase difference)

METHODS

set_channel_value

    $chip->set_channel_value($channel, $time_on, $offset = 0)->get
    

Sets a channel PWM time based on a single value from 0-4095. Starts the channel to turn on at COUNTER = 0, and off at $time_on. $offset lets you stagger the time that the channel comes on and off. This lets you vary the times that channels go on and off to reduce noise effects and power supply issues from large loads all coming on at once.

$on_time := 0; $off_time := $time_on;

set_channel_full_value

    $chip->set_channel_full_value($channel, $on_time, $off_time)->get
    

Set a channel value, on and off time. Lets you control the full on and off time based on the 12 bit counter on the device.

set_channel_on

    $chip->set_channel_on($channel)->get
    

Set a channel to full on. No off time at all.

set_channel_off

    $chip->set_channel_off($channel)->get
    

Set a channel to full off. No on time at all.

set_default_mode

    $chip->set_default_mode()->get
    

Reset the default mode back to the PCA9685.

set_frequency

    $chip->set_frequency()
    

Set the prescaler to the desired frequency for PWM. Returns the real frequency due to rounding.

enable

    $chip->enable()->get

Enable the device. Must be the first thing done with the device.

AUTHOR

Ryan Voots, <simcop2387@simcop2387.info> Paul 'LeoNerd' Evans <leonerd@leonerd.org.uk>