FINAL MCU WIRING MODIFICATION & CODE with SLEEPSleep mode (STANDBY) drops the MCU chip temperature rise from a huge 7C in the previous implementation to just 0.2C. By keeping clocks stopped and chip cool, we eliminate possible sources of noise during normal shooting and give a bit more headroom for lower Vcc operation (eg battery operation). To make sleep mode work, the thin ORG wire (MOTION_POWER) had to be moved from pin 7 to pin 2 (Fig 1). That's because pin 7 is tied to INT4, and it turned out that INT4 on the ATmega32u4 is the only interrupt that does not have wake up detection. That threw me for a loop trying to figure why the (simple) code wouldn't work!
// USAGE: After uploading the program, it will disable the USB and you lose your COM in the IDE.
// To reload your modified code from the IDE, press UPLOAD, then wait for the progress bar
// to go beyond the half-way point, then press the MCU reset pin RST twice in rapid succession.
// To disable sleep to have continuous COM port access for debugging and determining time
// constants, comment out the sleep_mode() call at end. Once you've got your code working,
// uncomment the call.
Always wait 10 seconds after PUP for the LEDs to blink once before you //
go ->REC in CHDKPTP, otherwise you will get a LENS ERROR. If so, RST, wait 10 seconds, and
// try again.
const int IRIS_pin = 8; // [iris PI-1] right breakout top (YEL wire)
const int FOCUS_pin = 9; // [FOCUS PI-2] left breakout (BLU wire)
const int ZOOM_pin = 5; // [ZOOM PI-4] left breakout (WHT wire)
const int MOTION_POWER_pin = 2; // [iris PI-3] right breakout top (ORG wire) -- MOTION_POWER input pin -- this pin is internally tied to INTERRUPT #1
const int ENCFR_pin = 14; // [ZOOM ENCODER PIs FRONT-R] right breakout botttom (YEL wire) -- Encoder front PI
const int ENCBK_pin = 16; // [ZOOM ENCODER PIs BACK-R] right breakout botttom (BLU wire) -- Enooder back PI
const int ENC_POWER_pin = 3; // [ZOOM ENCODER PIs COMM] right breakout botttom (ORG wire) -- ENC_POWER input pin -- this pin is internally tied to INTERRUPT #0
The solution is fully specified with MECHA pinouts here:
http://chdk.setepontos.com/index.php?action=dlattach;topic=8801.0;attach=7357. Orientation of the breakouts in Fig 1 is the same as the photo. Input pins 3 and 4 are tied to GND with a 3.9K resistor. All the output pins are level-shifted as: OUT -> 1K -> 2K -> GND, with the 1K-2K node going to the camera mainboard. This implementation runs on a Chinese 4.6VDC AC adapter for this camera (-ve camera GND), but should work down to 3.7V using the Canon battery (not tested). I put a 1000uF 6V cap about 5 inches from the camera and tapped the MCU PS there. The MCU module has to be well-grounded (gray wire) to the camera case.
TIPS: The USB connector is precariously mounted held only by copper pads and can easily come off. Before use, I glued the connector using JB Weld epoxy available at auto parts shops. JB Weld is non-conductive, tolerant of mixing ratio, and makes a very strong bond after cure for 1/2 hour at +45C. Best is to get a good bond from the connector bottom to the board edge. For added safety when using the USB cable, hold the board by pinching it firmly over the connector.