I/o problem

Status
Not open for further replies.
WHOA WAIT A MINUTE!!!

First off...OUTPUTS cannot be externally controlled. Their output state is controlled INTERNALLY. However, pins that are set up as INPUTS are externally controlled. We READ inputs, but we WRITE to outputs.

PIC can provide max source of 25mA right? If I connect very small resistance (e.g. 1 Ohms), pic will have to change output voltage to 25mV in order to privide 25mA right?

No! Using a 1 ohm resistor between a PIC output pin and ground will overload the port pin and possibly either burn out the pin or the PIC itself! A straight wire from the pin to ground will do the same! When a pin is configured as an INPUT, you can ground it out all day long, but ground out a pin that is set up as an output and you're going to burn up the PIC. You only get 2 voltage values from a PIC OUTPUT...5V and 0V. PERIOD! End of story!

You are thinking completely backwards. The PIC can source 25mA @ 5V output. Using Ohm's Law, this means that the pin can safely drive loads down to 200R (5V / 25mA = 200R....simple Ohm's Law).
There is no "forcing output pins to a different output voltage". Output pins get toggled between the Vdd and Vss pins internally, which will only provide two possible output voltages...5V and 0V. Using anything lower than 200R on an OUTPUT pin will burn up the chip. If you're pulling the pin voltage down lower than 5V when setting the output pin high, this means that you are overloading the pin.

and when it happens and I read bit during it, will it read the latch value which I wroti in with bsf? as diagram shows form datasheet, it will read 25mV, which means 0 right? and if It's so, than everything works fine, I mean, that's normal action

No...you're doing something completely wrong here.

If you want to be able to see if the pin is going to 1 or 0, put an LED in series with a 330R resistor between the pins and ground. They will give you a visual indication of what the pins are doing.

Can you explain in normal terms what you're trying to get the PIC to do? Cause from the sounds of it you're needing something with an on chip AD converter, which the F628A does not have.

Now since you wanted RA5 configured as digital input, I modified the config word in my last code posting. Please recopy, paste then assemble and the code should be correct. Wire up a couple of LED's with a 330R resistor in series with each LED, then place them on pins RA7 and RA0 and they should both come on.

Code:
	        list		p=16F628A, r=dec, w=1
		include		<P16F628A.INC>
		__config	b'10000100010000'
 
		org		0x000		;reset vector
		goto		START
 
START		movlw		0x07		;disable comparator
		movwf		CMCON
		clrf		PORTA		;init ports
		clrf		PORTB
		banksel		TRISA		;bank 1
		clrf		TRISA		;RA0-RA7 outputs
		movlw		b'00000001'	;RB1 input
		movwf		TRISB
		banksel		PORTA		;bank 0
 
		bsf		PORTA,7		;RA7 high
		btfsc		PORTA,7		;is RA7 low?
		bsf		PORTA,0		;no, set RA0
		goto		$	
		
		end
 
Last edited:
no no I was trying to do completely different thing. thank you very much for explaining, I used to connect LED directly to PIC output and seems like it caused the problem. I don't understand well what's happening inside chip, so I decided reading appropriate book and will only continue with PIC after finishing it. Thanks again
 
OK it's very simple.

When the PIC output is set high, the output voltage is 5V. This does not change with load resistance. The output CURRENT on the other hand changes with the load resistance that the output pin is driving. But the voltage is always 5V when the output pin is set high.

The 25mA rating is a MAXIMUM rating. Meaning that if you're driving a load that is greater than 200 ohms, your output current will be less than the rated maximum but the output voltage will still be 5V.

The way you're thinking is that the output current is always 25mA and the output voltage changes with load resistance, and 25mA x 1R = 25mV. But this is backwards. The output voltage is ALWAYS 5V on an output pin that gets set high. There is no way to change this. But the current output changes depending on load resistance and the 25mA maximum means that the lowest load you can drive is 200 ohms because 5V / 25mA = 200 ohms.

An LED with a 330R resistor in series with it will only draw 9mA from the output pin. This is because 2V of the 5V output voltage is across the LED, leaving the remaining 3V across the 330R resistor. 3V across a 330R resistor translates to 9mA -

3V / 330R = 9mA

Since the pin is capable of sourcing well above 9mA, it is totally safe to drive an LED with a 330R resistor in series with it. If you had the LED set up in this fashion, then the LED could not have damaged your PIC.

Does this make sense?
 
Last edited:
I understood, I got it, but when I measure voltage when directly connecting LED to output without resistance, voltage was 1.99v which is nor 5 not 0. I know that it's harmfull, it will burn out the chip and It's called pin overloading. thanks
 
Yes that is because LEDs act as a voltage "clamp". They will have a 2V drop across them regardless of voltage. When hooking them up with no resistor to a voltage source that is greater than 2V (such as a PIC output pin), it will draw enough current from the source to load the source output down to 2V, which is way more current than the supply can source as well as way more current than the LED can handle (anytime you hook up a load to a voltage source that pulls the source voltage down you are overloading the source, which is the cause of the voltage being pulled down).

This is why a current limiting resistor is needed in series with the LED...to take up the remaining 3V plus to limit how much current the LED can draw to keep from overloading the pin. You were drawing too much current from the pin.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…