pic pins are not all the same - Page 1
Forum section: electronics / beginners

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 17, 2016, 12:49:37 am
content: Gidday again.A small problem understanding input on a PIC.To be precise PIC16F84A-20/P. date code or batch code 04472GHDon't laugh at my choice of chip. I acquired a couple a few years ago and decided to start doing something with PICs.I'm a newbie and have had several posts before and will likely have a few more.I have designed a PCB for the PIC16F877A and it works fine.The rest of the project will require more PCB's and programming digital and Analog inputs when I can figure Analog out.I may have to ask for help on this as well.A smaller project came to mind while working on the main project and I have been sidetracked for a few days designing a PCB and programming.The project requires 4 inputs to replace LEDs in another project.The LEDs only indicate connected or not connected state of 4 USB ports that are being switched.Back to my quary. The PIC16F84A-20/P project.To drive the inputs, I intend to use 4n35 opto-couplers on each input.I am using ports RA0, RA1, RA2, RA3 configured as input// DEFINING PORT A FOR I/O#define FAULT_0 RA0 // input port#define FAULT_1 RA1 // input port#define FAULT_2 RA2 // input port#define FAULT_3 RA3 // input port// END OF PORT A DEFINITIONSin the MAIN VOID ROUTINETRISA = 0b11110; // RA0 - RA3 = INPUTS. RA4 = OUTPUTI have tested 2 chips, both PIC16F84A, the problem is this.RA0 wouldn't work but the other three do.I started measuring voltages and currents and found something a little strange as can be seen in the tables below.CHIP # 1 CURRENT - PIN RAx TO GROUND RESISTOR RESISTOR470 OHMS 235 OHMSRA0 2.5mA 3.76V 1.703VRA1 507uA 100.5mV 83.3mVRA2 508uA 100.6mV 83.4mVRA3 508uA 101.2mV 83.2mVCHIP # 2 CURRENT - PIN RAx TO GROUND RESISTOR RESISTOR470 OHMS 235 OHMSRA0 .5 - .7 mA fluctuating 3.579V 1.5VRA1 500uA = .5mA 52.1mV 34.0mVRA2 500uA = .5mA 51.7mV 34.1mVRA3 500uA = .5mA 51.5mV 34.0mVWhat is causing RA0 to draw so much current but it is unable to get the voltage near enough to ground to switch on.I can fix the problem by creating a Darlington Pair Transistor by adding a BC547 to the opto-coupler output but why is there this difference between pins?Why also the difference between two PIC16F84A from the same batch as far as I know.I understand that not all pins in a port are exactly the same, i.e. have alternate functions, but if it is configured as input, why be a different kind of input?I await a few words of wisdomand thank you for your patience.I will be going to work in a couple of hours and don't get home til 1:00 AM so will look at replies when I can.BILL.

author: Monkeh
author_rank: Super Contributor
timestamp: August 17, 2016, 01:06:13 am
content: You've set RA0 as an output, and RA1-4 as inputs.

author: MarkF
author_rank: Super Contributor
timestamp: August 17, 2016, 01:06:24 am
content: Quote from: neko efecktz on August 17, 2016, 12:49:37 amTRISA defines RA0 as output and RA1-RA4 as inputs.You want TRISA = 0b01111;

author: bson
author_rank: Unknown
timestamp: August 17, 2016, 01:09:08 am
content: Quote from: neko efecktz on August 17, 2016, 12:49:37 amThis makes R0 an output and R1-R4 inputs. It should be TRISA=0b01111;Edit: I see others beat me to the punch. What they said.

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 17, 2016, 01:13:23 am
content: Thanks Mark,I got caught by this while doing another design but never gave it another thought.How about the difference between the two chips, any ideas?Bill

author: Monkeh
author_rank: Super Contributor
timestamp: August 17, 2016, 01:15:40 am
content: Quote from: neko efecktz on August 17, 2016, 01:13:23 amDid you attempt to directly measure current between the pin and ground?

author: MarkF
author_rank: Super Contributor
timestamp: August 17, 2016, 01:21:56 am
content: Quote from: neko efecktz on August 17, 2016, 01:13:23 amThe biggest thing I see between the PIC16F84A and PIC16F877A (other than the number of ports) is that there is NO analog input conversion for Port A in the 84A chip.

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 17, 2016, 01:27:23 am
content: Mark,you mentioned Pic16f877A.That was another project.The two chips I tested were both the same PIC16F84A-20/pMy PIC16F877a project is awaiting more development in the software for analog inputs etc.BILL

