adafruit/Adafruit-PWM-Servo-Driver-Library

Regarding sleep-mode

mrusme opened this issue · 2 comments

While porting this library onto another platform I noticed some weird things inside the code which I could not explain to myself. Hence I'm writing this issue to clarify how exactly this is intended to work and whether these might indeed be bugs.

This library defines dedicated sleep and wakeup methods. However, it looks like, during setPWMFreq a redundant implementation for putting the shield – a 1411 in my case – into sleep mode is being used.

In addition to what seems to be duplicate code, it seems like the code either does not work on Arduino the way it's intended to or there is some other magic happening that allows you to setPWMFreq and thereby put the shield to sleep but then still be able to directly setPWM without explicitly waking it up again. Frankly speaking, I don't understand how this code works on Arduino, but I've tested it myself on an Uno and a Mega2560 and both worked with the linked example.

However, while porting to a different (3.3V operated) platform the shield did not accept any requests for setting the PWM at all while in sleep mode. Only when calling wakeup (between setPWMFreq and setPWM) it would accept the frequency and rotate the servo accordingly.

Maybe someone could explain to me how this code is intended to work and why it does work on Arduino even though the shield is apparently put to sleep right at the beginning? One uneducated guess might be, that the sleep mode itself does not work for this shield while it's being connected to an Arduino, hence there is no need to actually wake it up again.

Thanks in advance!

To me it looks like a wake up is sent two lines after it is put to sleep. However, unlike in the sleep method there are no delay directly after sleep mode is set here. I suspect that the board needs some time to go to sleep before the frequency can be set and the board woken up again. If an Arduino Uno or similar an explicit delay might not be needed, but if a faster chip is used weird bugs might pop up. Try adding a delay after line 147 and see if it works better.

Did you try it and it worked? If so, the delay should probably be added here too.