PDA

View Full Version : What is causing my problem?



BobK
- 11th July 2022, 11:59
Hello all!
It’s been a long time since I’ve posted here but I’ve still stayed in touch. I just made a project using a 16F87 and set 2
Outputs to 0 and I am getting voltage out of the pin that’s enough to turn the output transistors on. Can anybody give me a reason why a zero on a pin is not a zero? The original project I made back in 2005 was done with a 16F84a and is suppose to be pin compatible with the F87. The original project still works fine but I need another. Help, please!
Thank you, BobK

Jerson
- 11th July 2022, 12:10
Is it possible you did not set the TRISx register (where x is the port name) ? Perhaps the pin is an analog one by default and you haven't configured it for digital use?

these are what I can think of just now.

BobK
- 11th July 2022, 12:23
Thank you for the fast reply, Jerson.
I have 2 inputs on port A and the Tris A is =00000011 and the outputs are on port B and the Tris B is =00000000. I have the comparators disabled with CMCON = 7. Is there something missing here? Thank you!
BobK.

tumbleweed
- 11th July 2022, 13:54
... set outputs to 0 and I am getting voltage out of the pin that’s enough to turn the output transistors on.
What voltage are you measuring? Which PORTB pins are you using?

Jerson
- 11th July 2022, 14:06
Related to PORTB, I can see that only the ANSEL register is different.

I have some doubt if the ANSEL needs to be set to 0 on this chip.

If that does not help, then perhaps you can try by disconnecting the driven load and check if the outputs are following your code intent.

tumbleweed
- 11th July 2022, 14:27
PORTB has no analog functions on the 16F87.

Have you disabled the WDT?

BobK
- 11th July 2022, 15:37
No I did not disable the WDT. Is that necessary?

tumbleweed
- 11th July 2022, 16:00
If you don't disable it you'll be getting resets when the wdt times out.
That'll set the pins as inputs, so they'll be floating instead of low.

HenrikOlsson
- 11th July 2022, 18:57
For trouble shooting purposes, sure try disabling it but I'd be very surprised if has any impact on the issue.
Generally speaking, you don't need to disable the WDT. Unless you're code includes the line DEFINE NO_CLRWDT 1 PBP adds code to reset it periodically so it should not time out during execution.
If the WDT does time out and resets the PIC then yes, the TRIS bits gets set back to 1 but the code starts to execute from the beginning where one usually has it's initialization code to, for example, clear TRIS. In that case, yes, the pins does float but only until the the uC executes the TRISB = 0 again.

As have been suggested, disconnect the load from the I/O pin and measure the voltage on the pin and on whatever connects to the pin (which is now floating).

Post a schematic of the circuit and the shortest piece of code you can come up with that still shows the issue.

mpgmike
- 11th July 2022, 20:32
I had a similar experience with some PIC18F45K22 dip-40 parts I had laying around for many years. I couldn't get clean digital outputs to the point where things didn't work properly. After spending way too much time trying different things, I swapped in a K40 part and it worked perfectly. I therefore concluded that the K22 parts were defective. Now, were they defective when I bought them about a decade ago, or did they "rust" sitting in a drawer that long?