I’m using the qtr-rc sensor with a pic micro so I have to write my own code. I just need some clarification from the application note.
the procedure is listed as
- Set the I/O line to an output and drive it high
- Allow at least 10 us for the 10 nF capacitor to charge
- Make the I/O line an input (high impedance)
- Measure the time for the capacitor to discharge by waiting for the
I/O line to go low
In 1. is this referring to the vin on the sensor from a pin on the micro? I have seen in another post that this can be tied to the 5v. Which is how I wish to connect it. So step 1 becomes redundant does it?
And could you explain how the capacitor discharges in the circuit. Is it triggered by setting the io pin connected to out on the sensor to high Z input?
The QTR-RC sensors use a single I/O line connected to out to charge the capacitor then monitor it as it discharges. Vin can be at 5V. Step 1 is about setting that I/O line to an output and driving it high, so it is not redundant, and step 3 is about setting to an input, so the answer to your second question is yes.
Thanks Paul for your quick reply.
That is easy enough to implement but I was a little puzzled at how this would work by the circuit.
I wouldn’t mind understanding how the circuit works as I’m sure it would help at some later point.
Okay, did you look over circuit for the sensor? I do not really know what more to say than this: you charge up the capacitor with current from your I/O line, then (with the I/O line acting as an high-Z input) the charge flows through the phototransistor to ground. The more light there is, the faster the capacitor can discharge.
Does the cap charge in 2 directions?
I thought it would charge through vin to ground. And then I guess that allows a high on io to charge it the other way and then discharge finally when the io is taken to high z input. Sorry for my ignorance. Is this the way it works?
I guess I should say that technically you are discharging the capacitor by presenting the high output, than letting it charge up across the potentiometer. But that really does not matter - a capacitor to ground acts almost exactly the same as a capacitor to Vin from the point of view of your microcontroller, since all it knows is the voltage on the out pin. (The only differences are the voltage you will get when initially powering up and potential for breaking if too much voltage is applied.) Sorry if that confused you! Does it make more sense now?
I’m still lost with the circuit workings but at least I can get it working now I confirmed the 4 steps are the same whether you supply constant 5v to vin or it is supplied on demand from a second io pin.
That is all that is important for now. Maybe as I play with the electronics a bit more it will come to me.
Thanks for your help.
If it is still not making sense to you, and can not ask a specific question, you probably just need to go review (?) some basic electronics: Kirchhoff’s laws, V=IR, Q=CV and so on. Anyway, good luck getting it to work!