Searching \ for '[PIC] 12F675 rs232 ground problem' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: piclist.org/techref/microchip/ios.htm?key=rs232
Search entire site for: '12F675 rs232 ground problem'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] 12F675 rs232 ground problem'
2012\01\05@081043 by Adam Walley

picon face
Hello,

I have been struggling to establish communication between my laptop and a
pic12f675. I am needing some help to get this working, because it's
starting to drive me nuts. I have tried various methods, but the
show-stopper always seems to be when I connect the laptop's serial ground
to the PIC's. I'm sure I am making some basic mistakes, but don't have much
electronics experience. My set-up is as follows:

- 5V power supply (4xAA rechargeable cells) with de-coupling capacitor
across + and - lines
- 12F675 microchip
- laptop with usb-serial adapter listening on COM port with Hyperterminal
- some simple PIC code, which blinks an LED on one pin, and transmits a
bit-banged letter 'K' at 9600 8N1 on a second pin

I would like to get to the stage where I can fine-tune my code, as I
suspect it will need some corrections, but I really need to get the wiring
right first.

The laptop's serial pins appear to be operating at -9.6/+9.6V. I can create
random characters by simply shorting the DTR and RX lines.

I also have a ready-made MAX232CPE board, which works very well between a
PC and a Motorola phone. I have tried to use this with the PIC, but come up
against the same problem: as soon as I connect the ground lines the PIC
stops working (blinking LED stops).

I have read as many tutorials and FAQs as I could find on the web, have
tried different approaches with transistors and mosfets, but still cannot
get this working.

One more point: I have attempted the same exercise with my Desktop PC on
its serial port, but only get the same results (which hopefully rules out
the USB adapter as the culprit).

Any help would be appreciated

2012\01\05@083151 by Jan-Erik Soderholm

face picon face
Hi.

Could you be more specific on what is connected where ?
Pin numbers and so on. Best is a schematic...
This *should* work, of course. :-)

Jan-Erik.


Adam Walley wrote 2012-01-05 14:10:
{Quote hidden}

> Any help would be appreciated

2012\01\05@090432 by Carl Denk

flavicon
face
Always can take at the PC end, and jump pins 2 and 3, the transmit and receive. Then with a terminal program, should see the echo (the software echo turned off).

On 1/5/2012 8:10 AM, Adam Walley wrote:
{Quote hidden}

>

2012\01\05@093526 by Adam Walley

picon face
part 1 3319 bytes content-type:text/plain; charset="iso-8859-1" (decoded quoted-printable)

Ok,

Here is a simple drawing, showing the most basic layout I have tried. All
PIC pins set to digital out, comparator off, GPIO1 is TX to PC's RX line
and GPIO2 is an LED which shows me when the program starts and stops and
blinks between cycles. The code should send the letter 'K' five times over
the TX pin before the PIC goes to sleep.

I am using the MPLAB IDE with some assembly code. I am assuming the coding
and subsequent programming of the chip all works, because I have
successfully written to the EEPROM and confirmed its contents. I have also
got a working I2C interface with an LM35 temperature sensor (this is part
of my frustration: I can read the temperature and put it in the EEPROM, but
I cannot get the *&^*! RS232 to send it to the PC).

What am I doing wrong?

P.S. I can confirm that shorting pins 2 and 3 on the PC side does echo any
characters typed, so that all seems fine.

On 5 January 2012 13:31, Jan-Erik Soderholm <spam_OUTjan-erik.soderholmTakeThisOuTspamtelia.com>wrote:

{Quote hidden}

> -

2012\01\05@100951 by Jan-Erik Soderholm
face picon face
OK. Seems OK.
Well, probably something with the code (since
we havn't seen it)... :-)

The PIC shouild not stop simply by connecting the GND.

Maybe the "RX" is not connected to the correct MAX232 pin ?

/Jan-Erik.


Adam Walley wrote 2012-01-05 15:35:
{Quote hidden}

>> -

2012\01\05@102915 by Jan-Erik Soderholm

face picon face
Another thing... :-)

Adam Walley wrote 2012-01-05 14:10:
> Hello,
>
> I have been struggling to establish communication between my laptop and a
> pic12f675.

Check PIC12F1840. Builtin USART (amongst many things).
Also faster (32 MHz INTOSC), more memory and so on...

Just got a batch of them a few days ago... :-)

/Jan-Erik

2012\01\05@110200 by Charles Craft

picon face
What happens if you only connect the grounds - no TX -> RX connection?
I think your going to need something (resistor?) between the PIC and a RS-232 pin.

On 1/5/2012 9:35 AM, Adam Walley wrote:
{Quote hidden}

>> -

2012\01\05@112046 by Joe Wronski

flavicon
face
Are you correctly stating that connecting the ground, and *only* the ground to the computer ground causes the circuit to malfunction?  Because with a battery operated circuit this is very improbable.   It won't work as drawn, unless the 12F675 has a built in logic to rs232 converter.    Why aren't you using the ready-made MAX232CPE board between the PIC and PC?
Joe W




On 1/5/2012 9:35 AM, Adam Walley wrote:
{Quote hidden}

