James Newton, webhost wrote: > A circuit with two inputs and one output. > > All I/O optical in the human visible light range. > > All I/O in pulses of light of a width and frequency range discernable > by the human eye. (0 to 20 Hz) > > The output frequency varies over the range in inverse proportion to > the mathematical product of the input frequencies with an acceptable > error of 10 percent. > > Optimize the design for low cost of production by assembly workers > who have little technical ability. Now I think we've got something to work with. By the way, this is very different from anything you said before. This is the first time we are learning that the output frequency should be the *product* of the two input frequencies. So to write your spec more formally: Fmax = maximum input and output frequency (20Hz) F1 = input frequency 1 F2 = input frequency 2 Fo = output frequency F1 * F2 Fo = ------- Fmax However, inside a microcontroller it is much easier to deal with period instead of frequency. Let's rewrite this in terms of periods: 1 1 -- * -- 1 P1 P2 -- = ------- Po 1 ---- Pmin This reduces to: Po = P1 * p2 * Fmax which isn't hard to do at all in a 12F629 but rather difficult in analog. Use interrupt on change to detect the two input signals and maintain the internal official input period values. Use a timer interrupt to generate the output pulse based on the current output period. Have the foreground loop constantly run around doing a little filtering on each input period, then computing the resulting output period. It gets around to it when it gets around to it, but should still be instantaneous in human terms. One wrinkle to deal with is infinite periods. The output timer won't be able to do infinite periods, and you don't want to spend a lot of bits on really large period values either. You will have to decide at what point to make a special case where an input period is considered infinite and just shut off the output driver. In other words, your spec says 0 to 20Hz, but that will be unattainable. If a human is looking at the output, then 1/4 Hz is probably about as slow as you want to go. That would mean your spec should be .25Hz to 20Hz, with the output not flashing at all if either input is below .25Hz. The logic doesn't sound like a hard problem for a 12F629 running on its internal 4MHz oscillator. 10% accuracy shouldn't be a problem either since the 12F629 oscillator is accurate to around 5% if I remember right. This is the kind of job I would figure I can do in a day including the testing, which means I'd fix price it to a customer based on two days time. You still have to do some analog, however. The input detector needs to adjust its threshold value according to ambient conditions. You also need some hysteresis in the detector for two reasons. First, that guarantees a reasonable digital signal out suitable for a PIC digital input. Second the size of the hysterisis band essentially adjusts the sensitivity of your receiver. Light levels are always fluctuating somewhat, and there will of course be noise in the system. Without a minimum signal threshold the detector will always be seeing something. You probably want to low pass filter the light level input a little, then adjust the hysterisis threshold so that it doesn't react to the normal flicker of flourescent lights or a nearby CRT monitor. You may even want to make the sensitivity level adjustable. While all this may sound complicated, it isn't. The light level signal goes into the + input of an opamp, and a low pass filtered version of it into the - input (that's where the auto ambient level comes from). A little positive feedback adds the hysterisis. Use a 5V capable "single supply" dual opamp and have the output drive the PIC pin directly. ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu