Author Topic: PIC UART Level Issue  (Read 1936 times)

0 Members and 1 Guest are viewing this topic.

Offline Joseph1

  • Contributor
  • Posts: 14
  • Country: au
PIC UART Level Issue
« on: October 08, 2021, 12:32:46 am »
Want to connect PIC 16F628A directly to SIM800L (without any level converters) as in the schematic. The design works @ home, but in site condition it wont work.

All the trouble comes in SIM800L Transmitt path (When GSM modules recieves a call & SMS) in site condition the PIC won't recieve data properly.But when PIC transmit data (send call, send sms) it works nicely.

I have attached voltage levels of both PIC & SIM800L modules.

Are those levels matching?
« Last Edit: October 08, 2021, 12:41:30 am by Joseph1 »
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 1893
  • Country: us
Re: PIC UART Level Issue
« Reply #1 on: October 08, 2021, 10:13:05 am »
Welcome to EEVBlog

At what voltage are you running the 16F628A?  If 5V, then 0.8VDD = 4V for hi (see DO41), so there may be a problem with that.  The 628A will operate at lower voltages, but at 3V its maximum operating frequency is lower.  Newer chips are available that operate fully at 3.3V and would require little, if any additional programming.  Although, I don't know (doubt) there is a pin compatible version.
« Last Edit: October 08, 2021, 10:15:03 am by jpanhalt »
 
The following users thanked this post: Joseph1

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 2940
  • Country: it
Re: PIC UART Level Issue
« Reply #2 on: October 08, 2021, 11:26:08 am »
It's 3.3V nominal, he already posted the same question in the microchip forum.

Have you (OP) tried looking at the data with an oscilloscope? In any case there is little margin for it to work, i would rather put a level translator (it can be as simple as two resistors and a mosfet)
 
The following users thanked this post: jpanhalt, Joseph1

Offline Joseph1

  • Contributor
  • Posts: 14
  • Country: au
Re: PIC UART Level Issue
« Reply #3 on: October 09, 2021, 02:53:14 am »
Thanks both of you.

My supply voltage for PIC is 3V3. After reading the comments I planned to change the design to power the PIC from 5V & add a level shifer.

It's 3.3V nominal, he already posted the same question in the microchip forum.

Have you (OP) tried looking at the data with an oscilloscope? In any case there is little margin for it to work, i would rather put a level translator (it can be as simple as two resistors and a mosfet)

You got it.My design is in marginal level.I guess that's why its why it is not working in noise environments.
I planned to add a level shifter & check.Here is my drawing.

How can I supply the low side Voltage for the level shifter? What voltage need & do I need another regulator for that?
« Last Edit: October 09, 2021, 02:56:31 am by Joseph1 »
 

Offline MIS42N

  • Frequent Contributor
  • **
  • Posts: 328
  • Country: au
Re: PIC UART Level Issue
« Reply #4 on: October 09, 2021, 05:09:57 am »
I think your original scheme should work. The Voh output is minimum 2.7V, The required input to the 628A is 2.64V. Close but still within specification. If noise is your problem it is probably the earth connection between the two chips. It is better to fix that than redesign.

If you do want to redesign, this might be useful. Many years ago, I made a Sidereal clock. http://www.cashin.net/sidereal/circuit.html, it shows how I used the 2N7000.

Most device outputs are capable of sourcing and sinking current, so you shouldn't need a pull up resistor on low side.  The gate voltage has to be a similar level to the low side high signal, so the 2N7000 is not conducting. This has to be balanced against the need to conduct with gate to low side low turning it on. You could determine it by experiment, but I would go for a gate voltage of 3.3V or thereabouts. You could provide it by a divider off the 5V rail and a bypass capacitor, the gate doesn't draw significant current.

Unfortunately, the 628A USART input doesn't have a weak pullup. In my circuit one of the outputs (the 1pps signal) goes to a pin that does have a weak pullup, so no additional pullup was required.

If you feel like doing something weird and had spare I/O pins, you could set up a comparator with input from the SIM800L and a reference voltage of say 2V, and send the comparator output to a pin which is connected to the RX pin. Get your level shift for free.
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 2893
  • Country: gb