>> -

2012\01\05@113630 by Jan-Erik Soderholm

face picon face


Charles Craft wrote 2012-01-05 17:02:
> What happens if you only connect the grounds - no TX ->  RX connection?
> I think your going to need something (resistor?) between the PIC and a
> RS-232 pin.

No, one need a proper RS232/TTL-CMOS converter, such as MAX232.
And since he has one (right?), this is a non-issue.




{Quote hidden}

>>> --

2012\01\05@115443 by Djula Djarmati

flavicon
On 05-Jan-12 14:10, Adam Walley wrote:
{Quote hidden}

Check if MCLR pin is floating and restarting the PIC randomly.

Write a program that blinks the LED only once, connect the battery and try to touch the MCLR pin with your hand or a metallic object. If it doesn't reset, connect the ground wire.

The decoupling capacitor should be very close to PIC, not on the battery or somewhere in the middle.

Djul

2012\01\05@124726 by Charles Craft

picon face
On 1/5/2012 11:36 AM, Jan-Erik Soderholm wrote:
>
> Charles Craft wrote 2012-01-05 17:02:
>    
>> What happens if you only connect the grounds - no TX ->   RX connection?
>> I think your going to need something (resistor?) between the PIC and a
>> RS-232 pin.
>>      
> No, one need a proper RS232/TTL-CMOS converter, such as MAX232.
> And since he has one (right?), this is a non-issue.
>
>    
Nice to have but not a must have.
Google "rs-232 ttl transistor" and look at the schematic images.
Somewhere around here I've got a temperature sensor built into a DB-25 shell running a PIC that's powered by DTR.
A diode, 2950 LDO regulator, couple resistors and a transistor to drive the transmit line.
No room or power available for a MAX-232 chip. Works just fine on laptops and a Sun server.

chuckc

2012\01\05@131049 by Carl Denk

flavicon
face

> No, one need a proper RS232/TTL-CMOS converter, such as MAX232.
> And since he has one (right?), this is a non-issue.
>    
>
And the MAX232 inverts the signal, don't forget that.  :

2012\01\05@134500 by David VanHorn

picon face
As shown, the PC will put negative voltage on the data pin, which is
probably causing problems.
I don't see any level conversion happening.

I have seen some "hack" jobs which connect the "ground" of the uC to
the data pin and connect Ground of the PC to the uC input, but I don't
recommend it.

Although it's not routinely done anymore, the RS-232 spec allows some
fairly high voltages (+/- 24V IIRC) on those lines.  There are several
reasons that you shouldn't directly connect a uC to an RS-232 port

2012\01\05@144603 by Adam Walley

picon face
Wow. I am certainly glad that I subscribed to this list. Thank you for all
the responses.
I will try to cover some of the points made so far:

- I will post the code I am using shortly...
- I could use a chip with a USART, but I like the idea of being in full
control of the serial comms, and had selected the 12F675 because it did
everything I needed at the lowest price
- My main aim is to achieve the sending from the chip to the PC. I have not
included anything for an RX pin on the chip at the moment
- I have read various websites (Roman Black's is one that comes to mind),
which seem to show that a direct connection between PIC and PC is possible,
including some using the 12F675
- I am seeing problems with the chip when I connect only the ground from
the PC's serial port. As soon as I pull this ground wire out the chip
starts operating again.
- I am seeing the same problems when I try to use the MAX232CPE board I
have (I would prefer to get this working without the board, because it is
being used for something else, but if necessary I can wire up a MAX232CPE
chip with the capacitors, etc...)
- In connection with the two previous points, I think Djula may be on to
something with the MCLR. I have read information from various sources, with
some suggesting pins should be grounded if not used, and others saying it
is best to leave them unconnected. At the moment, I am leaving them
unconnected if not in use. Could 'floating' pins be the problem?

Is there anything I can add to protect the chip from unwanted negative
voltage? Measuring voltage between the two ground lines with a multimeter
does seem to indicate the PC's ground line is lower by about 0.04V compared
with the batteries.

Code to follow..

2012\01\05@150047 by Adam Walley

picon face
Here is the code I am using with the MPLAB IDE v8.33
Sorry for any bad formatting. The code is very crude because I am still
testing and debugging (that is also why there is an eeprom write and the
flashing LEDs - these confirm that my code has run).

================== ASM ==================

;12F675 send 'K' byte to PC via RS232 (GPIO1)
; as basic as possible to test correct code format
;


#include <p12f675.inc>
errorlevel  -302               ; suppress message 302 from list file

__CONFIG  _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF &
_INTRC_OSC_NOCLKOUT & _MCLRE_ON & _CPD_OFF

;***** Reset vector *************************************************
org 0x00
nop
goto init

;***** Assign Constants Value ***************************************
#define BANK1 banksel 0x80 ;Select Bank1
#define BANK0 banksel 0x00 ;Select Bank0

CLOCK   EQU     4000000 ; Set the clock as 4 MHz

;***** Assign variables *********************************

addr EQU 0x20 ; address for EEPROM access
dat EQU 0x21 ; value for EEPROM I/O
cnt EQU 0x22 ; counter
pins EQU 0x23 ; TRISIO pin status buffer
io_tmp EQU 0x24 ; GPIO status buffer
delay_temp EQU 0x25 ; Required for "delay.inc"
byte EQU 0x28 ; temporary byte buffer

;***** MAIN *********************************************
init
clrf cnt
clrf dat
clrf addr
movlw b'00111001' ; GPIO 1,2 outputs
movwf pins ; store in pin buffer
BANK1
movwf TRISIO ; set I/O pins
clrf ANSEL ; make all I/O ports digital
BANK0
movlw 0x07 ; comparator OFF bits
movwf CMCON ; switch it off
bcf ADCON0,ADON ; switch off A/D converter
clrf io_tmp ; turn off i/o pins in buffer
clrf GPIO ; turn off i/o pins
movlw 0x05 ; LOOPS
movwf cnt ; init counter
movlw 0x50 ; initial address value
movwf addr ; set address
call ewrite ; write '00' to EEPROM for start
BANK0
incf addr,1 ; add 1 to address

movlw 0xc8 ; 200 milliseconds
call delay_ms ; wait
movlw 0xc8 ; 200 milliseconds
call delay_ms ; wait
movlw 0xc8 ; 200 milliseconds
call delay_ms ; wait
call tx_hi ; set TX pin high to begin

loop
call flash ; FLASH LED
movlw 0xc8 ; 200 milliseconds
call delay_ms ; wait
movlw 0xc8 ; 200 milliseconds
call delay_ms ; wait

; ------------------------------------------------ <K>
; send 'T' at 9600 baud
; binary: 00101010 LSB->MSB
; using a 4 MHz chip
; 1 / 2400 baud = 416.6667 cycles per bit
; 1 / 4800 baud = 208.3333 cycles per bit
; 1 / 9600 baud = 104.1667 cycles per bit

call tx_lo ; START bit [   8]
call delay50 ; [  58]
call delay20 ; [  78]
call delay20 ; [  98]
call delay6 ; [ 104]

call tx_lo ; (0)0101010 [   8]
call delay50 ; [  58]
call delay20 ; [  78]
call delay20 ; [  98]
call delay6 ; [ 104]

call tx_lo ; 0(0)101010 [   8]
call delay50 ; [  58]
call delay20 ; [  78]
call delay20 ; [  98]
call delay6 ; [ 104]

call tx_hi ; 00(1)01010 [   8]
call delay50 ; [  58]
call delay20 ; [  78]
call delay20 ; [  98]
call delay6 ; [ 104]

call tx_lo ; 001(0)1010 [   8]
call delay50 ; [  58]
call delay20 ; [  78]
call delay20 ; [  98]
call delay6 ; [ 104]

call tx_hi ; 0010(1)010 [   8]
call delay50 ; [  58]
call delay20 ; [  78]
call delay20 ; [  98]
call delay6 ; [ 104]

call tx_lo ; 00101(0)10 [   8]
call delay50 ; [  58]
call delay20 ; [  78]
call delay20 ; [  98]
call delay6 ; [ 104]

call tx_hi ; 001010(1)0 [   8]
call delay50 ; [  58]
call delay20 ; [  78]
call delay20 ; [  98]
call delay6 ; [ 104]

call tx_lo ; 0010101(0) [   8]
call delay50 ; [  58]
call delay20 ; [  78]
call delay20 ; [  98]
call delay6 ; [ 104]

call tx_hi ; STOP bit [   8]
call delay50 ; [  58]
call delay20 ; [  78]
call delay20 ; [  98]
call delay6 ; [ 104]

BANK0 ; switch back to Bank0
decfsz cnt,1 ; dec cnt by 1
goto loop ; cnt>0, keep looping
goto finish ;


;***** TX on GPIO1 **************************
tx_hi ; 8 cycles
BANK0 ; for GPIO
bsf io_tmp,1 ; GPIO1 pin ON
movfw io_tmp ; move io_tmp to W
movwf GPIO ; copy new state to GPIO port
return

tx_lo ; 8 cycles
BANK0 ; for GPIO
bcf io_tmp,1 ; GPIO1 pin OFF
movfw io_tmp ; move io_tmp to W
movwf GPIO ; copy new state to GPIO port
return

;***** FLASH LED **************************
flash
BANK0 ; for GPIO
bsf io_tmp,2 ; GPIO2 pin ON
movfw io_tmp ; move io_tmp to W
movwf GPIO ; copy new state to GPIO port
movlw 0xc8 ; 200 milliseconds
call delay_ms ; wait
movlw 0xc8 ; 200 milliseconds
call delay_ms ; wait
bcf io_tmp,2 ; GPIO2 pin OFF
movfw io_tmp ; update io_tmp
movwf GPIO ; copy new state to GPIO port
movlw 0xc8 ; 200 milliseconds
call delay_ms ; wait
return

led_on
BANK0 ; for GPIO
bsf io_tmp,2 ; GPIO2 pin ON
movfw io_tmp ; move io_tmp to W
movwf GPIO ; copy new state to GPIO port
return

led_off
BANK0 ; for GPIO
bcf io_tmp,2 ; GPIO2 pin OFF
movfw io_tmp ; move io_tmp to W
movwf GPIO ; copy new state to GPIO port
return

;***** FINISH *****************************
finish
call tx_lo ; switch off TX pin
movlw 0x64 ; 100 milliseconds
call delay_ms ; wait
call led_on
movlw 0x32 ; 50 milliseconds
call delay_ms ; wait
call led_off
movlw 0x32 ; 50 milliseconds
call delay_ms ; wait
call led_on
movlw 0x32 ; 50 milliseconds
call delay_ms ; wait
call led_off
movlw 0x32 ; 50 milliseconds
call delay_ms ; wait
call flash
; mark end in EEPROM with 'BB'
movlw 0xBB ; end marker
movwf dat ; prepare for EEPROM
call ewrite ; write to EEPROM
BANK0
incf addr,1 ; add 1 to address
sleep

;***** Include routines *****************************
include "delays.inc"
include "eeprom_write.inc"

end
================== ASM =================

2012\01\05@152107 by Djula Djarmati

flavicon
On 05-Jan-12 21:00, Adam Walley wrote:
> Here is the code I am using with the MPLAB IDE v8.33
> Sorry for any bad formatting. The code is very crude because I am still
> testing and debugging (that is also why there is an eeprom write and the
> flashing LEDs - these confirm that my code has run).
>
> ================== ASM ==================
>
> ;12F675 send 'K' byte to PC via RS232 (GPIO1)
> ; as basic as possible to test correct code format
> ;
>
>
> #include<p12f675.inc>
> errorlevel  -302               ; suppress message 302 from list file
>
> __CONFIG  _CP_OFF&  _WDT_OFF&  _BODEN_OFF&  _PWRTE_OFF&
> _INTRC_OSC_NOCLKOUT&  _MCLRE_ON&  _CPD_OFF

Your problem is _MCLRE_ON. This connects the internal reset circuitry to external pin #4 which is floating.

When you use battery power, your power supply is noise free and this floating input stays at logic level 1 (which is pure luck).

As soon as you connect the ground wire, your device starts to receive more RF noise and this changes the MCLR logic level randomly and resets the chip repeatedly.

Use _MCLRE_OFF or connect your reset pin #4 to Vcc through a resistor.

Djula



{Quote hidden}

> ================== ASM =================

2012\01\05@161536 by Adam Walley

picon face
This is great! Thanks for pointing out the issue in my code - I am still
learning.
I will correct it and post back with results tomorrow.

P.S. The letter being sent should be 'T', not 'K'

2012\01\05@171819 by IVP

face picon face
> MCLR. I have read information from various sources, with
> some suggesting pins should be grounded if not used

There's no need, and it's inadvisable, to hard ground any pin that's
not being used. Simply TRIS it to output and leave it unconnected

Plenty of good advice here

http://www.piclist.com/techref/logic/xtrapins.htm

> _MCLRE_ON

If this is in the CONFIG, connect MCLR to Vdd. With a 10k resistor
if you want to reset the PIC manually

Or change it to _MCLR_OFF. This disconnects the pin from the
internal reset circuitry and allows use of the pin as GP3

> Is there anything I can add to protect the chip from unwanted negative
> voltage?

The signal line(s) will be protected from the PC port by the MAX.
0.04V difference between points on a ground line isn't much of a
concern in this situation. The danger point for I/O is -0.6V, which is
when the internal protection diodes will start conducting. A simple
solution is to add a Schottky (A to Vss, K to pin). This will start
conducting at 0.3

2012\01\05@193323 by Jan-Erik Soderholm

face picon face
IVP wrote 2012-01-05 23:18:
> Or change it to _MCLR_OFF. This disconnects the pin from the
> internal reset circuitry and allows use of the pin as GP3
>

Whithout knowing (or remembering :-) ) that he has a programmer
capable of re-progremming a PIC with internal MCLR on, it might
be a better advice to simply add a 10k resistor to the MCLR pin.

