PDA

View Full Version : Capacitor on PIC output



Michael
- 21st March 2008, 16:13
I have a simple problem that is making no sense at all.

Using a 16C65B at 4mhz.

Imagine if you will a simple RC circuit meant for timing that uses a 1000uf electrolytic cap to ground and a trim pot in parallel with the cap to ground for adjusting the delay.

These rc circuits are on the output pins d.0 d.1 and d.2

Using a pullup of 10k on the input pins e.0 e.1 and e.2


The code is ultra simple --

start

If porte.2 = 0 then 'channel 1
high portd.0
endif

if porte.1 = 0 then 'channel 2
high portd.1
endif

if porte.0 = 0 then 'channel 3
high portd.2
endif

goto start


Now here's what happens --

If I trigger each channel momentarily, one at a time, in any order, all is well -- the output pins each go high and stay there.

If I latch on channel 1 with a constant jumper....
channel 2 will operate fine but channel 3 will not go high if I try to trigger it.

If I latch on channel 2...
channel 3 will operate fine but channel 1 will not go high if I try to trigger it.

If I latch on channel 3...
neither channel 2 or channel 1 will operate.

NOW --

If I remove the cap from the channel trying to go high -- all is well.

??

I've tried to fix this in code -- still working on it but I can't have the program stop (pause).

I may end up figuring this out but sure would appreciate any hints.

It has to be more than just the cap being there based on the examples I gave.

THANKS KINDLY for any help.

Archangel
- 21st March 2008, 16:35
Hi Michael,
1 thought comes to mind, have you measured the total leakage current going to ground while the CAP is charging? I am curious as to the Hi state voltage at the capacitor too.

Michael
- 21st March 2008, 17:20
I'm working on some different code right now -- I HAVE to solve this in code or I'm screwed.

I haven't measured leakage currents or anything, it will do the same thin on a variety of caps-- I've tried 3 different electrolytics at 47 -- 1000 and 2200 --same results.

Besides, what is wierd is that if I take the cap out and it just sees the resistence of the trim pot to ground,,,,all is fine (about 2.2K).

For some reason, this cap must be shunting the output to ground -- but why "here and there".

Oh well, back to my code.

skimask
- 21st March 2008, 17:28
For some reason, this cap must be shunting the output to ground -- but why "here and there".
Might have to run the PIC faster. 4Mhz...cap is probably discharging before you even get a chance to see it.
I did a project awhile back where I used an LED as a touch sensor, basically read the residual voltage across an LED after 'charging' it. An LED has X amount of junction cap's, and it can be varied a bit by the amount of ambient light hitting the surface of the LED...
Anywho's, long story short, I tried it at 4Mhz, didn't work, no matter how tight I made the code. Capacitance was discharging faster than I could read it. Sped the PIC up to 40Mhz, worked like a champ.

EDIT: Disregard...I just noticed you were using a 16C65B... Wow! That's old school. There's a lot of newer options out there. Options that include built in comparators, ADC's, and so on...run faster, use less power, and so on...

JD123
- 21st March 2008, 17:28
If you are wanting to read the state of the cap charges, shouldn't you be making the ports inputs after they are triggered?

Michael
- 21st March 2008, 17:31
Thank God -- I just figured it out and I had suspected all along it was because HIGH portX
was being called more than once ? BUT, it never went low in the code so why would would that happen?

The port output wasn't appearing as true DC and the cap was taking it to ground?

Strange though because some channels would work fine.

Anyway - problem solved.

I did some code where once the input is trggered it called a subroutine that made the output HIGH just once.

Still, I wish I knew exactly why

start

If porta.0 = 0 then
high portd.0
endif

goto start

....acts wacko with the cap

Is the high output in that case looking like a rapid pulsating DC or something?


Funny thing is -- whenever I've gotten desperate enough to use this forum -- I always figure
it out 15 minutes after I post. !!

Anyone else like that?? LOL

skimask
- 21st March 2008, 17:34
Funny thing is -- whenever I've gotten desperate enough to use this forum -- I always figure it out 15 minutes after I post. !!
Anyone else like that?? LOL
Only everyone! :D

JD123
- 21st March 2008, 17:35
Funny thing is -- whenever I've gotten desperate enough to use this forum -- I always figure
it out 15 minutes after I post. !!

Anyone else like that?? LOL
We are but the grease the gets the stuck wheels moving. And yes, but I don't have internet access where I code, so it's more like 1 day + 15 minutes. ;)

Michael
- 21st March 2008, 17:42
Yeah JD123, that's part of this program -- I wait a few seconds and then make the pins inputs to see the charged cap.

16C65's because it's what I have (as in hundreds).

I guarantee though if anyone breadboards it and tries it you'll encounter the same thing.

JD123
- 21st March 2008, 17:47
Okay, Michael... I just didn't see that in your code.

Michael
- 21st March 2008, 19:10
Still would like to learn why I had that problem.

Because actually when you run code over and over again that includes HIGH it's pulsing the output pin again and again based on the instruction clocks square wave?

But when you call HIGH just once and leave the output pin alone, it's a steady DC that is stable.


start

If porta.0 = 0 then
high portd.0
endif

do other stuff

If porta.0 = 0 then
high portd.0
endif

do other stuff

If porta.0 = 0 then
high portd.0
endif

goto start

Not good when a capacitor is on the output?