Card corruption PROBABLY FIXED
After months of usage and countless experiments with my prototype, I got a broken card (the 1 GB Kingston, but I know of a 512MB Peak with similar issues). Before its final breathe, I noticed sporadic directory corruptions. This usually happened after writing about 500MB...2GB of data, but the card was still functional after reformatting. Then things got worse, and now I'm unable to reformat or use it anymore.
To date, the cause of this problem is not clear.
Initially I tought of a bug in the code, so I checked stack sizes, removed unnecessary interrupt code, and placed error traps on the AVR-DOS calls. The traps intercepted an error 23 and "file not found" errors, so I inspected the card with the FS-Interpreter tool. What I found was an apparently-good subdirectory, except it missed the links to the parent directory. This drives the file deletion system crazy.
Thinking of a bug in the AVR-DOS library, I contacted its Author, Franz Joseph Voegel, and he was so kind to try a debug version of the code on his system (using both compactflash and hard disk drives). The code worked for days of continuous recording, writing many GB of flawless data.
Joseph suggested that this could be a card wearout problem, as the AVR continually rewrites the FAT (file allocation table) and the directories as it is writing a new file. If the number of writes of a logic sector is limited, then the sectors assigned to the FAT and DIR could exceed the maximum numbers of rewrites quite rapidly. However, creating a flash file system almost invaribly requires you to separate logic sectors from phisical sectors (the ones that actually wear out), so I'm not incline to think SD-card designers overlooked the problem.
I'm investigating (2007) how wear levelling is performed on SD-card, but got very little information about this. Apparently, Kingston's card DO some form of wear levelling (see here), but they don't give much detail so wearout could or could not be an issue.
Most maufacturers don't even mention wearout or endurance information. With a SanDisk card (untested yet) this document I expect the Witnesscam to perform more or less like in the example 2 (lifetime = 317 years!). STEC industrial cards take wear leveling seriously, and give an application note with a lifetime calculator.
Readers knowledgeable about this topics, please shed more light on the subject! I would also like to know how the brand you are using is performing.
This is an open issue so please don't be shy and share your thoughts and insight, thanks!
UPDATE (2008): After switching to a SanDisk card, the system is working fine until now. So I'm more than inclined toward a wearout diagnosis.
UPDATE (2009): Year after year, the SanDisk card still works perfectly. Wearout definitely is a main factor, so I think I'll stick to SanDisk brand for my flash memory needs.
Probable Fix: Use only card with wear-levelling from known manufacturers. SanDisk worked well in my case.
Workarounds: Use continuos recording only for very short periods. When use PIR triggered modes, place the camera in a way that record is started only every now and then. Replace cards periodically (eg. every year or two).
Improvement tip: Add an input to enable recording only when the burglar alarm is engaged. This way recording starts only when nobody is at home.
Starting images badly over/under exposed
I have noticed that if no images are taken for some time (minutes), the camera enters automatically sleep mode. The initialization sequence wakes it up, but the very first frame can be uncorrectly exposed, often almost black or almost white. Pictures immediately following are OK. Chances are that the camera needs at least one frame to set correctly the exposure level immediately after a wake-up from sleep mode.
Workarounds: Tom Westhoff suggested the camera sending the "keep alive" instruction. He also suggests to count the number of the SYNC commands it takes to wake up the camera; if more than three, then the camera was sleeping so it's better to wait a while before taking the first picture.
Improvement tip: I also noticed (but did'n try it) that the snapshot command allows to specify how many pictures to take before getting the actual one. Maybe this was provided to allow some time to the camera to adjust the exposure properly?
Battery leakage through ADC monitoring circuitry FIXED
The resistor divider that adapts the battery voltage for ADC measurement wastes enough power to trigger the low-battery alarm in a few weeks..
Fix: change R3 to 2.7 megaohm, and R4 to 560 kiloohm (thanks to Nikolai Orlov for his advice).
Can I have the kit or the PCB?
Currently I'm collecting requests for PCB and/or kits. Should I get 50 or more requests I will prepare a run of PCBs from a professional manufacturer. So if you are interested drop me a line and I will notify you when the circuits are ready.
Actually, before going this step I need also a better PCB layout (the original layout was focused on single-sided boards and needs too many corrections), so if someone is designing a new PCB (or even have PCBs for sale) please let me know.
Once I got the PCBs I can start working on a kit, so please be patient.
Reader Marijan Vajdic designed a new PCB and prototype using through-hole parts (no-SMD), and offers to sell ready-made PCB boards. You can write him to email@example.com
Where to buy the camera?
I've got mine here: http://www.intertec-components.de
If you get lost in the site, here is direct link to the page with the camera specifications and their price list (36.90 EUR at 22 May 2007)
Singapore: SG-BOTIC, search for C328 VGA Camera Module With JPEG Compression [C328-7640S] (57 USD/ 22 May 2007)
France: LEXTRONIC (france) search for cjpg380 (47 EUR ttc / 22 May 2007)
South Africa: ELPRO
USA: ELECTRONICS 123 , search for JPEG cameras,
the exact model is out of stock butapparently similar parts with different lens are offered at about 47 USD/ 22 May 2007.
Also in the USA Sparkfun used to have it, but on a recent visit to their web site I was unable to locate it so maybe it's not available anymore.
If you know of any other place were to buy the camera please let me know.
Where to buy the remote control?
As I'm writing this (22 May 2007) the remote control model ROC3205, manufactured by Thomson, is available on most italian TV and electronics goods resellers for 9,90 EUR including taxes. I guess it should be available at similar prices from most of the big paneuropean names Media-Markt, Expert, Trony, Saturn etc.
Technically, any universal remote capable of producing RC5 codes is suitable (provided you can recompile the source code to adapt to the specific codes matching the remote control keyboard). This means that you can adapt the circuit for every universal remote, as I don't know of any universal remote that is not capable to send RC5 codes.
My remote control requires 4-digit codes!
Newer ROC3025 remote controls come with an improved firmware. Apparently they switched from 3-digit setup codes to 4-digit codes. In practice all the setup codes listed in the "old" user manual still work, provided you add a "0" before them. So the 4-digit device code to enter in order to setup the remote for Philips RC5 encoding is 0 1 5 5.
Where to buy the PIR module?
I've got mine here, but any similar module will do. For instance, I have also tried a similar sensor (paid about 8 EUR/22 May 2007 - from Artek) from the Parallax assortment with excellent results.
Can I use a USB webcam with a USB/RS232 cable instead?
A converter cable won't work. In fact, if you look closely to converter cables you will notice that they end with a male plug - the same as the camera - as they are designed to work with an USB host (that is, a PC). This is out of the reach of a small 8-bit controller, not to mention the need for a driver software appropriate for the camera in use.