Serial communication using blue LED and USB power (A620) - General Discussion and Assistance - CHDK Forum

Serial communication using blue LED and USB power (A620)

  • 8 Replies
  • 4076 Views
Serial communication using blue LED and USB power (A620)
« on: 30 / May / 2009, 20:33:31 »
Advertisements
Hi all,
This is very preliminary, but I have inelegant but reliable communication working between a (Windows XP) PC and an A620, using the USB power line to receive data from the PC and the blue led to transmit. I have hooked this up to the Lua interpreter in the camera and so far can execute lua functions which don't call lua_yield(). My longer term aim is to achieve inter-camera communication for the purpose of synchronizing settings between 2 cameras for stereo photography.

The serial I/O uses the kbd_process task at 10ms intervals, so the max rate is one transaction of 7 bits down and 7 bits up per 10ms. Each transaction actually sends and receives 14 bits since there are 7 bits of error detection and house-keeping info as well as the 7 bit payload. Each transaction takes about 2 ms total for the combined up and down transfer and uses a non-standard serial protocol suited to software polling and wait loops. When the camera is in camera mode, about 10% of the low level transactions fail due to an interrupt that appears to take as long as 1.5ms. However, a simple error handling protocol solves that issue, and communication seems reliable even when zooming and shooting. In Play mode even the low-level protocol is quite reliable.

A rudimentary command line program on the PC sends and receives characters by wiggling the COM port DTR line and reading the DSR line.

For hardware I use a photodiode from an old mouse driving a transistor, powered from the PC's COM port.

One problem which I don't understand is that the communication fails if the camera is in camera mode and the LCD display is off (or shut). It works fine in Play mode with the LCD shut. I suspect that the power to the blue led is reduced in some way when the LCD if off in camera mode.

If other people are interested in this, my code would need some tidying up. I am not totally clear about the proper organization of the CHDK source. Currently, most of my code is in chdk\platform\generic\kbd.c, because I used the platform specific (get_mmio() & USB_MASK) style code heavily. This could be moved into core if I added a fast function to get the USB state. The lua interpreter is in chdk\core\kbd.c. I build CHDK on Windows using Cygwin and binutils-2.18. By the way, I am a Windows programmer and don't know that much about gcc etc.

As usual, I have very little time to work on this. However, any advice or suggestions are welcome.

Regards,
Kit

Re: Serial communication using blue LED and USB power (A620)
« Reply #1 on: 31 / May / 2009, 05:40:07 »
I know someone else who is working on this so I will send him a link to this post.
I also have a pair of A620's so could possibly test this.

Not sure if get_mmio() returns valid values with all cameras.

Edit:

Is it possible to implement this without the overhead of Lua ?


David
« Last Edit: 31 / May / 2009, 05:43:24 by Microfunguy »

Re: Serial communication using blue LED and USB power (A620)
« Reply #2 on: 31 / May / 2009, 08:27:23 »
Just another comment ....

It is not possible to set many of the Canon menu features (even though you can read their status) so the two cameras may still not be setup the same.

With 10msec polling, how do you guarantee the slave receives the message ?

The comment about the interrupt is interesting, it could explain why there is the occasional 'poor' synch.


Re: Serial communication using blue LED and USB power (A620)
« Reply #3 on: 31 / May / 2009, 18:10:09 »

Is it possible to implement this without the overhead of Lua ?

Yes, I just used Lua because I wanted something vaguely intelligent to talk to in the camera. I was not intending to involve lua in the inter-camera synchronization.

Just another comment ....

It is not possible to set many of the Canon menu features (even though you can read their status) so the two cameras may still not be setup the same.

With 10msec polling, how do you guarantee the slave receives the message ?


I was intending to have the slave camera in manual mode and set the zoom, focus,aperture and speed in the first instance. Does that seem possible?

The 10ms polling is an issue. I had been hoping that _SleepTask() would let me adjust the timing of the polling to ms resolution so I could phase lock the kdb task of one camera to the other. However, measurements made since my initial post indicate _SleepTask() only supports a resolution of 10ms. Does anybody know a way to shift the timing of _SleepTask() by smaller amounts?

I did discover that code in core_spytask() periodically gets called 3ms and 6ms through the 10ms _SleepTask() period. This is probably due to gui_redraw() taking significant time - I will check that. This might make it possible to achieve polling overlap between cameras with < 5ms of polling. If polling of  the order of 5 ms is needed, I would not do it every 10ms, but at a lower rate, with the cameras locked with 10ms resolution, to reduce power consumption.

Thanks,
Kit


Re: Serial communication using blue LED and USB power (A620)
« Reply #4 on: 31 / May / 2009, 19:02:05 »
I was intending to have the slave camera in manual mode and set the zoom, focus,aperture and speed in the first instance. Does that seem possible?

For the A620, the camera has to be in manual focusing mode in order to set focus.

You can set manual focusing mode by software pressing the Down key.

Other cameras wiill be different but I guess your main interest for now is the A620.


David

Re: Serial communication using blue LED and USB power (A620)
« Reply #5 on: 31 / May / 2009, 21:57:47 »
I'm interested in hearing how this works out.  If you get results, please consider posting more information about it here.  Thanks!
Was: SD1100 IS, Autobuild, V1.01a, dunked in ocean
Next: SD990 IS, Autobuild, used to build sand castles with
Waiting to die: SX230

Re: Serial communication using blue LED and USB power (A620)
« Reply #6 on: 01 / June / 2009, 03:39:41 »
Hello...

I'm very interested in that communication.
Thus I have pair of A590.

But as I know the timer is updated in 1 ms interval. So there is thread that executes in 1ms interval.
10ms is just too long lattency (and sometime just more than 10ms due to interrupt).
Other option is to do more bits per cycle (eg use 10 to 30 ms pilot bit) and after that whole bunch of data at very fast rate.
On recceiving camera just to pool if start bit is detected and if then hold in routine (block other camera function) to receive all data.


Re: Serial communication using blue LED and USB power (A620)
« Reply #7 on: 01 / June / 2009, 03:51:43 »

But as I know the timer is updated in 1 ms interval. So there is thread that executes in 1ms interval.


I am very interested if you know of a thread running at 1 ms intervals. While the timer related functions take times in ms, and get_tick_count() returns time in ms, as far as I can tell, all the threads run at 10ms intervals minimum, and get_tick_count() increments in 10ms steps. Can you give me any information about threads running at a higher resolution than 10ms?

Thanks,
Kit


Re: Serial communication using blue LED and USB power (A620)
« Reply #8 on: 01 / June / 2009, 03:54:35 »
I'm interested in hearing how this works out.  If you get results, please consider posting more information about it here.  Thanks!

I will certainly provide information and code when I have it fit for public use. The inter-camera communication is turning out to be more challenging than I had hoped.

Cheers,
Kit

 

Related Topics