PDA

View Full Version : Problem with PIC16F87



The Master
- 2nd September 2009, 23:18
Hi, Ive connected a PIC16F87 up in the same way i always do and ive put a test program on but its not doing what i want it to. Ive checked the obvious things. The resonator is the correct value, MCLR is held high through a 10K resistor, The fuses are set correctly, The correct chip is selected in microcode studio and the programmer software.

Heres my test code


'Define the oscillator (20MHz)
DEFINE OSC 20

'Set the tris registers
TRISA=%00000011
TRISB=%00000100

'Define output pins
pSocket1 VAR PORTA.2
pSocket2 VAR PORTA.3
pSocket3 VAR PORTA.4
pSocket4 VAR PORTB.0
pSocket5 VAR PORTB.1
pSocket6 VAR PORTB.3

pPower VAR PORTB.7
pStatus VAR PORTB.4

pData VAR PORTB.6 'Switches between Master and Slave

'Define input pins
iSensor1 VAR PORTA.0
iSensor2 VAR PORTA.1

'BEGIN: Main loop
loop:


high ppower
high pstatus
high pSocket6

pause 500

low ppower
low pstatus
low pSocket6

pause 500

GOTO loop


I would expect the 3 outputs to turn on and off once every second. Instead they are all flickering at varying frequencies.

Ive tried multiple PICs and ive replaced the resonator but with no change

Im sure ive had this exact problem before when running the pause command but ive searched the forums and i cant find any posts about it.

aratti
- 3rd September 2009, 07:45
Add CMCON=7 to your code.

Al.

The Master
- 3rd September 2009, 09:08
Oops, i missed that off the list. I did try that after reading and old thread about a PIC16F877A. Im sure the PIC16F87 works with or without it but i had tried it anyway and still no luck

Acetronics2
- 3rd September 2009, 10:00
Hi,

Your PIC config sequence ... just is missing !!!


Try to add to your Code top




'************************************************* *****************************
'Configuration
'************************************************* *****************************

'Program Configuration Register 1
@ __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_ON & _HS_OSC

'Program Configuration Register 2
@ __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF

...

' Pour 16F88

ANSEL = 0
ADCON0 = 0
ADCON1 = 0
CMCON = 7
CVRCON = 0
CCP1CON = 0



you just have to translate the config lines for MCS ... if you use it.

Alain

aratti
- 3rd September 2009, 11:16
TRISB=%00000100


From your code you have portB.2 set as an input but it seems not used. Is this input pin floating?

Al.

The Master
- 3rd September 2009, 12:33
Acetronics: The fuses are set in micropro (the software that programs the chip). I will try adding all of the other lines to the code though.

aratti: portB.2 is used as a serial input. Its not used in this test code but it will be eventually

Acetronics2
- 3rd September 2009, 12:48
The fuses are set in micropro (the software that programs the chip)


Ayayaye ... Quel Malheur !!!



. I will try adding all of the other lines to the code though.


I do recommend you to succed adding those lines ... humour !

Alain

The Master
- 3rd September 2009, 18:24
Ive tried adding those lines. It wouldnt compile with the first 3 so i commented those out. Its still not working properly. It does seem like its trying to work now and for a few seconds the lights flash at the right speed then they will start to hang in 1 state or flash rapidly.

I think ive seen a chip do this before when the supply cable is faulty but ive replaced that. The PSU is one i always use for things like this and is working properly, there are capacitors on the board and ive even tried adding an extra external capacitor

Im going to breadboard the circuit up with only an LED connected to see if i can get it working. Is there anything else i can check?

The Master
- 3rd September 2009, 21:31
Ive found the problem. I thought a bit more about the faulty supply thing. Ive got a 555 on the same board. I tried removing it and the PIC seems to be working fine now.

Ive uploaded the schematic of the 555 part of the circuit. I know that works because ive checked it with the breadboarded version that i still have. The question is how can that affect the PIC part of the circuit?

Acetronics2
- 4th September 2009, 13:21
Hi,

I thought it was a 16F88 ... sorry !

Did you install the 0.1µF close to the '87 supply Pins ( between pins is best ! ) ... and a 10µF+ Tantalum as close as possible ???

Some decoupling might be also necessary for the 555 : there are well known current spikes while the output stage toggles ... or try a CMOS 555 !

Alain

The Master
- 4th September 2009, 14:25
I think i have a 10nF cap right at the side of the chip. Its as close as i can get it. There is also a 100uF cap right after the regulator. Theres also an audio circuit that connects to it which has a pair of 1000uF caps on i think (they are at least 100uF). It doesnt make any difference wether or not that circuit is attached.

I didnt use a CMOS 555 because i read somewhere that they wouldnt be suitable for this circuit.

