View previous topic :: View next topic |
Author |
Message |
gtx15
Joined: 19 May 2018 Posts: 27
|
Changing trisa causes reset |
Posted: Mon Jun 08, 2020 10:47 am |
|
|
Using a 18F46K22 the device during initialization resets/loses flow when I change trisa values with a 2.5 uf cap from pin a0 to pin a1. If i remove the cap or even put a short from a0 to a1 it works fine. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Jun 08, 2020 11:00 am |
|
|
Please post a small, compilable program that shows this happening. |
|
|
gtx15
Joined: 19 May 2018 Posts: 27
|
|
Posted: Mon Jun 08, 2020 5:00 pm |
|
|
Code: |
#include <erase.h>
void main()
{
while(TRUE)
{
set_tris_b (0x0f);
set_tris_c (0x80);
set_tris_d (0xb0);
set_tris_e (0x0);
set_tris_a (0x00); //crashes here!
while (1)
{
delay_ms(22);
led = 1;
delay_ms(44);
led = 0;
//TODO: User Code
}
}
}
|
Code: |
//////////////////////////////// erase.h
#include <18F46K22.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#bit led = 0xf83.3 //pin d3
#use delay(internal=64000000) |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Changing trisa causes reset |
Posted: Mon Jun 08, 2020 5:48 pm |
|
|
gtx15 wrote: |
when I change trisa values with a 2.5 uf cap from pin a0 to pin a1. |
It's not a good circuit design method to connect a cap between two i/o
pins. Especially not a big cap in the uF range. My suspicion is when you
pull the i/o pins down to 0v quickly, you may be generating a current or
voltage transient inside the PIC that is causing it to reset or to hang. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Jun 08, 2020 6:46 pm |
|
|
Those pins might have analog peripherals on them like ADC or comparator. Without disabling those peripherals and then using tris... I'm unsure what will happen.
Kinda obvious the PIC isn't 'happy'. As PCM P points out , I agree excessive current flowing where it shouldn't and the PIC halts.
Hopefully you haven't damaged 'something' inside !
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Jun 09, 2020 1:41 am |
|
|
Also (of course), a lot may depend on the other connections round
the chip.
If there is no reservoir capacitor close to the chip, and you then switch
what is instantaneously an overload on the chip, the supply itself might
be drooping.
Remember you can of course limit the maximum current involved
with a resistor. 100R, ensures that 5v, won't exceed the maximum
current rating of the output pins.
However I'd be suspicious of the other effect - raising the pin voltage
above Vdd, or taking it below Vss. This is the 'difference' between a
capacitor and a short.
Think about it you have pin 1 at 0v, and pin 2 at 5v. You then raise pin 1
to 5v. The effect it to momentarily take Pin 2 up to effectively 10v....
The capacitor becomes a charge pump at the moment you switch. This
will be clamped by the internal protection diodes into the supply rail.
Result will depend on the nature of the supply, and what overvoltage
clamping it has. Also the protection diodes inside the chip are not rated to
handle this.
The maximum current rating of an output pin, on this chip is 50mA. The
maximum current rating of the protection diodes is 20mA. So the
diode will be overloaded by a factor of more than 2*.... This is why
MicroChip very carefully specify that these are 'last ditch' protection only,
and if you have an input that needs to actually be clamped within the
rails, you need to provide your own diodes external to the chip..... |
|
|
|