Problem with PIC16F87


Closed Thread
Results 1 to 40 of 44

Hybrid View

  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,648


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

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

  9. #9
    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?

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

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

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


    Did you find this post helpful? Yes | No

    Default

    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
    Last edited by The Master; - 14th September 2009 at 01:51.

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


    Did you find this post helpful? Yes | No

    Default

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

    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.

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 : 0

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