The Master
- 12th September 2009, 14:39
Hi, Im still having problems with this one. I connected the circuit back up to have another go at fixing it but the PIC doesnt seem to work properly at all now. When the 555 isnt connected the chip will turn on and flash some LEDs (to show its alive) then after a few seconds it resets itself. With the 555 connected it does the same thing but flickers slightly during the flash pattern.

I connected my picoscope up to see whats happening. Ive uploaded a screenshot of it. This is with the audio circuit (with the big capacitor) disconnected and with the 555 connected. This is the most variation the circuit could possibly see but it doesnt look like its enough to cause any problems

mackrackit
- 12th September 2009, 15:11
What are you using for a power supply and how is BOR set?

The Master
- 12th September 2009, 15:25
Im using a PSU similar to ones that would power external hard drives etc. Ive run breadboarded PIC circuits from this before without having any capacitors so i know its a good supply.

Something i forgot to mention before, the manual for the picoscope says that it will pick up slight interefence so the voltage is probably a lot cleaner than that line makes it look.

BOR is a fuse value right? I think ive seen it before but this chip doesnt seem to have that fuse.

Ive uploaded a screenshot of the fuses i have available and their values. Its been about a week since i last programmed this PIC so maybe a fuse is wrong

mackrackit
- 12th September 2009, 15:44
BODEN or something like that for this chip. Sorry

The Master
- 12th September 2009, 16:09
I tried changing the BODEN value but i got a fuse error that i cant get rid of. Ive set the fuses back, turned the programmer off/on and restarted the program but everytime i try to program i get this error "Fuse error 0x2007, Good 0x3F6E, Bad 0x0F0F". The numbers change when i change the fuse values though

mackrackit
- 12th September 2009, 16:39
The BODEN may not be the problem but it seems like the method of setting/changing the configs is.

I have never thought it a good idea to use the programmer software ware to set the fuses for many reasons. Find a way to disable that part and set the configs either in the *.inc or in your code.
http://www.picbasic.co.uk/forum/showthread.php?t=543
You will not be able to really work with the micros until you can master the configs...pun intended :)

The Master
- 12th September 2009, 17:01
Ok, I cant seem to get it to compile when i set the fuses in the PBP source file but i found the file that defines defaults so i can change it in there. The current values are "_HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF". Same as they always have been. Even if i dont set the fuses in the programmer software it still gives me the error. Now its also complaining about EEPROM errors too. It doesnt appear to be writing any data to the chips :S

mackrackit
- 12th September 2009, 17:14
Crap, the more I help the worse it gets... :(

Is the programmer set to do an erase at program time?

The Master
- 12th September 2009, 17:19
The programmer doesnt erase the chip itself but i did try that and still no luck. Ive read it back after and i think its completely blank. Everything is 00. Is that right or should they all be FF?

The Master
- 12th September 2009, 17:30
Good news. The programmer seems to be working again. I just unplugged the picoscope and it started working. Im not sure how they could interfere with each other but it looks like they were.

Ive reprogrammed the chip and its still doing the same as before

mackrackit
- 12th September 2009, 17:46
Now you can go back and play with the configs...

Reading back though this thread the original problem was LEDs not blinking correctly and the a 555 showed up someplace...

Please recap what you are trying to do and whit it is doing and current code.

I am cornfused.

The Master
- 12th September 2009, 18:28
Im confused too ;)

I turned the watchdog timer off and the chip stopped resetting itself after a few seconds. I dont know why it suddenly started in the first place. Maybe its because the main loop hardly does anything and it thought it had crashed.

Now back to the original problem. When the 555 is plugged in the PIC turns outputs on/off randomly. The strange thing is that it only seems to cause a problem when the PIC runs a pause command.

The current code is as follows.


'Define the oscillator (20MHz)
DEFINE OSC 20

x var byte

'Set the tris registers
TRISA=%00000011
TRISB=%00000100

'ANSEL = 0
'ADCON0 = 0
'ADCON1 = 0
CMCON = 7
CVRCON = 0
CCP1CON = 0

'Define output pins
pSocket1 VAR PORTA.2
pSocket2 VAR PORTA.3
pSocket3 VAR PORTA.4
pSocket4 VAR PORTB.0
pSocket5 VAR PORTB.1
pSocket6 VAR PORTB.3

pPower VAR PORTB.7
pStatus VAR PORTB.4

pData VAR PORTB.6 'Switches between Master and Slave

'Define input pins
iSensor1 VAR PORTA.0
iSensor2 VAR PORTA.1

low pstatus

for x=0 to 10
high ppower
pause 100
low ppower
pause 100
next

'BEGIN: Main loop
loop:

ppower=isensor1
pstatus=isensor2


GOTO loop


It should make the power light flash a few times then use the power and status LEDs to show the state of the 2 sensors. Whats weird is that the chip gets stuck on the for loop when the 555 is connected. The power LED flickers randomly. If i take the 555 out then it will run as normal and enter the main loop. Once in that loop i can put the 555 back in and it seems to be running as it should.

