LPC2138 ADC question

Hi all.

I’d like to use the LPC2138 ADC to measure a signal that goes from 0 to +5v but the doc says the ADC can only handle up to 3v.

What’s the best way to convert the signal?

Thanks.

Ben.

Use a couple of resistors as a voltage divider.

Leon

Thanks for that.

Will this give me a good linear conversion?

Ben.

In fact, since I’m only interested in the first 3v out of the 5, is there an easy way to limit the signal to 3v so that anything above that is capped to 3v?

Sorry if these seem like very basic questions. I should have thought of the voltage divider :blush:

I think it will be limited to 3.3V by the ADC input, anyway. There is something in the User Manual about it.

Leon

shoppinit:
In fact, since I’m only interested in the first 3v out of the 5, is there an easy way to limit the signal to 3v so that anything above that is capped to 3v?

Sorry if these seem like very basic questions. I should have thought of the voltage divider :blush:

You can use a series current limiting resistor from your source, and then use a low voltage drop diode to your chips power supply pin as a voltage clamp. That will limit the voltage to VCC plus the diode drop, so it should be a low voltage drop type of diode.

OR, you could use the simple voltage divider and account for it in your A/D output calculations. A resistive voltage divider is, of course, perfectly linear. BUT, there are some things to watch out for. You need to be aware of the rate of change of your input signal, and size the total value of your resistor divider accordingly. The voltage divider forms an RC filter with the stray capacitance and input capacitance of your chip pins, so overly large resistor values will affect the maximum slew rate that you will see at the A/D input pins. At the other end, resistor values that are too small will load the source that you are trying measure. Sooooo, just give some thought to how you select the resistor values for your voltage divide.

Hope that helps.

–Dave

Thanks Dave, that’s a real help.

I’ve tried with the divider using a 15k and a 10k resistor to get from 5v to 3v. My sensor outputs at 12kHz and the signal can change pretty quickly, but I’ll only be sampling at about 1kHz. Do the resistance values sound ok?

Because the LPC2138 only has a 10 bit ADC just using the first 3 volts would give me better resolution so I’m going to look at the voltage drop diode that you mentioned.

Thanks again.

shoppinit:
Thanks Dave, that’s a real help.

I’ve tried with the divider using a 15k and a 10k resistor to get from 5v to 3v. My sensor outputs at 12kHz and the signal can change pretty quickly, but I’ll only be sampling at about 1kHz. Do the resistance values sound ok?

Because the LPC2138 only has a 10 bit ADC just using the first 3 volts would give me better resolution so I’m going to look at the voltage drop diode that you mentioned.

Thanks again.

The values look reasonable for the parameters that you gave. Not knowing your actual layout and pin capacitance I used a WAG of 10pf, so if it is actually in that range your divider values should be fine.

If you are breadboarding this setup and want to use the diode voltage clamp method, you could just remove the 15K resistor and leave the 10K in place. Then just connect the diode anode to the junction of the 10K resistor and A/D input pin, with the cathode connected to the chip power supply. Just remember that the clamp voltage will be the chip power supply voltage PLUS the diode forward voltage drop, so a low drop diode type, like a Schottky diode, will be the safest bet.

–Dave

Thanks for the useful answers. I got the ADC working OK.

I have another question that I guess is pretty basic, but I can’t get my head around it.

I want to use one of the digital IO pins on the LPC2138 for input and drive it with an external opto, but I’m scratching my head trying to work out how to connect one to the other.

The opto puts out 5v, but I need to pull the micro pin high (or low) but can’t figure out how to do it since the opto and the micro have separate power supplies. If I connect the opto to the IO pin directly then when the output is 5v my pin goes high, but when there is no output from the opto I guess my pin is floating.

I guess this should be really simple, but I just can’t figure it out! How can I do this?

Thanks.

Ben.

shoppinit:
Thanks for the useful answers. I got the ADC working OK.

I have another question that I guess is pretty basic, but I can’t get my head around it.

I want to use one of the digital IO pins on the LPC2138 for input and drive it with an external opto, but I’m scratching my head trying to work out how to connect one to the other.

The opto puts out 5v, but I need to pull the micro pin high (or low) but can’t figure out how to do it since the opto and the micro have separate power supplies. If I connect the opto to the IO pin directly then when the output is 5v my pin goes high, but when there is no output from the opto I guess my pin is floating.

I guess this should be really simple, but I just can’t figure it out! How can I do this?

Thanks.

Ben.

That question is a bit difficult to answer without knowing more about your optical device. Anyway, your description sounds like it’s output is either an open source FET or an open emitter transistor, IF it can only pull high. If that is the case, you need a resistor to ground for it to pull current through when it goes high, and the resistor will hold the LPC2138 input low when the opto device is not drawing current through it. The size of the source resistor will be determined by the swithing speed that you need, with smaller being faster but drawing more current. Since the digital inputs are 5 volt tolerant, you should not need to do anything to limit the input voltage.

–Dave

Thanks for that Dave,

I still can’t figure out how to do this and I’m getting in a mess with resistors all over the place and unexpected voltages at inputs…

Here’s the schematic of the opto I’m using.

http://barn.renovate.france.free.fr/opto.jpg

When the opto isn’t activated, I get 5v on the output and the LED is off. When it is activated, the LED is on and the output goes to 0v.

Maybe I can just connect the output from the opto directly to the microcontroller input? There already seem to be lots of resistors there - maybe I’m adding them unnecessarily…

Does any of this make sense?

Thanks.

Ben.

shoppinit:
Thanks for that Dave,

I still can’t figure out how to do this and I’m getting in a mess with resistors all over the place and unexpected voltages at inputs…

Here’s the schematic of the opto I’m using.

http://barn.renovate.france.free.fr/opto.jpg

When the opto isn’t activated, I get 5v on the output and the LED is off. When it is activated, the LED is on and the output goes to 0v.

Maybe I can just connect the output from the opto directly to the microcontroller input? There already seem to be lots of resistors there - maybe I’m adding them unnecessarily…

Does any of this make sense?

Thanks.

Ben.

Ahhhh Yes, it does make sense now! The short answer is that you can connect the pin labeled OUTPUT directly to a 5V tolerant LPC2138 digital input pin. In fact, it looks like the +VCC pin directly above the OUTPUT pin could be powered from the same power supply voltage as the LPC2138 unless it is specifically specified for 5V operation. When sufficient current flows between the upper two pins in your schematic, either plus or minus, then the two transistors in your schematic will be turned on and pull the OUTPUT pin to logic ZERO. When there is no current between the upper two pins, the two transistors will be off and the 3.3K resistor connected to the output pin will pull the OUTPUT to logic ONE.

–Dave

Brilliant, thanks for that Dave. That makes my life a lot easier.

I’m powering the opto and the micro with the same 5v power source (PC power supply), so I guess I should be OK with that setup. The opto needs 5v. I tried powering it with the 3.3 from the LPC, but that didn’t work.

One more problem solved. :slight_smile:

Thanks again!

Hi Dave,

Sorry to come back to you again on this, but I can’t get this circuit working properly. I thought the problem was resolved, but I guess it can’t be because the inputs are very sensitive to noise and interference - like they were floating.

Yet, the pins are at 5v… I really don’t understand. I’ve even tried powering the whole thing from batteries.

Do you have any ideas? I’m pulling my hair out here!

Thanks.

Ben.

shoppinit:
Hi Dave,

Sorry to come back to you again on this, but I can’t get this circuit working properly. I thought the problem was resolved, but I guess it can’t be because the inputs are very sensitive to noise and interference - like they were floating.

Yet, the pins are at 5v… I really don’t understand. I’ve even tried powering the whole thing from batteries.

Do you have any ideas? I’m pulling my hair out here!

Thanks.

Ben.

If the inputs that you are referring two are the top two pins (labeled VAC or VDC) in your schematic, you are right, they are floating. That way, you can drive them either differentially or single ended. I have no idea what your circuit driving them looks like, so here are a few general suggestions. If you have a long pair of wires driving those two pins differentially there is a good possibility of picking up power line frequency hum. In that configuration it helps to have the wires tightly twisted together as is done with telephone line cables. You can also reduce the sensitivity to hum pickup if you terminate the twisted pair wires with a resistor across the two (VAC or VDC) terminals. Something the 300-600 ohm range would be good if your drive circuit can handle it. If you just need single ended drive, then you can just ground whichever (VAC or VDC) terminal that you do not have the signal going to.

–Dave

Hi Dave,

Thanks for that. It looks like the problem is one of impedance matching, or so I’m told. I’ve no idea how to resolve this :(.

I’m tempted to solder a different opto directly onto the development board and get rid of the 6ft of wire I have going from the micro input pin to the rack and external opto.

I don’t see how this would resolve the impedance issue, but I’m running out of options (and time!)

What do you think?

Thanks again.

shoppinit:
Hi Dave,

Thanks for that. It looks like the problem is one of impedance matching, or so I’m told. I’ve no idea how to resolve this :(.

I’m tempted to solder a different opto directly onto the development board and get rid of the 6ft of wire I have going from the micro input pin to the rack and external opto.

I don’t see how this would resolve the impedance issue, but I’m running out of options (and time!)

What do you think?

Thanks again.

Are you saying that you have noise pickup at the input to the optoisolator circuit, OR at the output between the optoisolator and the LPC chip input???

If the noise pickup is at the input to the optoisolator, then the options I mentioned in my last post should help with that. If you really have six feet of wire between the optoisolator and the micro that is certainly a different issue. I guess that would also mean that you are running the VCC and logic ground signals the same six feet distance? That is a long ways to run a digital logic signal, plus there are two extra wires that can pick up noise, especially in a high noise environment. Of course, the ideal solution would be to have the optoisolator on the same circuit board as the LPC micro. You might be able to improve the situation by running the output signal on the center conductor of a coaxial cable, and ground the outer shield of the coaxial cable at both ends to reduce noise pickup. If you do that, then the coaxial cable takes care of your signal and ground connections, but you would need to add a capacitor from VCC to grond at the load end of VCC to bypass noise pickup on the six foot long VCC connection wire.

–Dave