Here's the gist of my little project.
I have a box (the function of which isn't really important for this discussion) which runs off 12V. The box has a power switch, a LED which may be on, off, or flashing (as controlled by the box). I want to use a PIC micro to detect the state of this LED.
Sound simple enough? Well, the LED is wired as shown in the attached diagram. As far as I can tell, the LED anode is wired directly to the +12V side of the switch, and the cathode goes to one of the connector pins on the box. Using my great power of ASSumption, I can surmise that the box switches the LED on/off via a transistor which grounds the cathode of the LED through a current limiting resistor.
I hooked my scope up to the point that I marked on the diagram (between the LED cathode and ground), to see what I would get. I saw about 5.5V with the LED on, and 10V with the LED off. This is a bit off from what I expected (something closer to 10 and 12V, based on a typical 2V drop from a LED).
Anyway, if I want to use a PIC to detect whether the box has the LED on or not, what do you think the best way is?
These are the options I thought of:
Option 1: Use a voltage divider to bring the maximum voltage down to 5V, and feed to one of the PIC inputs. Advantage: Easy to do. Disadvantage: the LED ON voltage may be too high (probably around 2.5V if I divide the voltage by 2) to trip the input low.
Option 2: Use a comparator. The PIC I'm using (PIC16F526) has two comparators on board, along with a programmable voltage reference. I could use that to detect whether the LED voltage is above or below a certain threshold (which I would divide down to meet the PIC's 5-volt maximum). Advantage: Almost as easy to do. Disadvantage: What if the next guy's control box drives the LED in a different way, or the voltages vary due to supply/load variation?
Option 3: Use the PIC's A/D converter. Then I can take measurements and detect a change in the LED's state when the A/D returns a significantly higher or lower value than the last check.
Option 4: Some other blatantly simple and obvious way that I'm totally overlooking, that's where you guys come in.![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
I have a box (the function of which isn't really important for this discussion) which runs off 12V. The box has a power switch, a LED which may be on, off, or flashing (as controlled by the box). I want to use a PIC micro to detect the state of this LED.
Sound simple enough? Well, the LED is wired as shown in the attached diagram. As far as I can tell, the LED anode is wired directly to the +12V side of the switch, and the cathode goes to one of the connector pins on the box. Using my great power of ASSumption, I can surmise that the box switches the LED on/off via a transistor which grounds the cathode of the LED through a current limiting resistor.
I hooked my scope up to the point that I marked on the diagram (between the LED cathode and ground), to see what I would get. I saw about 5.5V with the LED on, and 10V with the LED off. This is a bit off from what I expected (something closer to 10 and 12V, based on a typical 2V drop from a LED).
Anyway, if I want to use a PIC to detect whether the box has the LED on or not, what do you think the best way is?
These are the options I thought of:
Option 1: Use a voltage divider to bring the maximum voltage down to 5V, and feed to one of the PIC inputs. Advantage: Easy to do. Disadvantage: the LED ON voltage may be too high (probably around 2.5V if I divide the voltage by 2) to trip the input low.
Option 2: Use a comparator. The PIC I'm using (PIC16F526) has two comparators on board, along with a programmable voltage reference. I could use that to detect whether the LED voltage is above or below a certain threshold (which I would divide down to meet the PIC's 5-volt maximum). Advantage: Almost as easy to do. Disadvantage: What if the next guy's control box drives the LED in a different way, or the voltages vary due to supply/load variation?
Option 3: Use the PIC's A/D converter. Then I can take measurements and detect a change in the LED's state when the A/D returns a significantly higher or lower value than the last check.
Option 4: Some other blatantly simple and obvious way that I'm totally overlooking, that's where you guys come in.