Step 3What is LANC and how does the program work?
If you visit this link, it will tell you how the Sony LANC protocol works, and all the commands and camera data available on the LANC protocol:
http://www.boehmel.de/lanc.htm
As you can see, you can get a lot of information from the camera as well as controlling every function of the camera via the LANC communication port.
My code is very basic and the .asm file can be loaded into MPLAB (free from Micochip.com) and programmed using the PicKit2 quite easily.
How the code works:
If you download the source code, it is documented all the way through telling you what is happening, but I'll give a brief expanation here also.
There are 8 bytes on the LANC port every 20ms (16,6ms for NTSC). Each byte has a Start Bit followed by 8 bits, each at a length of 104uS. There is a gap of about 200uS - 400uS between bytes. After all 8 bytes have 'appeared' on the LANC line, there is a long gap (5 - 8 ms) where the LANC line is 'held' high, and then the same 8 bytes 'appear' again.
- When the program starts, it keeps checking the LANC input until it 'sees' it high for a period longer than 1000uS, this means that we are in the gap between the 8th byte and the first byte.
- Next the program waits to see the Start Bit (logic 0) on the line. When this happens the program waits for 52uS (half a bit length) and checks again to make sure there is still a logic 0 on the LANC line. If so, we know we have a valid Start Bit and are ready to read the byte.
-We now wait for 104uS (the length of 1 bit), so we will be right in the middle of the next bit on the LANC line. We read this bit, wait 104uS and read again. This continues for all 8 bits. We now have Byte 0.
-The program then waits for the next Start Bit and carries out the same task to get Byte 1, 2, 3, 4, 5, 6 and 7.
Byte 4 is the one I use in the program to get the information about the record status of the camera, but as you can see in the link I provided, there is loads of information available!
Right, that is the reading the LANC line discussed, what about writing to it to control the camera?
- When a button is pressed, 2 registers are loaded with the bytes needed to carry out the specific operation and a register called 'Sender' is loaded with the number 5 (I'll explain why later). When the program gets to the 'ready to read the bytes' part, if the register 'Sender' is not 0 it changes the RA0 pin to an output and starts outputing the first byte. Then it looks for the next Start bit and outputs the next byte. The register 'Sender' is decremented by 1 and RA0 is changed back to an input to read the last 6 bytes.
The reason the register 'Sender' is used is because for the camera to accept a command, it needs to see the command for a few cycles. Some sites say only 3 are necessary, but as 1 cycle only takes 20ms, sending it 5 times (to be on the safe side) only takes 100ms to complete.
I hope this brief Instructable makes sense and you are able to make your own DIY helmet cams. Feel free adapt my code to suit your needs, but please credit me for the code if you publish it anywhere else.
LANC source.zip2 KB| « Previous Step | Download PDFView All Steps | Next Step » |





































http://sites.google.com/site/telepicdata/