author: MarkF
author_rank: Super Contributor
timestamp: August 17, 2016, 01:34:38 am
content: Quote from: neko efecktz on August 17, 2016, 01:27:23 amThen, what two chips are you talking about?

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 17, 2016, 01:36:02 am
content: MarkThe two chips I tested were both the same PIC16F84A-20/p with the same date/batch codeBill

author: MarkF
author_rank: Super Contributor
timestamp: August 17, 2016, 01:37:55 am
content: I guess I don't understand the question then? The two PIC16F84A should work the same. Assuming the programming is the same and the chips are not damaged.

author: MarkF
author_rank: Super Contributor
timestamp: August 17, 2016, 01:44:10 am
content: You were driving the RA0 pin while it was in output mode of PIC16F84A. I wouldn't expect the same result while you have the conflict in input and output mode. It would depend on the small manufacturing differences in the drive current capabilites of each pin.

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 17, 2016, 01:50:11 am
content: Mark,If you look at the original post there are some test results.Where I was getting 2.5mA for RA0 with one chip and 0.5 to 0.7mA for the other.The other pins were all about 0.5mA for both chips.Now that I have fixed the port pin allocation all currents are the same approx 0.5mA.Thank youBill

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 17, 2016, 01:58:24 am
content: just another quick question.I have about 1/2 a dozon 4Meg and 8Meg crystals.I used 22pf caps with these.The other day i was given 50 pcs of 18.432MHz low profile crystals.they work ok with the 22pf caps in the basically simple project i am building.Would i need to change cap value if I start to make more complex projects utilizing the chips memory or a lot of processing that a PIC16F877A is capable of.I'm a long way from that at the moment but i am trying to be a little more adventurous each day.thanksBill.

author: MarkF
author_rank: Super Contributor
timestamp: August 17, 2016, 02:09:43 am
content: I can't help you there. I've been using oscillator chips instead of crystals for my projects.The PIC datasheet might have suggested values for the caps for different crystal frequencies.The program size or amount of processing being done is NOT going to affect the capacitors for the crystal. The capacitors and crystal just control the speed at which the instructions are executed. So if you toggle a Port pin with a slow crystal and then replace that crystal with a higher freq, the pulse width of the output pin will be shorter.

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 17, 2016, 02:19:44 am
content: Thankyou for your helpI have to have lunch now then go to work.all the bestBill.

author: katzohki
author_rank: Frequent Contributor
timestamp: August 17, 2016, 10:52:15 pm
content: Besides the ordering of TRISA, another common thing that might get you is to check that ANSELA is also set correctly. This sets pins to be configured as analog or digital (input) for port A and can cause things to not work if you're trying to use analog vs digital input and get it wrong. It has default values of analog on power up, for the part I'm looking at.When others have asked me about getting started with PICs I've recommended a PIC10F320 (or similar PIC10 series) and a PICKit, that's really all you need to get started at a bare minimum.

author: MarkF
author_rank: Super Contributor
timestamp: August 17, 2016, 11:29:13 pm
content: Quote from: katzohki on August 17, 2016, 10:52:15 pmIn my opinion that is a very poor Pic to learn on. The pic16f886 is a much better choice to start with. It also has more capabilities to learn. Like SPI and I2C Interfaces and timer functions.

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 18, 2016, 12:07:58 am
content: Good morning All,The projects I'm interested in doing, at the moment anyway, are LCD display units.The PIC16F84A and any other 18 pin device only gives me 4 pins for input plus 0ne pin of output to a led etc.A 28 pin device would give me more inputs and also some analog if i so choose.Please recommend a 28 pin chip. I haven't looked into them much at the moment.I bought a PIC16F877A to give me lots of input / output as well as analog.As I said i will start trying to do the analog software soon.I need to do some more research and experimenting.There are so many sample codes out there but a lot of them are a little cryptic and or incomplete.Then I have to try to incorporate it into my current code.I may need to ask for help on this subject in a week or two.got to finish the USB switch project first.Thank you for your help and suggestions.Bill

author: neko efecktz
author_rank: Regular Contributor
timestamp: August 18, 2016, 01:30:42 am
content: Yes.I have had the PIC16F887 recomended but i will also look int the PIC16F177x family. particularly the PIC16F1778.I have already designed a board for both 18 pin and 40 pin chips so doing a 28 pin board will kind of complete the set.I have made the boards to drive LCD 2 x 16 and a place to fit pull up resistor arrays on all I/O as required.By having a v+ pad at each end of the port I can either fit a 8 way array or cut one down and either use the high end or low end of the port for either input or output.Thankyou for your suggestion.Bill

author: MarkF
author_rank: Super Contributor
timestamp: August 18, 2016, 02:41:49 am
content: Another PIC I would recommend is the PIC18F2520. It has lots of program space and RAM for larger projects. The PIC18F2550 is simular but with a USB interface.