Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Logic Level Conversion - PIC

Status
Not open for further replies.

Suraj143

Active Member
I'm Reading a UART stream which has voltage levels of 2.8V Max & 0V & the reception is done using a 5V UART PIC.PIC UART receiver has a schmitt trigger input so it is expecting 0.8*5V = 4V to receive data properly.I made the below circuit but sometimes its not working. How to bias it properly?
 

Attachments

  • PIC+UART.JPG
    PIC+UART.JPG
    17.1 KB · Views: 180
Are you sure it has a schmitt trigger input?, I thought the UART inputs were usually standard TTL?.

Your circuit is doing little because it's a common emitter circuit (I'm surprised it works at all?), with an NPN transistor (and the other way up) it will work properly, BUT will invert the signal - can you invert the source in the code there?, or use a software UART in the 628 where you could invert it in the software. Or use a more modern device that allows inversion of the UART hardware.

However, you say the incoming signal is 2,8V?, is it from a 3,3V device?, because RS232 from 3.3V devices normally works perfectly on a 5V PIC.
 
I changed the 'sex' of the transistor. What you had, the transistor will be on all the time.
1592483680766.png
 
There are many diagrams of level converters between 3.3V and 5V using a simple MOSFET:

1592487571500.jpeg


You can buy 2 or 4 port level converters ready made on places like Amazon or Ebay. These are bi-directional, so they can be used to receive or send, but can also be used in one direction only. I use such a level converter between a 3.3V GPS and an Arduino in receive mode only.

PS: Sorry, I posted the same image as the link previously posted by Spudboy, I just never followed the link till now...
 
There are many diagrams of level converters between 3.3V and 5V using a simple MOSFET:

View attachment 125493

You can buy 2 or 4 port level converters ready made on places like Amazon or Ebay. These are bi-directional, so they can be used to receive or send, but can also be used in one direction only. I use such a level converter between a 3.3V GPS and an Arduino in receive mode only.

PS: Sorry, I posted the same image as the link previously posted by Spudboy, I just never followed the link till now...

No problem as it means it's instantly visible.

However, it should probably work perfectly anyway with no conversion (the input is a schmitt when set to RX, and TTL as I/O) - I wonder if he's ever actually tried it?.
 
OK thank you very much for the info.

The UART data coming from a SIM800L GSM module. The incoming UART signal has 2.8V max voltage.All this time I did with a PNP transistor method.It worked.But the levels are in the marginal.Not enough to capture the signals from the PIC.Because PIC sees 2.8V + 0.7V = 3.5V not enough.

I'm using hardware UART.I have some large SMS strings to be read.Home workbench its working but in the site environment the SMS mostly fails to capture by PIC. :( I need to stick with the same PIC16F628A.
 
OK thank you very much for the info.

The UART data coming from a SIM800L GSM module. The incoming UART signal has 2.8V max voltage.All this time I did with a PNP transistor method.It worked.But the levels are in the marginal.Not enough to capture the signals from the PIC.Because PIC sees 2.8V + 0.7V = 3.5V not enough.

I'm using hardware UART.I have some large SMS strings to be read.Home workbench its working but in the site environment the SMS mostly fails to capture by PIC. :( I need to stick with the same PIC16F628A.

I don't see how the PNP version could ever work?, a better option would probably be a simple silicon diode rather than a transistor, which would give the 2.8+0.7V. Can you confirm that you've tried it with nothing?, and that it wouldn't work like that.

If it won't, then use the FET version shown above - or run the PIC at a lower voltage? - I presume you're attenuating the PIC output to the SIM800?, or you'll kill it.

However, a major issue is the choice of PIC, the 628 is an antique with low spec and VERY little memory, either ROM or RAM - only 224 bytes or RAM (split across 3 banks) making it difficult to handle large strings. An SMS message can easily exceed that.

For my original foray in to SMS I upgraded to the 16F1827 which gives you 384 bytes of RAM, and allows you to access it as one contiguous linear buffer, rather than as different banks.

Now I use more modern devices again, which offer far greater memory capacities, such as the 16F18446 offering 28K ROM and 2K RAM (as a low cost example, similar to a 16F628).
 
I have often used the circuit posted by sagor1.

For I2C, change the resistors to 4.7k and don't use any other pullup resistors.
 
Nigel has a valid point, can you run the PIC at a lower voltage? Even at 4.0V or 4.5V, your input to the UART may be enough to trigger the threshold. One issue may the clock speed. At 5.0V, you can run up to 20Mhz. At 4.5V, that starts to drop, but looks close to 20Mhz maximum (graph is not clear on this in datasheet). At 4.0V, maximum clock (crystal) speed seems to be about 15Mhz. See 16F628A datasheet, section 17. Other issue is, what else is the PIC driving, is 4.5V or 4.0V enough to drive external devices attached to the PIC?
Don't worry about using "old" PICs, they still do the job, if the job is "small". I've used, and still use, old PICs (16F6xx series and 12Fxxx series) with projects that only need 1k or 2k of program space, including UART stuff (16F690, 16F688) and interrupts.
 
Don't worry about using "old" PICs, they still do the job, if the job is "small". I've used, and still use, old PICs (16F6xx series and 12Fxxx series) with projects that only need 1k or 2k of program space, including UART stuff (16F690, 16F688) and interrupts.

It's not the 'age' that the issue, it's lack of memory, and specifically lack or RAM - the SIM800 will spit out more data from an SMS than the entire RAM of the 628, which is on multiple banks anyway, and you've got to do something with it before it's lost. The 16F1827 I mentioned (and used for SMS) has enough linear RAM to store an entire SMS message, you can then process it from there.

One extra thought?, how fast is he running the UART?, if he's using the internal oscillator it's best to keep the speed down to the lower choices, I usually use 9600 baud.
 
I don't see how the PNP version could ever work?, a better option would probably be a simple silicon diode rather than a transistor, which would give the 2.8+0.7V. Can you confirm that you've tried it with nothing?, and that it wouldn't work like that.

If it won't, then use the FET version shown above - or run the PIC at a lower voltage? - I presume you're attenuating the PIC output to the SIM800?, or you'll kill it.

However, a major issue is the choice of PIC, the 628 is an antique with low spec and VERY little memory, either ROM or RAM - only 224 bytes or RAM (split across 3 banks) making it difficult to handle large strings. An SMS message can easily exceed that.

For my original foray in to SMS I upgraded to the 16F1827 which gives you 384 bytes of RAM, and allows you to access it as one contiguous linear buffer, rather than as different banks.

Now I use more modern devices again, which offer far greater memory capacities, such as the 16F18446 offering 28K ROM and 2K RAM (as a low cost example, similar to a 16F628).
Very good info.Actually I tried without anything.Directly connected the SIM800 TX to PIC RX & the PIC TX via a voltage divider to SIM800.No any data receives That's why I added a PNP. It worked but its not a reliable method due to voltage levels.

When I lower down the supply voltage to 4V it worked nicely.I changed my entire PCB design & made the changes like "Spudboy488" mentioned (Two transistor version).In this time also the power supply is 4V.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top