Author Topic: Logic level converter, 0-12v to 0-3.3v.  (Read 1113 times)

0 Members and 1 Guest are viewing this topic.

Offline luiHSTopic starter

  • Frequent Contributor
  • **
  • Posts: 609
  • Country: es
Logic level converter, 0-12v to 0-3.3v.
« on: October 21, 2024, 09:25:34 pm »

I need to read two-state signals of 0 and 12v with the ports of a RT1064 microcontroller, to convert them to 0 - 3.3v signals compatible with the GPIO of the microcontroller.

I thought of something as simple as a diode and a pullup resistor, but I have my doubts. Now I think that I will not really get the low logic level of 0v in the GPIO, but the voltage drop of the 0.7v diode. And I think that the microcontroller will not interpret it as a low logic level or that value may be right on the border of what is the low logic level and the reading of those signals may be unstable with erroneous readings.

I saw other schemes using BJT and MOSFET transistors, or for 5v signals using logic gates like the 74HCT245.
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4884
  • Country: dk
Re: Logic level converter, 0-12v to 0-3.3v.
« Reply #1 on: October 21, 2024, 09:37:07 pm »
two resistors, divide 12V down to 3.3V
 
The following users thanked this post: luiHS

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20524
  • Country: gb
  • 0999
Re: Logic level converter, 0-12v to 0-3.3v.
« Reply #2 on: October 21, 2024, 09:42:42 pm »
It will also default to 12V, if the input floats, i.e. is left unconnected.

Why not use a potential divider?


R1 = 33k
R2 = 10k

How fast does it need to be? If more speed is required then put a 100pF capacitor across R1 and a 33pF capacitor across R2, forming a capacitive divider with the same attenuation factor as the resistors.
 
The following users thanked this post: luiHS

Offline bson

  • Supporter
  • ****
  • Posts: 2506
  • Country: us
Re: Logic level converter, 0-12v to 0-3.3v.
« Reply #3 on: October 21, 2024, 10:01:01 pm »
What's the threshold on the 0-12V signal?
 
The following users thanked this post: luiHS

Offline luiHSTopic starter

  • Frequent Contributor
  • **
  • Posts: 609
  • Country: es
Re: Logic level converter, 0-12v to 0-3.3v.
« Reply #4 on: October 21, 2024, 10:16:47 pm »
What's the threshold on the 0-12V signal?

The 0-12v input is via switches, the line is at 12v via a pullup resistor and each switch connects to GND when closed.

According to the datasheet, the logic levels of the RT1064 GPIO are from 0 to 0.3v for the low logic level and from 0.7 to VCC for the high. What I don't understand is what happens between 0.3 and 0.7v
 

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 2139
  • Country: au
Re: Logic level converter, 0-12v to 0-3.3v.
« Reply #5 on: October 22, 2024, 02:08:39 am »
What's the threshold on the 0-12V signal?

The 0-12v input is via switches, the line is at 12v via a pullup resistor and each switch connects to GND when closed.

According to the datasheet, the logic levels of the RT1064 GPIO are from 0 to 0.3v for the low logic level and from 0.7 to VCC for the high. What I don't understand is what happens between 0.3 and 0.7v

Usually that is margin and hysteresis. Measure a few devices and check.
Then take your desired 12V sense level (eg 6V ?) and divide that down to the GPIO. 6V -> 500mV divider will sit with 1V with 12V in.

Or, you could use a Digital Transistor with resistor ratio chosen to give a higher threshold,  eg a PDTC144V (47K : 10k) specs typical  3.1V off and 3.8V on

or you could choose a Digital transistor + a 50uA zener if you want a more precise, even higher threshold.
 
The following users thanked this post: luiHS

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15956
  • Country: fr
Re: Logic level converter, 0-12v to 0-3.3v.
« Reply #6 on: October 22, 2024, 02:19:03 am »
The simpler would be a resistive divider as suggested above. It's safe. Benefit is that it gives you a pull-down for free when the "12V" signal is floating.
Now since you mentioned how you get this 12V signal, we know that speed is not an issue. But, a resistive divider as is would be, as the signal comes from a pull-up to 12V (is the pull-up value known and purely resistive?)
If it's a known resistor value, then all you'd need is a pull-down resistor, which will act as a resistive divider combined with the pull-up resistor. Done. You could add a diode to Vdd (3.3V) to clamp it, just in case something goes wrong.


 
The following users thanked this post: luiHS


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf