View previous topic :: View next topic |
Author |
Message |
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
Pin as ADC in and digital out |
Posted: Thu Sep 27, 2012 12:36 pm |
|
|
I have one A port pin currently driving a MOSFET to control an LCD's backlight. I need to read an analogue voltage but have no other spare port A input.
As the MOSFET gate impedance is high, it shouldn't shunt the sensor's input. Can I therefore just change the pin from digital output to ADC in, read the value and then put it back to digital output again?
PIC is an 18LF2550.
Thanks for the help. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Sep 27, 2012 1:11 pm |
|
|
I see no problem as far as the PIC is concerned.
How will the MOSFET drive to the LCD behave as the MOSFET gate drive is taken through the range of sensor output voltage?
How will your voltage sensor react to being digitally driven?
Mike |
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
|
Posted: Thu Sep 27, 2012 1:41 pm |
|
|
Hi, Thanks for the reply. The sensor is an MPX4115 pressure sensor, buffered by an opamp, so I can put a diode from the opamp output to the pic pin, so no problem there. The LCD backlight will be turned on and this is the problem I hadn't considered!! There doesn't seem to be any way around that!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Sep 28, 2012 2:16 am |
|
|
One thing you could do, though 'complex'. is have the PIC pin connect to the MOSFET via a comparator. Set this so it's output will go 'on' at (say) 2.5v, and then your analog source can drive the pin up to this voltage, without turning the FET on.
Other thing you have to consider is the effect of the diode drop on accuracy.
Best Wishes |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Sep 28, 2012 2:20 am |
|
|
Quote: | The sensor is an MPX4115 pressure sensor, buffered by an opamp, so I can put a diode from the opamp output to the pic pin, so no problem there. The LCD backlight will be turned on and this is the problem I hadn't considered!! There doesn't seem to be any way around that!! | Isolating the OPA with a diode only works one way. The PIC digital O/P sources and sinks current depending on its state. You could just use a resistor, (avoids the diode drop problem).
You don't tell us how you're driving the FET, so can't help without more information. Assuming that it's simple ON/OFF, you may be able to use an RC filter. Make the time constant long enough for the A2D to get its sample, but short enough for the FET to respond without observable glitch, or being killed as it passes through its linear region.
Mike
EDIT Ttelmah replied whilst I was typing (thinking). |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Sep 28, 2012 3:12 am |
|
|
and our answers complemented each other well, with 'alternative solutions'.
Best Wishes |
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
|
Posted: Sat Sep 29, 2012 9:45 am |
|
|
The mosfet is simply driven via a potential divider. The idea of a time constant sounds clever - wouldn't have thought of that!
Brian |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Sep 29, 2012 1:22 pm |
|
|
One thing you will have to watch.
When doing an ADC, the OPA output is attenuated by the attached resistor network. The signal amplitude is dependent on the voltage at the FET gate. You will need to either, adjust the resistor ratio to make their effect negligible, or correct for it.
Mike |
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
|
Posted: Sat Sep 29, 2012 10:54 pm |
|
|
Thanks for that. The other possibility is to remove the mosfet from the port and drive it from a monostable triggered by one of the 3 pushbuttons which would leave the ADC input as sole user. Means an additional chip though.
I'll have to play with both ideas.
Thanks again
Brian |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sun Sep 30, 2012 1:38 am |
|
|
One thought does occur.
You have been talking about just this one pin, but if you are controlling an LCD, then you have a minimum of four other pins available you can use.
The four data lines to the LCD, are ignored by the LCD, when it is not enabled. All you need is something like a bilateral switch, operated off the enable line, so the connection is made to the other circuitry, when the LCD is not being talked to.
Just a thought.
Best Wishes |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Sep 30, 2012 2:57 am |
|
|
On the LCD theme.
Could you free up the R/W line? (Then you won't need extra hardware)
Mike |
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
|
Posted: Sun Sep 30, 2012 12:45 pm |
|
|
no, the R/W pin on the LCD is already grounded, so that's a non-starter! Why is it that Murphy always conspires to make sure that you are one line short?
I could try one of the LCD lines but the monostable would be no more complex. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sun Sep 30, 2012 1:45 pm |
|
|
With a resistive drive, you can do it directly to one of the LCD data lines with no other circuitry at all. If you are not using R/W, the PIC is the only thing that can drive these lines, and will only do so, when you send data to the LCD.
So long as you choose a drive value, that is low enough to meet the ADC input requirements, but high enough that the PIC pin can still drive the line to the logic levels needed by the LCD (probably perhaps 2KR), then provided an ADC is available on on of the LCD data lines, all you'd need do is stop using the LCD for a moment, use 'output_float' on this line, wait for Tacq, read the voltage, then drive the line again.
Best Wishes |
|
|
|