0

Fatal error with PCA9865 PWM Shield
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Fatal error with PCA9865 PWM Shield

by gumfoo on Mon Aug 19, 2019 1:21 pm

Hello, I have encountered an issue with the PCA9865 shield. When using the latest version of the library 1.0.4 the arduino (nano 328p) seems to crash (gets stuck or reboots to setup() ) just as the pwm.begin() is called. I went back to library version 1.0.2 and this problem does not occur. I suspect the change in begin(), currently takes a prescale could be the culprit <somehow> (may be the memory location is not cleared). All the basic examples provided with the library showed the same error behaviour. I have set the address of the shield in use to 0x54 (0x40+0x14), may be this could also be affecting the outcome but I do not see how.

I hope this is enough information :)
Thanks!

Version 1.0.4
Code: Select all | TOGGLE FULL SIZE
void Adafruit_PWMServoDriver::begin(uint8_t prescale) {
  _i2c->begin();
  reset();
  if (prescale) {
    setExtClk(prescale);
  } else {
    // set a default frequency
    setPWMFreq(1000);
  }
}


Version 1.0.2
Code: Select all | TOGGLE FULL SIZE
void Adafruit_PWMServoDriver::begin(uint8_t prescale) {
  _i2c->begin();
  reset();
  // set a default frequency
  setPWMFreq(1000);
}


Code: Select all | TOGGLE FULL SIZE
/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  PWM test - this will drive 16 PWMs in a 'wave'

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/815

  These drivers use I2C to communicate, 2 pins are required to 
  interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x54);
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40);

void setup() {
  Serial.begin(9600);
  Serial.println("16 channel PWM test!");

  pwm.begin();
  pwm.setPWMFreq(1600);  // This is the maximum PWM frequency

  // if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
  // some i2c devices dont like this so much so if you're sharing the bus, watch
  // out for this!
  Wire.setClock(400000);
}

void loop() {
  // Drive each PWM in a 'wave'
  for (uint16_t i=0; i<4096; i += 8) {
    for (uint8_t pwmnum=0; pwmnum < 16; pwmnum++) {
      pwm.setPWM(pwmnum, 0, (i + (4096/16)*pwmnum) % 4096 );
    }
#ifdef ESP8266
    yield();  // take a breather, required for ESP8266
#endif
  }
}

gumfoo
 
Posts: 6
Joined: Mon Aug 19, 2019 11:37 am

Re: Fatal error with PCA9865 PWM Shield

by adafruit_support_bill on Mon Aug 19, 2019 1:37 pm

I suspect the change in begin(), currently takes a prescale could be the culprit

Prescale defaults to zero in the header file, so that should not cause a problem:
Code: Select all | TOGGLE FULL SIZE
  void begin(uint8_t prescale = 0);


I have set the address of the shield in use to 0x54 (0x40+0x14), may be this could also be affecting the outcome but I do not see how.

Do things work with the older version of the library and the modified (0x54) address?

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Fatal error with PCA9865 PWM Shield

by gumfoo on Mon Aug 19, 2019 2:15 pm

Yes, it works on v.1.0.2 with my given address

gumfoo
 
Posts: 6
Joined: Mon Aug 19, 2019 11:37 am

Re: Fatal error with PCA9865 PWM Shield

by adafruit_support_bill on Mon Aug 19, 2019 2:33 pm

The other change to the library was reversing the order of arguments to the constructor:

Now the address should be first:
Code: Select all | TOGGLE FULL SIZE
Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(uint8_t addr, TwoWire *i2c)


https://github.com/adafruit/Adafruit-PW ... 49c50a924d

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Fatal error with PCA9865 PWM Shield

by gumfoo on Mon Aug 19, 2019 2:38 pm

In my tests with the example sketch I only passed the device address as it was shown in the same comments of the sketch

gumfoo
 
Posts: 6
Joined: Mon Aug 19, 2019 11:37 am

Re: Fatal error with PCA9865 PWM Shield

by adafruit_support_bill on Mon Aug 19, 2019 3:01 pm

When using the latest version of the library 1.0.4 the arduino (nano 328p) seems to crash (gets stuck or reboots to setup() ) just as the pwm.begin() is called. I went back to library version 1.0.2 and this problem does not occur.


Looks like quite a few commits since V1.02. Have you tried it with 1.03? That might help narrow things down.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Fatal error with PCA9865 PWM Shield

by gumfoo on Tue Aug 20, 2019 9:44 am

Yes, I have tried same set up with only change, the library version to v1.03 and it shows same erroneous behaviour as v1.04 :(

gumfoo
 
Posts: 6
Joined: Mon Aug 19, 2019 11:37 am

Re: Fatal error with PCA9865 PWM Shield

by adafruit_support_bill on Tue Aug 20, 2019 9:58 am

OK. That narrows the search to changes made between 1.02 and 1.03. I'll take a look and see if we can identify the cause of the problem.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.