Re: PIC UART Level Issue
« Reply #5 on: October 09, 2021, 09:33:57 am »
I think your original scheme should work. The Voh output is minimum 2.7V, The required input to the 628A is 2.64V. Close but still within specification. If noise is your problem it is probably the earth connection between the two chips. It is better to fix that than redesign

Noise is a fact of life, and with such little noise margin the design can be expected to be unreliable.
 
The following users thanked this post: SiliconWizard, Joseph1

Offline MIS42N

  • Frequent Contributor
  • **
  • Posts: 328
  • Country: au
Re: PIC UART Level Issue
« Reply #6 on: October 09, 2021, 08:43:18 pm »
I think your original scheme should work. The Voh output is minimum 2.7V, The required input to the 628A is 2.64V. Close but still within specification. If noise is your problem it is probably the earth connection between the two chips. It is better to fix that than redesign

Noise is a fact of life, and with such little noise margin the design can be expected to be unreliable.
If designers had that attitude, HiFi amplifiers wouldn't exist. If the margin was microvolts, then it's challenging. 60mV not so hard. It's a schmitt trigger input so should have good noise immunity.
 

Offline Joseph1

  • Contributor
  • Posts: 14
  • Country: au
Re: PIC UART Level Issue
« Reply #7 on: October 10, 2021, 02:27:39 am »
I think your original scheme should work. The Voh output is minimum 2.7V, The required input to the 628A is 2.64V. Close but still within specification. If noise is your problem it is probably the earth connection between the two chips. It is better to fix that than redesign.

If you do want to redesign, this might be useful. Many years ago, I made a Sidereal clock. http://www.cashin.net/sidereal/circuit.html, it shows how I used the 2N7000.

Most device outputs are capable of sourcing and sinking current, so you shouldn't need a pull up resistor on low side.  The gate voltage has to be a similar level to the low side high signal, so the 2N7000 is not conducting. This has to be balanced against the need to conduct with gate to low side low turning it on. You could determine it by experiment, but I would go for a gate voltage of 3.3V or thereabouts. You could provide it by a divider off the 5V rail and a bypass capacitor, the gate doesn't draw significant current.

Unfortunately, the 628A USART input doesn't have a weak pullup. In my circuit one of the outputs (the 1pps signal) goes to a pin that does have a weak pullup, so no additional pullup was required.

If you feel like doing something weird and had spare I/O pins, you could set up a comparator with input from the SIM800L and a reference voltage of say 2V, and send the comparator output to a pin which is connected to the RX pin. Get your level shift for free.