IVP (did not) wrote 2012-01-05 23:18:
>> Is there anything I can add to protect the chip from unwanted negative
>> voltage?
>

The first thing is to make sure you never have any negative
voltages at the PIC pins

2012\01\06@033422 by William \Chops\ Westfield

face picon face
>> Is there anything I can add to protect the chip from unwanted negative voltage?

Well, to start with, there should be a substantial resistor; about 10k.
This will rely on the internal protection diodes to clamp the voltages to levels that won't cause problems.  There is plenty of reason to assume that this is insufficient, but microchip does publish app notes where this is done (apparently successfully.)

Um, you know, the RX input of the PC ought to be a high impedance input, without providing any dangerous currents to the PIC.  Are you sure you have the correct pin connected?  You shouldn't see -9.6V on the receive pin; it should be floating...
It ought to be sending data in the other direction that causes problems.

The other thing I've seen is getting the connector wiring wrong, and using DCD as GND and DTR as RxD (to mention the most likely error on a DB9 connector.)  Make sure that the signals you are using are the ones you think you're using.   A "breakout board" is valuable:  http://www.flickr.com/photos/58843278@N00/6645963575/  An LED/resistor connected between GND and the PC's RX signal should NOT light up in either direction!

BillW

2012\01\06@042013 by Isaac Marino Bavaresco

