I'm attempting to make a cough detector. This requires to record data from a piezo transducer at a high sample rate (10kHz) and save it to an SD card, awhile simultaneously outputting a square wave (50% duty cycle) in order to set the cut off frequency of a hardware low pass filter.
I have managed to do each of these tasks independently; with the data acquisition using Timer 1 and the output square wave using Timer 2.
I now need to combine both these bits of code, i think i need to apply more interrupts in order to be able to use Timer 2 simultaneously. Has anyone had any experience doing anything similar?
Is it necessary that the output be software automated? That is to say, do you need to vary it? If not, I would just separate it and hardware automate it with a 555. Super simple and reliable. I guess I'm asking why you need to combine them. Help me understand.
Square waves can be output using the tone() function very easily. Set the tone on a pin and it will continue until stopped by notone().
Then a sampling rate of 10 kHz is slightly more than the standard rate for a freerunning ADC (let it convert and every time a new conversion is ready, taking just over 100 µs, an interrupt is triggered and you can write the data to your SD card - assuming that interface is fast enough to follow).
I was reading through the data sheet of the filter and saw this:
'When using these devices for anti-aliasing or DAC postfiltering, synchronize the DAC (or ADC) and the filter clocks. If the clocks are not synchronized, beat frequencies will alias into the desired passband.'
So i thought i could output the clock required for the filter from the arduino.
If i use a 555 how do i synchronise the arduino ADC and the filter?
Ross2511:
I have managed to do each of these tasks independently; with the data acquisition using Timer 1 and the output square wave using Timer 2.
I now need to combine both these bits of code, i think i need to apply more interrupts in order to be able to use Timer 2 simultaneously. Has anyone had any experience doing anything similar?
Since the square wave is whole generated in hardware with timer2, there is nothing difficult, just set up
timer2 and you'll get your squarewave out whatever else is happening on the microcontroller, so long
as nothing else touchs timer2's settings of course.