|
|
View previous topic :: View next topic |
Author |
Message |
sareehy
Joined: 03 May 2016 Posts: 20
|
would be better to connect unused pins or leave them unconne |
Posted: Sat Aug 19, 2017 3:47 pm |
|
|
Hi,
Would be better to use the unused pins of mcu as i/p or o/p ?
or, should leave them unconnected ?
regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 19, 2017 4:33 pm |
|
|
Leave them unconnected, and set them to be low level output pins.
Do this near the start of main().
See this thread. The problem was a 10% error rate during SPI
transmission, caused by noise from unconnected pins on the PICs.
http://www.ccsinfo.com/forum/viewtopic.php?t=45371&start=15
Setting all unused pins to low level outputs solved the problem.
Example:
Code: |
void main(void)
{
// Put variable declarations here.
init_unused_pins();
.
.
.
.
}
//-------------------------------------------------
// Set all unused pins to be low level outputs.
init_unused_pins(void)
{
output_low(PIN_A0);
output_low(PIN_A1);
output_low(PIN_B3);
output_low(PIN_B4);
output_low(PIN_B5);
output_low(PIN_C1);
output_low(PIN_C5);
}
|
This example assumes you are using Standard i/o mode (which is the
default mode of the compiler), and not Fast i/o mode. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Aug 22, 2017 12:27 am |
|
|
I felt it possibly worth going a little further here.
Generally, on 99% of electronics, the thing that must be avoided, is having pins left as inputs, and floating. This is a very common way of generating problems.
Now on most electronics, you don't have the option to program pins as outputs, so on these you have to provide external pull-up or pull-down.
Which to use, actually depends on the technology involved. Historically 'TTL' IC's drew fractionally more power if you tried to pull the inputs 'down', rather than 'up', so external pull-ups became a common standard.
You then have 'why a resistor, rather than a direct short'?.
The reason, covers several things:
First, if you have a solid connection, and then accidentally or deliberately a signal is injected, you then have created a short. Not good. Being able to re-use a pin that is being pulled up, without making any change to the board, can be quite convenient at times.
Second, in some cases (depending on how supplies to the chip are actually implemented), there can be situations where parts of a chip power up before others. This again can give a short.
Then (of course) if the pin does at some time have an internal drive capability, and this gets enabled, again a short.
Then if for some reason the chip is not powered, this creates the possibility of it trying to draw power from the connection.
Now on the PIC, for 90%+ of the pins, you have the option to change it to an output, and drive it. This is obviously cheap to do, and effective in avoiding the pin floating. This is the option shown by PCM_Programmer in the above thread. The only 'caveat', is if the pin does get connected to something else that is also capable of driving, then the pull-up/down, does become the 'better' option.
It is surprising sometimes just how large a resistor can be and still prevent problems. When you realise just how high the input impedance of a CMOS gate can be, and that the FET's internally can act as rectification diodes, it becomes the realisation that an unconnected pin can be charged like a balloon with static, but also can act as a radio receiver.
Now this goes on to the second part of keeping a PIC circuit reliable. Good grounds, some local decoupling close to the PIC itself, and then ensure there are no floating input pins, and a very large percentage of the 'peculiar' problems that some people have with circuits, disappear.... |
|
|
sareehy
Joined: 03 May 2016 Posts: 20
|
|
Posted: Tue Aug 22, 2017 9:29 pm |
|
|
Thank you for useful information guys
I appreciate your effort ^^
Could the mclr pin connection cause a similar problem ?
and what is the recommended connection for it ?
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|