flavicon
face
Em 06/01/2012 06:34, William "Chops" Westfield escreveu:
>>> Is there anything I can add to protect the chip from unwanted negative voltage?
> Well, to start with, there should be a substantial resistor; about 10k.
> This will rely on the internal protection diodes to clamp the voltages to levels that won't cause problems.  There is plenty of reason to assume that this is insufficient, but microchip does publish app notes where this is done (apparently successfully.)
> ...


I prefer to use an external Zener diode plus two resistors to clamp the
voltages, forming a "T" with the Zener as the "leg" of the "T".

Isaac

2012\01\06@043422 by cdb

flavicon
face
I was wondering there might be an earth differential, that is the laptop earth is higher than the gadgets, though only if the laptop was being run from the mains.

Colin

--
cdb, colinspamspam_OUTbtech-online.co.uk on 6/01/2012
Web presence: http://www.btech-online.co.uk   Hosted by:  http://www.justhost.com.au
 This email is to be considered private if addressed to a named  individual or Personnel Department, and public if addressed to a blog,  forum or news article.

2012\01\06@061248 by Adam Walley

picon face
Ok. I ran some tests and confirmed that the MCLR pin was indeed resetting
the code, suggesting that the added noise caused by connecting the ground
wire from the PC (or pretty much anything) was preventing the PIC from
operating correctly. Lesson learned.

I have re-programmed the chip with the _MCLRE_OFF statement in my config. I
am now making progress as I am getting a character received on
hyperterminal. Admittedly not the right one, but this is almost certainly
down to timing and fine-tuning my code. I may drop the baud down to 2400
before trying to push it back up.

Thanks again to all, who have helped

2012\01\06@072618 by Byron Jeff

flavicon
face
On Fri, Jan 06, 2012 at 07:20:08AM -0200, Isaac Marino Bavaresco wrote:
> Em 06/01/2012 06:34, William "Chops" Westfield escreveu:
> >>> Is there anything I can add to protect the chip from unwanted negative voltage?
> > Well, to start with, there should be a substantial resistor; about 10k.
> > This will rely on the internal protection diodes to clamp the voltages to levels that won't cause problems.  There is plenty of reason to assume that this is insufficient, but microchip does publish app notes where this is done (apparently successfully.)
> > ...
>
>
> I prefer to use an external Zener diode plus two resistors to clamp the
> voltages, forming a "T" with the Zener as the "leg" of the "T".

What's the purpose of the resistor between the zener and the PIC input? For
quick and dirty testing, I use a 4.7K resistor in series with the RS-232
output and a 4.7V zener. For more permanent circuits I use this as the base
input to a NPN transistor inverter with a pullup resistor to protect the
PIC's input from the -0.7V the zener allows when the RS-232 output swings
negative.

The last time this discussion came up, Russel noted to me that allowing the
negative voltage to the PIC input, even though it's clamped by the
protection diodes, causes the part to operate outside of it's range
specified in the datasheet (-0.3V minimum). Hence the transistor in the
permanent circuit. I'm unsure what if any damage that 150 uA of current at
-0.7V can do to the input.

BAJ

>
> Isaac
>
> -

2012\01\06@080026 by Isaac Marino Bavaresco

flavicon
face
Em 6/1/2012 10:26, Byron Jeff escreveu:
> On Fri, Jan 06, 2012 at 07:20:08AM -0200, Isaac Marino Bavaresco wrote:
>> Em 06/01/2012 06:34, William "Chops" Westfield escreveu:
>>>>> Is there anything I can add to protect the chip from unwanted negative voltage?
>>> Well, to start with, there should be a substantial resistor; about 10k.
>>> This will rely on the internal protection diodes to clamp the voltages to levels that won't cause problems.  There is plenty of reason to assume that this is insufficient, but microchip does publish app notes where this is done (apparently successfully.)
>>> ...
>>
>> I prefer to use an external Zener diode plus two resistors to clamp the
>> voltages, forming a "T" with the Zener as the "leg" of the "T".
> What's the purpose of the resistor between the zener and the PIC input?


If the RS-232 is connected when the PIC is not powered, the pin will
have 4.7V and the board will be powered by the PIC's internal parasitic
diode and large currents may flow through it, perhaps violating some
parameter.
With the additional resistor (say 1K) the current will be limited to a
few mA, well inside the allowed range.


>  For
> quick and dirty testing, I use a 4.7K resistor in series with the RS-232
> output and a 4.7V zener. For more permanent circuits I use this as the base
> input to a NPN transistor inverter with a pullup resistor to protect the
> PIC's input from the -0.7V the zener allows when the RS-232 output swings
> negative.


When using an NPN transistor I use a small signal diode from ground to
base to protect the base-emitter junction from reverse biasing. The PIC
will never see the -0.7V because the base-collector junction will be
reverse biased, but the transistor's base-emitter junction may be
damaged as they are usually rated for -5V.


Best regards,

Isaac


> The last time this discussion came up, Russel noted to me that allowing the
> negative voltage to the PIC input, even though it's clamped by the
> protection diodes, causes the part to operate outside of it's range
> specified in the datasheet (-0.3V minimum). Hence the transistor in the
> permanent circuit. I'm unsure what if any damage that 150 uA of current at
> -0.7V can do to the input.
>
> BAJ
>

2012\01\06@092817 by Byron Jeff

flavicon
face
On Fri, Jan 06, 2012 at 11:00:23AM -0200, Isaac Marino Bavaresco wrote:
> Em 6/1/2012 10:26, Byron Jeff escreveu:
> > On Fri, Jan 06, 2012 at 07:20:08AM -0200, Isaac Marino Bavaresco wrote:
> >> Em 06/01/2012 06:34, William "Chops" Westfield escreveu:
> >>>>> Is there anything I can add to protect the chip from unwanted negative voltage?
> >>> Well, to start with, there should be a substantial resistor; about 10k.
> >>> This will rely on the internal protection diodes to clamp the voltages to levels that won't cause problems.  There is plenty of reason to assume that this is insufficient, but microchip does publish app notes where this is done (apparently successfully.)
> >>> ...
> >>
> >> I prefer to use an external Zener diode plus two resistors to clamp the
> >> voltages, forming a "T" with the Zener as the "leg" of the "T".
> > What's the purpose of the resistor between the zener and the PIC input?
>
>
> If the RS-232 is connected when the PIC is not powered, the pin will
> have 4.7V and the board will be powered by the PIC's internal parasitic
> diode and large currents may flow through it, perhaps violating some
> parameter.

The series resistor will limit the incoming current. With a 4.7V zener and
a 4.7K series resistor, the maximum current the unpowered PIC will see is 1
mA. All the rest of current from the higher incoming voltage will be
shunted to ground by the zener.

{Quote hidden}

The zener serves the purpose of that small signal diode with the input
voltage is negative as the zener is now forward biased. So the base-emitter
voltage is never more that -0.7V which is nowhere near the reverse bias
breakdown voltage for the transistor.

I haven't had any problems so far, and it's a heck of a lot easier than
trying to track down a MAX232 or equivalent. I haven't seen a USB serial
adapter yet that swings any more than +/- 5V, and every one so far works
fine with 0-5V going into their inputs. With the near universal death of
dedicated serial and parallel ports on PC's, USB serial adapters are my
current bit wiggling interface.

BAJ

{Quote hidden}

> -

2012\01\06@105344 by Dwayne Reid

flavicon
face
At 05:26 AM 1/6/2012, Byron Jeff wrote:

>The last time this discussion came up, Russel noted to me that allowing the
>negative voltage to the PIC input, even though it's clamped by the
>protection diodes, causes the part to operate outside of it's range
>specified in the datasheet (-0.3V minimum). Hence the transistor in the
>permanent circuit. I'm unsure what if any damage that 150 uA of current at
>-0.7V can do to the input.

I don't believe that any damage could ever occur at that current level, but there is a really GOOD chance that any analog functions (a/d, comparitor) could be affected.  I can confirm this DOES happen on earlier PICs (16c73) - I don't know if more modern PICs are affected by substrate currents because I learned my lesson way back then and simply don't allow any substrate currents at all.

Yeah - that does mean a bit of extra care when interfacing with signals that might swing below ground but its just not worth the hassle trying to figure out why your a/d readings are so messed up, or whatever.

dwayne

-- Dwayne Reid   <@spam@dwaynerKILLspamspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax
http://www.trinity-electronics.com
Custom Electronics Design and Manufacturing

2012\01\06@113430 by Spehro Pefhany

picon face
At 08:00 AM 06/01/2012, you wrote:

>When using an NPN transistor I use a small signal diode from ground to
>base to protect the base-emitter junction from reverse biasing. The PIC
>will never see the -0.7V because the base-collector junction will be
>reverse biased, but the transistor's base-emitter junction may be
>damaged as they are usually rated for -5V.

I guess if you like to live dangerously you could do this and
save a part:


                          Vdd o
                              |
                             .-.
                             | |
                         30K | |
                             '-'
                              |          Out
                              +-----------o
                              |
                     ___    |>
              In  o-|___|- -|
                            |\  NPN
                   4.7K       |
                              |
                             ===
                             GND


Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
KILLspamspeffKILLspamspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

2012\01\06@122251 by Isaac Marino Bavaresco

flavicon
face
Em 6/1/2012 12:28, Byron Jeff escreveu:
{Quote hidden}

If I understand it right, you use a resistor with one terminal connected
to the PC's RS-232 TX and its other terminal connected the the zener
cathode AND to the pin of the PIC, right?

In this scenario your circuit may clamp the voltage below the zener
voltage and all the current will flow through the PIC's internal diode.
If the resistor is connected to a higher voltage then the current may be
much higher than your figures.

Remember, the current through a resistor is proportional to the
difference of voltage between its two terminals. The only thing you are
guaranteeing is that the PIC's side terminal will never be higher than
4.7V (probably), but you cannot control the voltage on the other side.


{Quote hidden}

My point is that in this situation the small signal diode will work the
same way as the zener, both will be forward biased and the base voltage
will never be less than -0.7V (or close to this). When the voltage on
the base is positive, the base-emitter junction will be forward biased
and the zener will never conduct, thus the use of a zener or a small
signal diode is indifferent. The advantage of the small signal diode is
that it may have a much lower capacitance, making switching faster.


Isaac


{Quote hidden}

>> --

2012\01\06@123207 by Isaac Marino Bavaresco

flavicon
face
Em 6/1/2012 14:30, Spehro Pefhany escreveu:
{Quote hidden}

Is your emitter connected to the output and collector to ground? By
swapping collector with emitter you bet on the base-collector junction
being able to withstand the negative voltage?

This is even worse because the base-emitter junction now will be reverse
biased by Vdd-Vin Volts (an even more negative voltage).

Also, remember that although a transistor in this configuration may
work, its gain is WAAAAY lower than in the normal configuration.


Isaac

2012\01\06@130733 by Isaac Marino Bavaresco

flavicon
face




Point A is the input, point C is connected to the PIC.

V(A) may be any voltage;
-0.7V <= V(B) <= Vz (if zener parameters not violated);
-0.7V <= V(C) <= Vcc (if Vz < Vcc).

Current through R1 may be any value.
Current through R2 will be between -((Vcc+0.7)/R2) and (Vz/R2).


With good values chosen for the resistance of R1 and the power of zener,
point A may be connected to mains and the only damage would be R1 burned.


Best regards,

Isaac




Em 6/1/2012 12:28, Byron Jeff escreveu:
{Quote hidden}

>> --

2012\01\06@132354 by Isaac Marino Bavaresco

flavicon
face
Oops! Circuit didn't show. Trying again...




Em 6/1/2012 16:07, Isaac Marino Bavaresco escreveu:
{Quote hidden}

>>> --

2012\01\06@133052 by Spehro Pefhany

picon face
At 12:31 PM 06/01/2012, you wrote:

>Is your emitter connected to the output and collector to ground? By
>swapping collector with emitter you bet on the base-collector junction
>being able to withstand the negative voltage?
>This is even worse because the base-emitter junction now will be reverse
>biased by Vdd-Vin Volts (an even more negative voltage).

I did say it was dangerous. It will likely zener that junction,
but I suspect that does not lead to a permanent reduction in
_reverse_ beta. It will draw some current from the power supply.

>Also, remember that although a transistor in this configuration may
>work, its gain is WAAAAY lower than in the normal configuration.

It should be more than 1 though, (and the saturation voltage is
actually lower in the reverse active region), so a 5:1 ratio
in resistors should be safe, given a minimum input not much
less than Vdd.

Best regards,

2012\01\06@134557 by Isaac Marino Bavaresco

flavicon
face
part 1 4837 bytes content-type:text/plain; charset="iso-8859-1" (decoded quoted-printable)

Trying once more, this time an attached JPG.


Em 6/1/2012 16:07, Isaac Marino Bavaresco escreveu:
{Quote hidden}

>>> --

2012\01\06@140351 by Byron Jeff

flavicon
face
It's days like this I need to remember that I'm a computer scientist, not
an electrical engineer.

On Fri, Jan 06, 2012 at 03:22:48PM -0200, Isaac Marino Bavaresco wrote:
{Quote hidden}

I'm trying to work this through but I keep confusing myself. Let's share an
example so that maybe I can lift the fog. Take a look at this simple zener
regulator:

http://en.wikipedia.org/wiki/Linear_regulator#Simple_Zener_regulator

Fundamentally it's a resistor voltage divider with the zener as a shunt
between the two resistors. In operation R1, the top resistor, limits the
total current coming from the source, and the zener shunts current to keep
the midpoint between the two resistors at the zener voltage. The way I've
always thought about this circuit is that VS/R1 is the amount of current
available to the zener and R2, and that since the zener is forcing the
voltage between the two to the zener voltage, that the amount of current
through R2 is fixed.

But I'm realizing from your discussion that's only the case if R2 is fixed.
If R2 is variable, then if it can accept more current, then it will
regardless of the zener. Let me clarify with some numbers:

VS = 14.1V (3 * 4.7V)
R1 = 4.7k
DZ = 4.7V
R2 = variable

The current available from R1 is 14.1V/4.7k = 3 mA. Now my (mistaken)
thinking is that the zener would shunt 2 mA of that current and that a
4.7V/4.7K = 1mA supply would be available to R2.

But that's only the case if the original voltage divider of R1/R2 develops
a voltage above the knee of the zener, such as if R2 is not present. But if
R2 is a dead short of 0 ohms, then it would draw all 3 mA across it and the
zener would shunt no current since the voltage divider is 0V at the R1/R2
junction. That's the part I didn't see.

So if R2 is the PIC, and it can draw 3 mA of power, it could certainly be
powered through its inputs.

So your T circuit splits R2 with a second resistor, say R2A and R2B and
puts the zener between R1 and R2A which limits current to 1 mA.

Makes sense now.

