Adafruit 16-Channel 12-bit PWM/Servo Driver

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
prp
 
Posts: 3
Joined: Fri May 10, 2013 6:38 am

Adafruit 16-Channel 12-bit PWM/Servo Driver

Post by prp »

I am using pwm to control 4 motors from a raspberry pi 2 through the Adafruit 16-Channel 12-bit PWM/Servo Driver. However the output from the servo driver is only correct when i write one byte at a time to the registers controlling the pwm on the servo driver.

If I use the following code to set the on and off times for pin 1:

unsigned char d[4] = {0x0, 0x0, L, H};
write_byte(ON_L, d[0]);
write_byte(ON_L + 1, d[1]);
write_byte(ON_L + 2, d[2]);
write_byte(ON_L + 3, d[3]);

where d is an array with four bytes of data and ON_L is the base address of the 4 sequential registers that controls pin #1, everything works fine. The write_byte function simply wraps the i2c_smbus_write_byte_data function.

If I use the following code:

unsigned char d[4] = {0x0, 0x0, L, H};
write_block(ON_L, d, 4);

things go wrong. The function write_block is a wrapper for a call to i2c_smbus_write_i2c_block_data which should simply write the 4 bytes in the array d to the 4 sequential registers at base address ON_L. However the output on my scope is all over the place.

What am I missing? Why is pwm output correct when I write the bytes one at a time, but wrong when i attempt a block write?

Any help is much appreciated.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver

Post by adafruit_support_mike »

Try scoping the SDA and SCL lines while running both sets of code.

Different output implies different input, and nothing beats direct observation.

prp
 
Posts: 3
Joined: Fri May 10, 2013 6:38 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver

Post by prp »

True enough. I have tested both sets of code with the scope attached to SDA and SCL.

Four writes of one byte each (case 1):

Image

One write of four bytes (case 2):

Image

To me this output seems correct. In case 1 the four writes are clearly seen with correct data. In case 2 there is only one write, and the same four bytes of data are present in the data part of the write. Should the servo driver not react the same way to these to operations and deliver the same pwm signal on the output pin?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver

Post by adafruit_support_mike »

The PCA9685 should accept sequential bytes, but I'm not sure about the part of the sequence here:
i2c.jpg
i2c.jpg (41.69 KiB) Viewed 312 times
You can see a series of runt pulses in the signal train where the PCA9685 ACKs each byte. The pulse in the ring looks like it might be a NAK.

prp
 
Posts: 3
Joined: Fri May 10, 2013 6:38 am

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver

Post by prp »

Thank you for your input. I still haven't been able to get it to accept a block write in order to do more effecient communication, but I have increased the i2c bus speed instead. This speeds up my control loop sufficiently for now.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adafruit 16-Channel 12-bit PWM/Servo Driver

Post by adafruit_support_mike »

I'm glad to hear you have it working. Sorry I couldn't offer more help with the bulk transfer.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”