On the circuit the 555 and ceramic resonator are right next to each other. Could that be why only the pause command seems to be affected?

One other thing i think i should mention. The 555 part is to make IR transmitters flash at 38.5KHz. In a previous thread someone said i should also have pulses. I didnt have enough spare pins on the PIC to control those pulses and my breadboarded version worked fine without them. Could that cause this problem?

Darrel Taylor
- 12th September 2009, 22:40
Do you have a more complete schematic?
Because something doesn't seem right ...

http://www.pbpgroup.com/files/555.PNG


The 555 part is to make IR transmitters flash at 38.5KHz.
The way that 555 is set-up, it's NOT an astable multivibrator. (oscillator)

Is it connected to the PIC?
And if so, is that connection going to pin 7 of the 555?

Pin 7 is the "Discharge" output from the 555. It should be tied to the 1nF capacitor via another resistor that's in series with the 15K resistor.

If you have it connected to an OUTPUT from the PIC, it may cause the PIC to continually reset due to conflicting OUTPUTs drawing too much current.

If you want to modulate a 38khz signal from the 555, it needs to be set-up as an "astable multivibrator" and the signal from the PIC should go to pin 4 (reset).

The Master
- 12th September 2009, 23:13
The 555 schematic i posted is complete. It is only connected to the PIC through the 2 power rails. The 555 part is actually working and appears to modulate correctly. The receivers detect the IR now where they wouldnt when the emitters were unmodulated.

This 555 design is aparently an astable circuit but its not like any ive used before. I found the design for it on the internet and it was specificly designed for driving IR emitters.

I did notice something strange. With only the 555 section of the circuit running (including 2 IR emitters) the 5V regulator is getting very hot (too hot to touch).

Even though my picoscope clearly shows that the voltage doesnt vary by more than about 0.5V either side of 5V i think its possible that the 555 circuit is actually a monostable one but its designed to short something out which causes it to reset and act like an astable. This would account for the hot regulator and the PIC acting strange

Edit: I did just notice. The only thing missing from the schematic are 2 resistors that go from the output to each of the 2 IR emitters.

Darrel Taylor
- 12th September 2009, 23:42
If the top of the 15K resistor is connected to pin 3 (output) it might work.
But the schematic didn't reflect that.

http://www.pbpgroup.com/files/555_Astable.gif

What size resistor goes to the LED's, and how big is the regulator?

.

Darrel Taylor
- 13th September 2009, 00:00
Oh crap, now I see that the thing in the upper left corner of your schematic is actually a POT.
It looked like the 15k was tied to power and a resistor was above that.
That should work, sorry. :o

But I'm still curious about the emitter loads and regulator.

.

The Master
- 13th September 2009, 00:12
Each emitter has a 33ohm resistor. The regulator is a standard DE7805 that i use for every project. These dont normally get this hot unless they are shorted out. I even had a DE7812 running 48 high power LEDs (in 15 sets) and it didnt get this hot.

The Master
- 13th September 2009, 03:30
Ive tried removing everything from this circuit. At the moment the 555 is running from a breadboard through a seperate regulator and pin 3 feeds back into the circuit to the transistor. This seperate regulator is cold. The main regulator stays cold until i connect the IR emitters then it gets really hot. Ive checked the current with a multimeter. With both regulators and the 555 it uses 16.5 (milliamps i assume). When i connect the IR emitters it jumps to 101.2 and keeps increasing to about 102. The regulator gets hot quite quick.

Im a little worried about this heat because i need to connect the PIC chip, an RS485 chip and the audio amp circuit and they all use the same regulator.

It looks like using 2 or maybe 3 regulators for the different parts of the circuit should solve everything. Ive got some heatsinks i can put on too.

I still cant figure out why the 555 causes such problems. At the moment the emitters are running from the same board as the PIC. The 555 and its resistors/capacitors etc are running from a seperate regulator and it all works fine. The emitters are drawing way more current than anything else yet its not those causing it. It doesnt appear to be a short and my picoscope shows a fairly stable voltage. I also checked the picoscope when it wasnt connected to anything and the line looked pretty much identical but at 0V so most of it is just noise that the scope picks up.

dhouston
- 13th September 2009, 11:26
You cannot measure the current accurately without a true RMS meter - the circuit is highly non-linear.

You need to show us the complete schematic.

The Master
- 13th September 2009, 12:40
Ive made and uploaded a schematic based on my PCB layout.

The pins at the top go to the IR receivers and 1 of the speakers.
The ones at the bottom left go to the IR emitters and the other speaker
Bottom right go to some light outputs
Right top are the main connections for power/data/line in
Right bottom goes to the audio amp circuit

