Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By Barnabybear
#56167 Hi, sorry to be lazy - a cut and paste of one of my posts on another site - take a copy of the photo as when my dropbox gets full I have to remove stuff.
As the PCA9685 is a free running PWM IC, it has its own internal clock and is not synchronised to the mains, this means you would need to check back on it every so often to ensure it hadn’t drifted too far from the mains and rewrite the start time if needed. I haven’t tested this yet but it should do the trick, it replaces one of the outputs, not ideal but it leaves 15 available. In theory it should take 2.5 seconds for the drift to change the overall output by one value i.e. 127 -> 128 not a problem unless its 0 -> 255 or 255 -> 0, so it might be prudent to leave a little space at each end when coding the ESP. In general if you’re going to use this with most of the common sequencers it’s going to be updated anything between 10 & 40 times a second so the drift will be calculated and corrected way before it has any affect.
Image
The idea is that one of the channels that the ESP controls, sets the output to 50% on and 50% off. With this circuit it can check how this output is performing, and as all outputs would have the same error, once detected all can be corrected.


Select the closest PWM frequency to your mains (PRE_SCALE = 119 (50Hz) or 99 (60Hz). 7.3.5 - page 25 of the data sheet) and then when you have the feedback from the above (the on / off time is no longer 50/50) keep adjusting the LEDn_ON and LEDn_OFF (Fig 7 - page 17 of the data sheet) to follow the zero cross point. You'll have to use Triacs as it's nearly imopssable to find non-zero crossing SSRs at a good price.