Excellant clear reply.You got it.After failing many times I redesigned the PCB layout as in the original schematic.The problems came down to half way mark.I think there is a long routed ground path issues (I don't know that).But further I want to clear all customer complaints (Again Not working....) by adding a level shifter.Because sometimes this unit has to place nearby RF panels, low GSM signal areas etc...So the pcb signal path has to be super steady in any environment.

I have attached the new schematic.See how it looks likes.It is nice that I can form a divider voltage from a normal 7805 rather than GSM supply voltage (4.2V).Because When GSM signal recieving, the buck converter voltage fluctuates due to drawing large currents that can misbehaves the FET gate voltage.
« Last Edit: October 10, 2021, 02:32:25 am by Joseph1 »
 

Offline Joseph1

  • Contributor
  • Posts: 14
  • Country: au
Re: PIC UART Level Issue
« Reply #8 on: October 11, 2021, 05:39:08 am »
A small doubt regarding choosing the level shifter transistor.Can this 2N7000 operates from 2.7V? Is its Vgs is can be low as that?  I don't have BSS138.
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 1893
  • Country: us
Re: PIC UART Level Issue
« Reply #9 on: October 11, 2021, 08:48:19 am »
Its gate threshold is nominally 2.1V but it can be as high as 3V.
 

Offline Joseph1

  • Contributor
  • Posts: 14
  • Country: au
Re: PIC UART Level Issue
« Reply #10 on: October 11, 2021, 09:20:21 am »
Ok.My divider resistors generates 2.7V for gate, is it work reliably or need to up the gate voltage level to 3V ?
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 1893
  • Country: us
Re: PIC UART Level Issue
« Reply #11 on: October 11, 2021, 09:37:29 am »
In my view, any project that depends on selecting components from a batch with certain characteristics is asking to be redesigned.

Have you considered conventional level shifters:
Microchip:
http://ww1.microchip.com/downloads/en/DeviceDoc/chapter%208.pdf
TI:
http://www.ti.com/lit/sg/scyb018f/scyb018f.pdf
N-channel bidirectional mosfet:
Philips 1997 (secondary site):
http://www.adafruit.com/datasheets/an97055.pdf
NXP 2007
https://www.nxp.com/docs/en/application-note/AN10441.pdf
Sparkfun board and schematic:
https://learn.sparkfun.com/tutorials/bi-directional-logic-level-converter-hookup-guide

That is just copy and pasted from my files.  The NXP reference is often cited.
 

Offline Joseph1

  • Contributor
  • Posts: 14
  • Country: au
Re: PIC UART Level Issue
« Reply #12 on: October 13, 2021, 09:43:59 am »
Hi All.

I made the following circuit with added FET level converter for UART. But the results are worst.Earlier when I lower the PIC supply voltage to 3V3 & directly drive the SIM800L it works nicely (even though it is in marginal).

But with the new modification the data is coming weirdly. Sometimes coming & sometimes it takes time to come.
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 1893
  • Country: us
Re: PIC UART Level Issue
« Reply #13 on: October 13, 2021, 10:09:32 am »
Have you looked at the input signal to the PIC?  Here's the recommended level shifter (source: https://www.gme.cz/data/attachments/dsh.775-083.1.pdf  ,page 31).



Why not use it?
 

Offline Joseph1

  • Contributor
  • Posts: 14
  • Country: au
Re: PIC UART Level Issue
« Reply #14 on: October 13, 2021, 11:08:38 am »
Have you looked at the input signal to the PIC?  Here's the recommended level shifter (source: https://www.gme.cz/data/attachments/dsh.775-083.1.pdf  ,page 31).



Why not use it?

Its hard to find SMD unfamiliar Transistors.I am not sure it can be done using commonly available 2N2222 part....!!!
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 9165
  • Country: fr
Re: PIC UART Level Issue
« Reply #15 on: October 13, 2021, 05:31:15 pm »
It should work with pretty much any NPN transistor here.
 

Offline MIS42N

  • Frequent Contributor
  • **
  • Posts: 328
  • Country: au
Re: PIC UART Level Issue
« Reply #16 on: October 13, 2021, 09:07:14 pm »
I don't think you mentioned what baud rate you are using. It should be the lowest rate that gets the job done. Although speeds of 115,200 work, the faster they are the less tolerant to external interference. Also some high baud rates are hard to match with the processor clock, so there is a residual speed error. Up to 2% is OK, over 5% things stop working. And I did recommend 3.3V for the gate, the 2N7000 should be off with less than 0.7V, but on can be as high as 3V. There is no need to use a FET, the advantage they have is they are bidirectional.
 

Offline Joseph1

  • Contributor
  • Posts: 14
  • Country: au
Re: PIC UART Level Issue
« Reply #17 on: October 13, 2021, 11:42:43 pm »
I don't think you mentioned what baud rate you are using. It should be the lowest rate that gets the job done. Although speeds of 115,200 work, the faster they are the less tolerant to external interference. Also some high baud rates are hard to match with the processor clock, so there is a residual speed error. Up to 2% is OK, over 5% things stop working. And I did recommend 3.3V for the gate, the 2N7000 should be off with less than 0.7V, but on can be as high as 3V. There is no need to use a FET, the advantage they have is they are bidirectional.
Thanks.I am using 9600bps.Just thinking what to do.Do some experiments with FET thing (increase gate voltage etc...) or Just stick with direct connection method..!!
 

Offline MIS42N

  • Frequent Contributor
  • **
  • Posts: 328
  • Country: au
Re: PIC UART Level Issue
« Reply #18 on: October 14, 2021, 08:54:10 am »
Thanks.I am using 9600bps.Just thinking what to do.Do some experiments with FET thing (increase gate voltage etc...) or Just stick with direct connection method..!!
You didn't say if you have an oscilloscope. If you are using one of the cheap 3A buck converters, their output is quite noisy when the current draw is small. You should look there. You don't show any additional bypass capacitors on the SIM800L supply, it may pay to put more capacitance there, low ESR electrolytic and a ceramic. It seems people do have trouble with the power supply because of the very short 2A bursts of current. Also need a bypass on the FET gate to GND. You may have one but don't show it.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 2611
  • Country: es
Re: PIC UART Level Issue
« Reply #19 on: October 14, 2021, 11:48:53 pm »
If your application doesn't really need 20MHz to comply the requirements, easy fix, it's 4V for 16MHz and 3V for 10MHz. (Datasheet page 136)
0.8x4VDD is 3.2V, still very close but might work. The best is to run it at 3.3V if possible.
Of course, the rest of the circuitry should be capable of working at such voltage.
Thats a prehistoric pic BTW.
« Last Edit: October 14, 2021, 11:52:21 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Joseph1

  • Contributor
  • Posts: 14
  • Country: au
Re: PIC UART Level Issue
« Reply #20 on: October 17, 2021, 04:05:50 pm »
You didn't say if you have an oscilloscope. If you are using one of the cheap 3A buck converters, their output is quite noisy when the current draw is small. You should look there. You don't show any additional bypass capacitors on the SIM800L supply, it may pay to put more capacitance there, low ESR electrolytic and a ceramic. It seems people do have trouble with the power supply because of the very short 2A bursts of current. Also need a bypass on the FET gate to GND. You may have one but don't show it.

Yes I have an oscilloscope. BUt didn't try to capture some waveforms yet. I use cheap LM2596 buck modules Like these.
https://www.amazon.com/Lysignal-LM2596-Supply-Adjustable-Converter/dp/B074J4NXCM

I don't use any capacitors on the PCB except the 0.1uF ceramic cap to PIC micro.I guess the SIM800L modules have some 100uF cap & two ceramic caps on its board.DO I need additional caps for SIM800L module?

https://www.amazon.com/DAOKI-SIM800L-MicroSIM-Quad-Band-3-7-4-2V/dp/B08212SNVQ/ref=sr_1_6?crid=13FM1A01M2P14&dchild=1&keywords=sim800l&qid=1634486701&s=electronics&sr=1-6


 

Offline Joseph1

  • Contributor
  • Posts: 14
  • Country: au
Re: PIC UART Level Issue
« Reply #21 on: October 17, 2021, 04:09:11 pm »
If your application doesn't really need 20MHz to comply the requirements, easy fix, it's 4V for 16MHz and 3V for 10MHz. (Datasheet page 136)
0.8x4VDD is 3.2V, still very close but might work. The best is to run it at 3.3V if possible.
Of course, the rest of the circuitry should be capable of working at such voltage.
Thats a prehistoric pic BTW.

For 9600bps I'm using internal 4Mhz oscillator.I'm doing testing on my original design (the 3V3 version).Most tries are ok.But sometimes in the noisy environment it misses the incoming phone number captured by the PIC..!!
 

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1350
  • Country: us
  • Very dangerous - may attack at any time
Re: PIC UART Level Issue
« Reply #22 on: October 17, 2021, 04:55:08 pm »
Are you using the hardware UART? If so, what is the baud rate generator configuration. I suspect you have a more than 7% error on the bit rate. Should be under 2% for reliable operation.
 

Offline Joseph1

  • Contributor
  • Posts: 14
  • Country: au
Re: PIC UART Level Issue
« Reply #23 on: October 17, 2021, 05:36:21 pm »
Are you using the hardware UART? If so, what is the baud rate generator configuration. I suspect you have a more than 7% error on the bit rate. Should be under 2% for reliable operation.

I use hardware UART.
SPBRG =25(decimal)
oscillator =4Mhz internal osc

On SIM800L Init I dont send any baudrate commands in power up sequence.(Using the factory default ones).
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf