high impedance toggle

Status
Not open for further replies.

patroclus

New Member
Hello,
If I set pull up resistors in port b, can I just toggle from 5V to ground by setting port bit to 0, and toggle trisb ??

When bit set in trisb, it is an input, high impedance and pull up resistors makes 5V.
When bit clear in trisb, it is an output, and as portb holded 0, it is grounded.

Is this correct??
 

Yes, in fact my I2C tutorial does exactly that - but with external pull-ups. Are the internal pull-ups low enough?, I'm presuming that's what you are intending?.
 
I don't know if they are.
In fact, they are not resistors but MOS transistors I think.
Which resistor value can I suppose for them??
In a previos test circuit controlled by parallel port instead of PIC, I used 4.7k resistors and it worked great.
 
patroclus said:
I don't know if they are.
In fact, they are not resistors but MOS transistors I think.
Which resistor value can I suppose for them??
In a previos test circuit controlled by parallel port instead of PIC, I used 4.7k resistors and it worked great.

Use those then, the internal pullups are high, usually considered as something like 600,000 ohms - I never considered using them for I2C, they are FAR too high.
 
I've got a problem now..
I just programmed my 16F628, using internal clock.
I don't know if I'm making something wrong, since it's been a year since I don't use PIC.

I conected
Vss to GND
Vcc to 4.5V
MCLR to Vcc

And that's it.
It is suppose to do some filtering routines with RB0 and RB1 pins.
I used my logic analyzer, and I get all port pins toggling with no sense, and the program is not working. After some time, ports pin stop toggling, and that's it...
I verified twice that the program is correct, by reading PIC.

Am I missing something??
 

Well, it's not Vcc, it's Vdd (as it's a CMOS chip) - but obviously that won't have any effect!.

But the connections sound fine, as long as the usual proper precautions are taken - suitable decouplers etc. I suspect it's more likely a bug in your program?.
 
I don't thnik so, because everytime I turn it on, I get different behaivours from the PIC. Never the same!
I didn't use cap, I'm gonna try 100nF and 1uF caps, but I don't think that will work..
 
Nigel Goodwin said:
Use those then, the internal pullups are high, usually considered as something like 600,000 ohms - I never considered using them for I2C, they are FAR too high.

The 16F628 datasheet gives the pull up resistor typical current as 200uA.

At 5V that works out to be 25K.
 
Ok I see.
At the begining, when power on, the lines are unstable until the PIC finally starts working. It takes about 1.3 ms (sometimes even 4.5ms) as measured with my logic analyzer.
From that on, it starts working.
 
I assume trisb = tri-state buffer.

I say Yes too.

In your case, you defined the default logic level for port b as logic high. In other words, without user input, port B = all bits are 1.
Anything (VCC or Ground) connected to any input at port B will override the default level.

For example: if a resistor is connected from +ve to the port input, and a wire is connected from the port input to ground, then the default level of 1 is overrided with a logic level of 0, because the resistance coming from ground is lower.
 
patroclus said:
Hello,
When bit set in trisb, it is an input, high impedance and pull up resistors makes 5V.
When bit clear in trisb, it is an output, and as portb holded 0, it is grounded.

This will work but there is a hidden flaw which you should be aware of. If you use the above scenario on PortB bit 0 and it is set to input then any write to the port will set the output latch to logic high and it will subsequently be high when set to output. This is because any write is a read modify write command. Therefore, bsf PortB,7 will still set bit 0 (or any other input with a pullup resistor) to 1.

Hope that makes sense!

Mike.
 

I don't think it works like that?, the read/write/modify reads the output buffer, and NOT the input pin - so it works OK.
 
Nigel Goodwin said:
I don't think it works like that?, the read/write/modify reads the output buffer, and NOT the input pin - so it works OK.

When you read a pin that is an input then it reads the pin otherwise it wouldn't be an input. When you write to a pin it writes to the data latch and therefore writes back what it sees on the input.

Just to be sure I tried the following.

Code:
                bcf     PORTB,7;        set bit 7 to 0
                bsf     STATUS,RP0
                bsf     TRISB,7;        set bit 7 to input
                bcf     STATUS,RP0
                bsf     PORTB,0;        alter another bit
                bsf     STATUS,RP0
                bcf     TRISB,7;        set bit 7 to output
                bcf     STATUS,RP0

After executing the above bit 7 was high. If you remove the bsf PORTB,0 then bit 7 remains low.

Mike.
P.S.I just had a look and section 5.3.1 of the 16F628 data sheet explains it.
 
Nigel Goodwin said:
I don't think it works like that?, the read/write/modify reads the output buffer, and NOT the input pin - so it works OK.

You're assuming they are actually work like that?, but (from what you've said) you don't actually know it, and have never tried it?.

And BTW, they are called read/modify/write instructions and not read/write/ modify as you have put it.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…