Yea, but they are in memory banks.
This is one of those moments that I would like to have here, reading
us, some of those PIC-minded persons that say that PICs are as good as
other MCUs and that they don't give any problems. At least you just
admitted you are having problems.
Step by step. Let's not get lost.
Your MCU:
Microchip PIC16F819
----------------------------
1.95 GBP (qty 1) @ Farnell
4.03 USD (qty 1) @ DigiKey
3584 bytes flash
256 bytes RAM + 1 register.
Memory is divided in banks
No analog comparator
35 instructions
No hardware multiplier
ADC: 5 x 10-bit
A cheaper and better option:
Atmel ATmega48
----------------------------
1.40 GBP (qty 1) @ Farnell
2.58 USD (qty 1) @ DigiKey
4098 bytes flash
256 bytes RAM + 32 registers.
Linear memory map
With analog comparator
131 instructions
2-cycle hardware multiplier
ADC: 8 x 10-bit
See any difference?
The analog comparator in the ATmega would save you one external
comparator. The 131 vs. 35 instructions would mean shorter code, and
the capability to do more things. Dividing 256 bytes into banks is
something from the cave times. We are in 2006!
Hot air is not currently in short supply here in Arizon

Sorry, I've
had just toooo much work experience with 'engineers' who talk a good
line, but fail at producing real, working designs.
You may have a loooong experience, but you just gave me a good example
of a real...ly suboptimal design.
Even a _32-bit_ ARM7 LPC2101 is cheaper (3.15 USD (qty 1) @ DigiKey)
than your PIC!
Also, the fact that
a 'better' scheme can be achieved using a lots more parts, more time,
and even totally different hardware is not suprising, but of little
interest to me in this application.
Ok, let's forget about checker boards and CRCs. We don't need them, to
beat your scheme.
Take your hardware. Exactly as it is. Take your wonderful PIC. Let's
assume exactly the same 8x8 sampling matrix. Change your software to
do this:
Reserve 64 bytes of RAM for a frame buffer (you still spare 192 bytes.
The code you published needs much less than 192 bytes of RAM).
At the beginning of each frame:
- Reset flag_change.
For each pixel in your matrix:
- Read the 10-bit sample from the ADC.
- Use it to compute the average value of the current frame.
- Subtract from the sample the average value of the previous frame,
for which you have the exact value from the very first pixel. This way
you don't need a second frame buffer.
- Keep the 8 most significant bits (it was your choice to work with
8-bit algebra).
- Subtract from it the corresponding value in the frame buffer,
compute the absolute value, and compare with a threshold. If smaller,
do nothing. If larger, set flag_change, and update the frame buffer
with the 8-bit value.
At the end of each frame:
- Compare the average value of the current frame with the average
value of the previous frame. If the difference is larger, in absolute
value, than a certain threshold, reset flag_change.
- Check flag_change. If true, decide that there has been some change
in your image, and switch cameras. Otherwise, do not switch cameras
(unless a timer says it is time to do it).
No checker boards. No CRCs. This scheme detects many more cases of
change than yours, yet easily avoids noise. It does not miss neither
the diagonal movements that your scheme misses, nor many other
changes. It fits in your PIC, and the conceptual complexity is lower.
Now, change the PIC for the ATmega, and you'll save money and parts
(one comparator).
Paraphrasing your text, it turns out that "a better scheme can be
achieved using less parts, less conceptual complexity, and less
money."
H.L.C.