dhouston
- 13th September 2009, 13:49
I'm afraid I don't grasp what the 555 is doing. Do you have a link to the website where you found the 555 circuit?

The Master
- 13th September 2009, 14:16
Sorry, I just realised that schematic is slightly wrong. The POT should connect to pin 7. Its connected right on the PCB though.

Ive uploaded the corrected schematic. I found the website i thought i got it from but it seems i didnt use that one (i dont think i got it to work). The circuit i used is one of the example circuits in PCB Wizard. Ive uploaded a screenshot of that too.

In my circuit ive used a 15K resistor and a 5K POT in series instead of the 100K VR in the example and ive used a 1nF cap instead of 100uF

Melanie
- 13th September 2009, 15:10
No Resistor from the 555 to the Base of the Transistor? How hard do you want to turn that poor Transistor on? If you disconnect pin 3 on the 555 and still have your 7805 (they DO need a heatsink) overheating, then you've damaged your 555.

The Master
- 13th September 2009, 15:26
Thats another mistake, sorry. There is a 10K resistor between pin 3 on the 555 and the base of the transistor.

I use 7805s in every circuit i make that needs 5V and they never need a heatsink. Sometimes they do get slightly warm if a lot of things are running from them but still not enough to need a heatsink.

For testing i moved the 555 to a breadboard with a seprerate regulator and that regulator stayed cold. The one on the main board still got hot though which means its the IR emitters that are causing it to overheat. According to the datasheet they should be drawing 100mA each. Theres 2 of them but its about a 50% duty cycle so i would expect the average to be around 100mA. Lastnight my multimeter showed 102mA for the emitters and the 555 so i guess thats about right then as long as i put a heatsink on this regulator.

dhouston
- 13th September 2009, 16:07
I see Data A & Data B but no GND for the RS485 network.

The Master
- 13th September 2009, 16:11
The RS485 ground is the same as the ground for the rest of the circuit (0V)

dhouston
- 13th September 2009, 17:19
Try it with the RS485 network disconnected. If the current drops, then use a 100 ohm, 1/4W resistor between the RS485 GND and this circuit's GND.

The Master
- 13th September 2009, 17:23
The RS485 chip hasnt been plugged in most of the time

dhouston
- 13th September 2009, 18:21
The RS485 chip hasnt been plugged in most of the time
You could still be drawing a lot of current due to mixing grounds. Try it with the network disconnected, including its GND.

The Master
- 13th September 2009, 18:29
For most of this testing the RS485 chip hasnt been plugged in and the data wires disconnected. When it has been connected up the RS232 to RS485 convertor has been running from the same power supply.

Im pretty sure theres no problem with the RS485 part of the circuit. When the chip starts having a fit during pause commands if i pull the 555 out then it suddenly goes back to normal.

I also tried using the 555 on the breadboard but removing its regulator and connecting the power wires after the regulator on the PCB and that causes problems aswell. It only works when the 555 and PIC have different regulators

The Master
- 14th September 2009, 01:47
Ive just connected the audio amp circuit up and for some reason that causes the PIC to constantly reset too in the same way the 555 does. The audio circuit has some extra capacitors on so i would have thought that should help.

I tried connecting the audio circuit on the same regulator as the 555 and everything works. The only thing i noticed is that i had to change the POT to get the IR receivers to pick a signal up.

So, the 555 and audio circuit both cause problems with the PIC but the IR emitters that use more current than everything else put together have no effect on it. Im really confused

Edit: I just remembered something else too. When i press the button on my smoke machine the PIC resets. Ive had this problem in the past too. I wonder if this problem could be somehow related. The smoke machine is interfering even though its only connected by the mains wires in the house so it seems things can have an effect on the PIC even when in theory they shouldnt

mackrackit
- 14th September 2009, 09:13
Not knowing how mains are wired where you are at but I will guess that there is a problem in the way they are wired at your place.

I had a similar problem at a customers place. A lot of high frequency "stuff" runs (similar to your smoke machine?). After spending time changing the power supply, adding capacitors etc I found the problem was bad or no earth grounds on most of the equipment. Several places the ground wire was connected to the machine but not to a ground rod creating several antennas going several directions.

I went though and fixed and or added the earth grounds and the problem was solved. The false alarms on their security system even stopped. Not sure about that one, just what I was told.

Might not be the problem, but just from a safety side it would be worth a look.

The Master
- 14th September 2009, 11:51
I dont think the 555 problem is caused by grounding problems. Its on the same PCB using the same ground as everything else. The smoke machine itself is definately earthed correctly and ive had the same problem in a few different buildings. The PIC also resets if i plug something like a soldering iron or big transformer in and the ignition on our gas cooker causes a reset too. These things have affected every PIC circuit ive made so i guess they are normal but im just wondering if the 555 is creating a similar kind of interference thats so small that it only causes a problem when its connected to the same power rails as the PIC.