PDA

View Full Version : PIC 16F819 Turn-On Problem



Dick Ivers
- 8th June 2005, 19:28
I'm using the PIC to drive the gate of a n-channel mosfet. The fet controls a small, fast-acting solenoid. Code snippet as follows:

low porta.1
(some code here)
pulsout porta.1,100 'pulse the solenoid on for 1 ms

Everything works fine except for this:
When power is first supplied to the PIC the solenoid will briefly turn on by itself. Obviously, the fet is coming on during start-up. Is there a way to stop this?

Dave
- 8th June 2005, 21:37
Dick, I'm assuming that you have a logic level gate fet. I would put a pull down resistor of about 4.7k to 1k ohm from the gate to ground. This should stop the gate from seeing a turn on condition during poweron-reset while the micro port pins are in an input state.

Dave Purola,
N8NTA

Dick Ivers
- 9th June 2005, 00:30
Dave,
Thanks for your suggestion. Unfortunately, the pull down resistor did not work. The PIC behaves as if the port pin is very briefly going to the high state when it is first set as an output.
I decided I can live with the anomaly for now. I will use a p-channel mosfet on my next board . That should fix it.

Dick

mister_e
- 9th June 2005, 07:32
this has to be really fast depending of your software and crystal speed

did you try something like this right at the top of your code

TRISB =0
Solenoid var PORTB.0
solenoid=0

Melanie
- 9th June 2005, 09:17
Datasheet!

By default your PIC will come up in Analog Input mode on PortA.

When you initialise your PIC your first instructions should be...

TRISA=%xxxxxx0x

where x defines your other pins I/O status...

ADCON1=%00000111

to switch into Digital Mode, and finally...

Low PORTA.1

Now Bruce would prefer you to put the 'Low PORTA.1' first which could be good, but I calculate at 4Mhz, that's 3uS from the moment your PIC powers up, to that pin going low anyhow (and there's no-way your solenoid can react that fast). If you want to include a "belt and braces" solution, then put a 100nF Capacitor (of the type you use to decouple your PIC) between PortA.1 and Vss. That Cap will try to nail any initial spike during the first switch-on period before the PIC actually takes that pin low.

Remember, these MUST be the FIRST instructions your PIC executes.

Of course, depending on your PSU, if it's pretty crappy it could be a while (several mS) before your PIC wakes up. In that case you might need a more sophisticated input circuit to your FET than a single Resistor between the PIC and the FET gate. But that's another story...

Dick Ivers
- 9th June 2005, 16:29
Hi,
Thanks for your replies.
My circuit is supplied from a battery driven voltage regulator which is fully on before the power is switched to the circuit.
I neglected to mention that there are actually 2 solenoids and 2 mosfets. It is only the second one that misbehaves. Yes, I have 2 initialization steps at the very top of the code...already thought of that:

low portb.3
low porta.1

I don't have a scope. The solenoids are very fast and can operate in less than 100 us. I will try the cap idea from Melanie. Otherwise, will go to a p-channel mosfet on my next board.

Dick

Bruce
- 9th June 2005, 19:01
If you have a device that can react that fast to a power-on condition, you
might also consider disabling PWRT (power-up timer).

PWRT alone can introduce a power-up delay period of roughly 72mS before
any code can execute & set/clear outputs. Factor that in with normal start-
up times, and you can end up with a substantial delay period before you can
initialize everything properly.

I think the PBP config word defaults in most device header files have PWRT
enabled, but if your power supply comes up quickly, and you don't see erratic
behavior on power-up with PWRT disabled, that just might cure the problem.

Dick Ivers
- 9th June 2005, 22:31
Bruce,
PWRT is already disabled. Here is the whole configuration line:

@device pic16f819,intrc_osc_noclkout,wdt_on,pwrt_off,mclr_ off,bod_off,lvp_off,cpd_off

@ device ccpmx_off,debug_off,wrt_off,protect_off

I will try M's cap fix. The approach makes sense because it creates a transient path to gnd for the spurious voltage. Can't do this right away though...will have to wait.

Dick

markedwards
- 9th September 2005, 15:37
Dick,

Did you ever solve your 16F819 Turn-On problem?

Like Bruce recommended, I have found the PWRT seems to help.
I am also using INTRC and initialize to OSCcon = $60 (4mhz) and
later switch to OSCcon = $70 (8mhz) at the end of my initialization,
just before my main loop.
I have used 16F627A with INTRC, and 16F876, 16F872 w/ crystal and never had power up Turn-On problem like the 16F819.

Mark

peterdeco1
- 10th September 2005, 09:10
Hi Dick. I had exactly the same problem with a 16LF818 attached to a music chip. Upon power-up the chip would blast a few milliseconds of music from the speaker. I cured the problem by turning "POWER UP TIMER OFF". It's been about a year now and no problems have arised by doing this.

Dick Ivers
- 13th September 2005, 22:12
Peter and Mark,

No, I never really solved the problem, and yes, the power-on timer is already set to off as explained earlier. I have now moved past the problem because I no longer use the super-fast solenoid. Have gone to a servo instead .. no problem.