CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Pin as ADC in and digital out

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
BLL



Joined: 11 Nov 2006
Posts: 181
Location: Birmingham, UK

View user's profile Send private message

Pin as ADC in and digital out
PostPosted: Thu Sep 27, 2012 12:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 27, 2012 1:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 27, 2012 1:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 28, 2012 2:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 28, 2012 2:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 28, 2012 3:12 am     Reply with quote

and our answers complemented each other well, with 'alternative solutions'. Smile

Best Wishes
BLL



Joined: 11 Nov 2006
Posts: 181
Location: Birmingham, UK

View user's profile Send private message

PostPosted: Sat Sep 29, 2012 9:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Sep 29, 2012 1:22 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Sep 29, 2012 10:54 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 30, 2012 1:38 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 30, 2012 2:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 30, 2012 12:45 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 30, 2012 1:45 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group