I've got an inelegant solution to a problem, but I'd love some input from other people.
I'm trying to design (and in the near future, build) some vision research equipment. This sounds like it should be the easiest thing to do, but I need to get it to turn on and off with a 50% duty cycle square wave. The issue is I need to be able to control the frequency over a wide range (probably 1Hz to 100Hz) with a high level of precision (preferably +/- 0.01Hz, but I'd be alright with +/- 0.1Hz) without bogging down the Arduino for too long and preventing it from handling sensor input for long.
The current (probably awful) plan is as follows:
- Arduino sets the values for daisy chained SPI/I2C controlled digital pots rigged up in series.
- The digital pots change the frequency of a 555 timer astable multivibrator.
- The output from the 555 timer is fed into a JK or D type flip flop, generating a 50% duty cycle square wave at half of the 555 timer's output frequency. (Multiple flip flops can be used to further half the output frequency while maintaining the 50% duty cycle.)
- pulseIn() is periodically called to sample the output of the final flip flop (averaged) and see if the digital pots need to be adjusted to correct the frequency.
- When it's not actively sampling or adjusting the output frequency, the Arduino can handle data output, sensor input, etc.
From here, the questions I have are:
- Is there a better way to generate the initial frequency than the 555 timer that won't require continuous input from the Arduino?
- Is there a better way to adjust the frequency of a 555 timer (or other astable multivibrator).
- Am I missing anything obvious?
Thanks in advance to anyone with any suggestions.