PDA

View Full Version : Mystery instability of 16f628a



Davidmarks
- 2nd March 2011, 18:40
Having struggled unsuccesfully to get a simple pendulum driver program working I have gone back to basics in order to check out my programming. i have built a basi cbreadboard with a 16f628A It simply has the supply connected (5V) and the 5 lines necessary from a pickit 2. There is an LED with 1K in series hanging on port b.3. Sometime it works sometime it doesn't.
Bringing a finger to within an inch of the pickit2 makes it run. Have I gone mad (again) or have I just done something unspeakably daft ?

joseph
- 2nd March 2011, 20:05
add a 4.7k pull up resistor on mclr pin

Bruce
- 2nd March 2011, 21:08
Have I gone mad
Quite possibly - but we will hold-off sending the guys with the white coat over until we've seen schematics and code...:)

Davidmarks
- 2nd March 2011, 21:52
Thanks for that Bruce - I should have asked matron to check my post - forgot to attach the code, Just arrived back from the village pub and tried Joseph's 4.7k pull up on mclr and lo and behold... it works ! many thanks for that .
Cheers David

Davidmarks
- 3rd March 2011, 13:25
I do not believe this ! After a spot of tinkering and adding to the circuit this am it has suddenly gone unstable again (It only operates when finger approaches or touches PIC) stripped circuit down to basic (schematic attached) and it still doesn't work. By the time i have finished it would be quicker to build the thing with valves (tubes) I used to understand them ! The code is as follows:
[@ device pic16f628a,INTRC_OSC_NOCLKOUT
define osc 4
begin:
low porta.0 ' Turn LED on
PAUSE 500 ' Wait 500mS (1/2 second)
high porta.0 ' Turn LED off
PAUSE 500 ' Wait 500mS (1/2 second)
GOTO BEGIN ' Loop continuously
end

master_olan
- 3rd March 2011, 13:40
Have you try turning off the analog comparators? if you dont know how just add ADCON1=7 near the top row...

rsocor01
- 3rd March 2011, 13:48
Also, add the line

TRISA = 0

Bruce
- 3rd March 2011, 13:50
CMCON = 7 will disable the comparators. Also place a small 0.1 or 0.01uF cap between the PIC gnd & vcc pins. Make sure it's as close as possible to the pins.

It's also a good idea to include at least the minimum config options in your code so you're not left with whatever the default unprogrammed config bits are.

I would use at least @ device pic16F628A, intrc_osc_noclkout, wdt_on, mclr_on, lvp_off, protect_off.

If that doesn't take care of it, check your power supply.

master_olan
- 3rd March 2011, 13:54
yup..my mistake...its cmcon = 7...

Davidmarks
- 3rd March 2011, 15:01
Hi,
Thanks for the suggestions folks. tried them all one by one and got nowhere, then noticed that /MCLR was checked in PicKit 2. Unchecked it and everything worked like a dream ! I then worked backward taking each mod off in turn to see which one had done the trick! Yes, youve guessed it .. the dam thing still worked. I have reintroduced all suggestions again in the hope that this thing shows a tad more reliability, but I'm not holding my breath !

Thanks again
David

Bruce
- 3rd March 2011, 15:07
Glad to hear you got it working, but you really do want to include that cap between the gnd & vcc pis. Without it you might have more problems down the road. Some older PIC types could get by without this cap, but most all newer A versions will experience problems without it. Just FYI. It's cheap insurance...:)

Davidmarks
- 3rd March 2011, 15:44
Thanks Bruce. It's back in even as we speak ! Belt, braces and a piece od string as they say !
Cheers

Archangel
- 10th March 2011, 19:32
Hello Davidmarks,
I am curious, are you getting any warnings when you compile? It occurs to me, without the present ability to check MY pbp due to a hard drive failure here at home, What is the default OSC setting in the 16F628A.inc file? Have you opened it and commented it out ? Because if not, your program will use the default osc setting and NOT the one you wrote into your code. So if the default is for using a crystal instead of INTRC_OSC * * * you will in effect have the external crystal ports open to the ether looking for a finger to help start the oscillator by stray capacitance. One more thing, is the " [ " at the beginning of the config statement, in you code or just in your post?

Davidmarks
- 10th March 2011, 23:01
Thanks Joe. As I said in previous post the thing is working OK now. Didn't know about the need to change the inc file for the internal oscillator, but I have now done so and relieved to find it still works. The [ symbol was intended to signify the start of the code.. seem to remember someone telling me that I should do that when posting code. I now have yet another seemingly inexplicable problem. I am programming in circuit with PicKit 2 which has suddenly decided to stop the circuit working if I disconnect it. I have a seperate power supply which is powering the circuit so simply cannot understand why it should stop working when I remove the PicKit2 . It wasn't doing it earlier this week so I am at a loss to know what I have done ( nevertheless I'm pretty sure that I know who is to blame again!)
Cheers
David M

Archangel
- 11th March 2011, 00:39
Microchip sells demo boards at a reasonable price which simply plug into the pickit2. I like them for testing code snippets, easy quick push button changes and viola it is running again, no wires to fuss with. different boards for the 628 and similar vs 690 series. As for who is to blame . . . blame it on the curve, the learning curve, we ALL have lost it on that curve, be careful not to oversteer, so as not to spin out :D

mackrackit
- 11th March 2011, 08:56
I am programming in circuit with PicKit 2 which has suddenly decided to stop the circuit working if I disconnect it.

Sounds like a MCLR issue. Try _MCLRE_OFF
in your configs.

Pimentel
- 11th March 2011, 10:04
Put a 100nF capacitor near pins 5 and 14 (gnd and vcc) !
Its solve my mistery problems in the pass.

Good luck
Pimentel

hardcore
- 22nd March 2011, 02:43
I had problem with 16f628a
After repeating to reprogram IC with the same code it start working as has to be.
Possible disadvantage of 16f628a is some bits of reprogrammed memory do not change their state during programming.
Hope it helps.
hardcore

George
- 4th April 2011, 22:47
Hi David,

I had exactly the same problem as you seem to be having with a project I'm currently working on, also with a PIC16F628a.

I found the answer to be _LVP_OFF

What would happen is it defaults to LVP on, each time it would get a signal on the LVP pin, the micro would reset, hope this helps