Problem with PIC16F87


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 44
  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697

    Default Problem with PIC16F87

    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
    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.

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Add CMCON=7 to your code.

    Al.
    All progress began with an idea

  3. #3
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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
    Last edited by The Master; - 3rd September 2009 at 09:13. Reason: Fixed spelling mistake

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi,

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


    Try to add to your Code top

    Code:
    '******************************************************************************
    '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
    Last edited by Acetronics2; - 3rd September 2009 at 10:02.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Code:
    TRISB=%00000100
    From your code you have portB.2 set as an input but it seems not used. Is this input pin floating?

    Al.
    All progress began with an idea

  6. #6
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by The Master View Post
    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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?

  9. #9
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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?
    Attached Images Attached Images  

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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.

  12. #12
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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
    Attached Images Attached Images  

  13. #13
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What are you using for a power supply and how is BOR set?
    Dave
    Always wear safety glasses while programming.

  14. #14
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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
    Attached Images Attached Images  

  15. #15
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    BODEN or something like that for this chip. Sorry
    Dave
    Always wear safety glasses while programming.

  16. #16
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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

  17. #17
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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
    Dave
    Always wear safety glasses while programming.

  18. #18
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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

  19. #19
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Crap, the more I help the worse it gets...

    Is the programmer set to do an erase at program time?
    Dave
    Always wear safety glasses while programming.

  20. #20
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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?

  21. #21
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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

  22. #22
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  23. #23
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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.
    Code:
    '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?

  24. #24
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Do you have a more complete schematic?
    Because something doesn't seem right ...



    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).
    DT

  25. #25
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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.

  26. #26
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    If the top of the 15K resistor is connected to pin 3 (output) it might work.
    But the schematic didn't reflect that.



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

    .
    DT

  27. #27
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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.

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

    .
    DT

  28. #28
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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.

  29. #29
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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.

  30. #30
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    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.

  31. #31
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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
    Attached Images Attached Images  

  32. #32
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    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?

  33. #33
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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
    Attached Images Attached Images   

  34. #34
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  35. #35
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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.

  36. #36
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    I see Data A & Data B but no GND for the RS485 network.

  37. #37
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    The RS485 ground is the same as the ground for the rest of the circuit (0V)

  38. #38
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    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.

  39. #39
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    The RS485 chip hasnt been plugged in most of the time

  40. #40
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    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.
    Last edited by dhouston; - 13th September 2009 at 18:24.

Similar Threads

  1. problem using GOSUB under interrupt
    By fobya71 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 5th March 2010, 19:52
  2. Problem to compile my program
    By wagner in forum Off Topic
    Replies: 5
    Last Post: - 7th July 2008, 20:17
  3. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  4. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59
  5. PORTA.PinNo = 1 ' problem
    By frank small in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th May 2004, 14:30

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts