In this column, Kristen answers questions about all aspects of electronics, including
computer hardware, software, circuits, electronic theory, troubleshooting, and anything
else of interest to the hobbyist. Feel free to participate with your questions, comments, or
suggestions. Send all questions and comments to: Q&A@nutsvolts.com.
; WITH KRISTEN A. McINTYRE
PIC Sounds for a Camera
QI have an outdoor IP camera that works fantastic except for one issue. It has an RCA audio input for two-way communication and for detecting sounds to trigger the camera to write video
to the SD card. I don’t use the communication. I would
like to use the trigger mechanism, but I have so much
background noise in my neighborhood that I get too many
I need a circuit to generate an RCA compatible tone,
so I can trigger the camera based on a PIC connected to a
PIR sensor. I have both ends of the circuit; I just need the
active low 5V output from a PIC to trigger an audio tone
output to the camera’s input.
AI can think of two approaches to solve this problem. Both use the same general idea, but one relies on the PIC to create the signal, while the other uses an oscillator that is outboard.
Each has its advantages and disadvantages.
Starting with using the PIC to create the signal, we’d
have to write some code. The function of this code would
be to make a square wave with one of the PIO pins on the
PIC. The idea behind the code is very simple, though the
implementation might not be.
In a loop, you’d set the chosen PIO pin output high,
delay the appropriate amount, and then set it low and
delay the same again. This could be maintained for as long
as the tone would be desired.
The length of the delay would be half of the period
of the desired frequency. Let’s assume 400 Hz, just as an
initial cut. That’s a pretty common frequency that’s
present in an environment, and should trigger your
camera. The period for 400 Hz is 1/400, or 2. 5 ms.
A square wave would be half of that period in each
state high or low. That means 1.25 ms is the desired
delay in the loop.
There also needs to be a way to break out of the
loop, so some external variable needs to be checked
so that you can exit.
Let’s assume you have that code written. With a
400 Hz square wave, we probably want to do at least
a little filtering and level reduction. I’m going to propose
that we do it with a very simple one pole low-pass filter.
We’ll precede that with a voltage divider to bring the level
down somewhat closer to a typical 1V P-to-P audio signal.
We’ll AC couple the output for good measure; particularly
since a low-pass filter will pass DC levels through, with DC
being below the cutoff frequency.
While the low-pass filter may not be strictly necessary,
it seems a safe approach for the cost of a few more
components. All of the high frequency energy from a
fast-rising square wave might cause undue coupling of this
energy up to the 100 kHz region into the camera circuitry
with unknown consequences. An example circuit using no
gain elements is shown in Figure 1.
The upside of this approach is hardware simplicity.
The downside is that code must be written that is both
timing sensitive, requires a breakout mechanism, and will
completely occupy the processor while the tone is being
generated unless timer interrupts are used. Using interrupts
significantly complicates the code.
An approach that is much easier in software but
requiring more hardware is to build an oscillator in
hardware, and enable or disable it with a single control
• PIC Sounds for a Camera
• Going the Distance with I2C
• Analog Flickering
Q & A
; FIGURE 1. Low-pass filter for PIC PWM output.
12 January 2018