>
> Remember, the current through a resistor is proportional to the
> difference of voltage between its two terminals. The only thing you are
> guaranteeing is that the PIC's side terminal will never be higher than
> 4.7V (probably), but you cannot control the voltage on the other side.

But by added the second resistor, it guarantees enough resistance that R2
in total cannot sink all the current.

>
>
> >
> >> With the additional resistor (say 1K) the current will be limited to a
> >> few mA, well inside the allowed range.

In my example R2A would need to high enough to force the R1/R2A junction to
br 4.7V or higher so that the zener kicks in. So for example a second 4.7K
resistor creates a half voltage divider to 7V, the zener would lower the
voltage to 4.7V and the maximum current would be 4.7V/4.7K = 1 mA even if
the PIC (R2B) is a dead short.

{Quote hidden}

Got it. So a zener in a T configuration, or no zener, but a signal diode
instead, with the transistor.

BAJ

{Quote hidden}

2012\01\06@143020 by Isaac Marino Bavaresco

flavicon
face
Congratulations,


Your explanation is very detailed and much more elaborated than mine.


Best regards,

Isaac



Em 6/1/2012 17:03, Byron Jeff escreveu:
{Quote hidden}

2012\01\06@180843 by IVP

face picon face
> on earlier PICs (16c73) - I don't know if more modern PICs
> are affected by substrate currents because I learned my lesson
> way back then and simply don't allow any substrate currents at
> all

IME analogue inputs are fairly fragile. I've seen it on older PICs
like the 16F877 and recently had to modify someone's design in
which a dsPIC's ADC input was taken out twice by a ground
disturbance when another device using the PSU was turned o

2012\01\06@184543 by Jan-Erik Soderholm

face picon face


cdb wrote 2012-01-06 10:34:
> I was wondering there might be an earth differential, that is the laptop
> earth is higher than the gadgets, though only if the laptop was being run
> from the mains.
>

Probably not, since the PIC run on batteries.



{Quote hidden}

2012\01\06@184734 by Jan-Erik Soderholm

face picon face


Adam Walley wrote 2012-01-06 12:12:
> Ok. I ran some tests and confirmed that the MCLR pin was indeed resetting
> the code,

How ?
It does sound as if you do not have any MCRL pullup resistor !?


> suggesting that the added noise caused by connecting the ground
> wire from the PC (or pretty much anything) was preventing the PIC from
> operating correctly. Lesson learned.
>

Not sure...

> I have re-programmed the chip with the _MCLRE_OFF statement in my config.

Note that Microship still recomends an external pullup. At least in
the 16F690 datasheet.

2012\01\06@210000 by Djula Djarmati

flavicon
On 07-Jan-12 00:47, Jan-Erik Soderholm wrote:
>
>
> Adam Walley wrote 2012-01-06 12:12:
>> Ok. I ran some tests and confirmed that the MCLR pin was indeed resetting
>> the code,
>
> How ?
> It does sound as if you do not have any MCRL pullup resistor !?

Yes, there is clearly no pull up on his schematic which shouldn't be a problem if he is using internal MCLR.

{Quote hidden}

I can't find that in my 41262a.pdf datasheet, can you please say where they recommend that?
I can only find where they advise against connecting external MCLR to Vcc directly due to external MCLR being very sensitive to overvoltage.

Djul

2012\01\06@212457 by Djula Djarmati

flavicon


On 07-Jan-12 03:00, Djula Djarmati wrote:
{Quote hidden}

I just realized what you mean, the problem in leaving MCLR input floating is that despite turning MCLRE off, high voltage spikes on floating MCLR could disrupt normal operation by i.e. inadvertently entering programing mode.

So Adam, you should definitively connect the MCLR pin through a resistor to GND or Vcc and not leave it floating. You can set other pins as output in code so thay are not floating either.

Djul

2012\01\07@082126 by Jan-Erik Soderholm

face picon face
Djula Djarmati wrote 2012-01-07 03:25:
>
>
> On 07-Jan-12 03:00, Djula Djarmati wrote:
>> On 07-Jan-12 00:47, Jan-Erik Soderholm wrote:
>>>
>>>
>>> Adam Walley wrote 2012-01-06 12:12:
>>>> Ok. I ran some tests and confirmed that the MCLR pin was indeed resetting
>>>> the code,
>>>
>>> How ?
>>> It does sound as if you do not have any MCRL pullup resistor !?
>>
>> Yes, there is clearly no pull up on his schematic which shouldn't be a
>> problem if he is using internal MCLR.
>>

Yes. My point was that setting "internal MCLR" could have other
side-effects when re-programming the chip. We (at least I) do not know
if he has a programmer capable of handling that ("Vpp-before-Vdd).
My general tip if one does not absolutely need the MCLR pin as
an extra input pin, is to simply leave it as an external MCLR pin.
One less thing to worry about.

{Quote hidden}

Yes, that whas what I was thinking about. So "internal MCLR" does not
generaly save componenets, it does give one extra input pin, if you
realy need that.

Jan-Erik

More... (looser matching)
- Last day of these posts
- In 2012 , 2013 only
- Today
- New search...