Announcement

Collapse
No announcement yet.

Program "destroys" PIC16F88 when loaded in Chip

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Program "destroys" PIC16F88 when loaded in Chip

    I have 2 (very) strange problems when programming a PIC16F88.
    The problem is not the programmer but the actual program itself.
    -
    The program is a very simple and only used to see how the USART on PIC16F88 can be used.
    When I added the "ON INTERRUPT GOTO MyInt" I noticed that all PortA/B Led's on my test box switch on/off every 2 seconds for about 0.25 second.
    Take the ON INTERRUPT instruction out and everything seems normal.
    But when I add the PORTA.7=1 instruction in MyInt routine that Led stays of, suggesting the interrupt routine is not called... as should be, because INTCON=0
    -
    But now the second and really annoying problem
    I started to take away pieces from my program to test the failing ON INTERRUPT.
    When I program the PIC16F88 with this program (See below) the FIRST time it looka all normal.
    However when I want to load the same (or another) program again the programmer does not recognize the PIC16F88 anymore.
    If I take a fresh PIC16F88 the same happens. First time = OK after that the PIC is unusable.
    -
    I wrote many programs for PIC16F88 and if I take one of those programs I can load and reload as often as I want, no problems.... and no strange behavior of the ports... even when there is an ON INTERRUPT instruction in the program.
    -
    Just for good measure I exchanged the programmer for another one but that made no difference.
    I can only assume that somehow I set some crazy Fuses somewhere but as far as I can see they are all quite normal.
    The config bits are identical to the programs that show no problems.
    -
    You are now my last hope.
    I have destroyed 6 PIC16F88 chips so far and have no idea where to look anymore.
    -
    I will copy the code below.
    There are lots of text and some routines that are not used (I use skeleton files with pre-written subroutines) but I did not dare to take them out to keep the code exactly as I used it here.

    I hope somebody sees what I am doing wrong here.... I am running out of new PIC16F88 chips...

    Thanks, Jan

    ====================================================
    '*******************************************************************************
    '* Name : UNTITLED.PBP *
    '*-----------------------------------------------------------------------------*
    '* Purpose : *
    '* : *
    '* : *
    '*-----------------------------------------------------------------------------*
    '* Author : J.W. Haarbrink *
    '* Notice : Copyright (c) 2009 J.W. Haarbrink *
    '* : All Rights Reserved *
    '* Date : xx-xx-2009 *
    '* Version : 1.0 *
    '*-----------------------------------------------------------------------------*
    '* Proc : PIC16F88 *
    '*-----------------------------------------------------------------------------*
    '* Ports : A0 (I) = unused *
    '* : A1 (I) = unused *
    '* : A2 (I) = unused *
    '* : A3 (I) = unused *
    '* : A4 (I) = unused *
    '* : A5 (I) = unused *
    '* : A6 (I) = unused *
    '* : A7 (I) = unused *
    '* : *
    '* : B0 (I) = unused *
    '* : B1 (I) = unused *
    '* : B2 (I) = unused *
    '* : B3 (I) = unused *
    '* : B4 (I) = unused *
    '* : B5 (I) = unused *
    '* : B6 (I) = unused *
    '* : B7 (I) = unused *
    '*-----------------------------------------------------------------------------*
    '* 01-01-2009 : Initial version *
    '* *
    '* *
    '*******************************************************************************

    '--- Fuses ---------------------------------------------------------------------
    #CONFIG
    __config _CONFIG1, _INTRC_IO & _WDT_ON & _LVP_OFF & _CP_ON & _MCLRE_OFF & _PWRTE_ON
    #endconfig

    '--- Init -------------------------------------------------------
    FLAGS=0 'Reset all flags
    DEFINE OSC 4
    include "modedefs.bas"
    ON INTERRUPT GOTO myint 'Interrupt handler is myint

    '... Set Analog outputs ..............................................

    '... Set Analog outputs ....................................................
    CMCON=%00000111 'Disable Comparators
    ANSEL=%00000000 'Force RB6 and RB7 digital (16F88 only)

    '... OSC Settings ..........................................................
    OSCCON =%01100000 'Oscillator Settings (4MHz

    '... Outputs ...............................................................
    OPTION_REG.7=0 '0=Enable Weak Pull-Ups on PortB

    TRISA=%00110000 'PORTA set to Output/Input
    TRISB=%00000000 'PORTB all set to Input

    '... USART .................................................................
    SPBRG=6
    RCSTA=%10010000

    INTCON=%00000000


    ''---- Register Display Box ----------------------------------------------------
    RegBox_Addr con $70
    RegBox_SDA var PORTA.0
    RegBox_SCL var PORTA.1
    Reg0 var byte 'Registerbox register 0
    Reg1 var byte 'Registerbox register 1
    Reg2 var byte 'Registerbox register 2
    Reg3 var byte 'Registerbox register 3

    '---- Init vars ----------------------------------------------------------------
    '... Ports .....................................................................
    Tst6 var PORTA.6
    Tst7 Var PORTA.7
    Frm_Err var PORTA.2
    Overrun_Err var PORTA.3

    '... Word vars .................................................................
    Bzr var word
    '... Byte vars .................................................................
    '... Bit vars ..................................................................
    Rx_Int var PIR1.5
    F_Err var RCSTA.2
    O_Err var RCSTA.1

    '... Constants .................................................................
    L_Tone CON 277 'Low Beeptone
    H_Tone con 222 'High beep tone

    '---- Setup vars ---------------------------------------------------------------
    PORTA=0
    PORTB=0
    '---- Masterloop ---------------------------------------------------------------
    Master_Loop:



    goto master_loop

    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    'Interrupt routine
    '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    DISABLE
    MyInt:
    tst7=1
    END
    resume
    ENABLE

    ''+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    '' Beep at 1800 Hz
    ''+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ' L_Beep:
    ' for bzr=1 to 500
    ' Beeper=1
    ' pauseus l_tone
    ' Beeper=0
    ' pauseus l_tone
    ' next bzr
    ' return

    ''+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    '' Beep at 2200 Hz
    ''+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ' H_Beep:
    ' for bzr=1 to 500
    ' Beeper=1
    ' pauseus h_tone
    ' Beeper=0
    ' pauseus h_tone
    ' next bzr
    ' return

    '-------------------------------------------------------------------------------
    ' Write to display register box
    '-------------------------------------------------------------------------------
    Write_Reg:
    I2cwrite RegBox_SDA,RegBox_SCL,RegBox_addr,$00,[$27,reg0,reg1,reg2,Reg3]
    pause 10
    return

  • #2
    The program looks good BUT, What are you interrupting from? I see NO interrupt enable bits being set.
    Dave Purola,
    N8NTA
    EN82fn

    Comment


    • #3
      Also JanHaarb, Why are you setting the CODE PROTECT BIT if you are just developing code? Are you affraid you might READ what you have just programmed? When you do that you MUST erase the entire program memory before re-flashing the device. Also you are disabling the MCLR or RESET pin which may be interfering with the flashing routine. You should put a PAUSE of about 1 or so milliseconds before you set the TRIS register for the PORTA MCLR pin.
      Dave Purola,
      N8NTA
      EN82fn

      Comment


      • #4
        Originally posted by DavidP View Post
        The program looks good BUT, What are you interrupting from? I see NO interrupt enable bits being set.
        For test purpose (remember I tried to see why the PORTA and PORTB get these short pulses when I add the ON INTERRUPT instruction) I more or less completely removed the original program.
        I just wanted to see if the ON INTERRUPT command would somehow trigger an interrupt that caused the PORTA and PORTB leds to flash.
        To make 110% sure that the program would NEVER go to MyInt I even added the END statement.
        That is when the second problem, destroying the PIC16F88, started to occur.

        As I far as can see MyInt is not called and that is as should be.
        But why the PIC16F88 is destroyed... I do not know.

        Comment


        • #5
          Originally posted by DavidP View Post
          Also JanHaarb, Why are you setting the CODE PROTECT BIT if you are just developing code? Are you affraid you might READ what you have just programmed? When you do that you MUST erase the entire program memory before re-flashing the device. Also you are disabling the MCLR or RESET pin which may be interfering with the flashing routine. You should put a PAUSE of about 1 or so milliseconds before you set the TRIS register for the PORTA MCLR pin.
          No, that bit is set in my skeleton file and is mainly for when the program is finished.
          I automatically erase the PIC when I program it so during development it does not bother me.

          I rarely use the MCLR pin as Reset but use the pin as an input.
          So far I never had any problems with it. The other programs I used (and that could be reprogrammed over and over again, all had the identical setup (= same skeleton file)

          There is most likely a link between the strange flashing of the PORT pins and the destroying of the PIC.
          But I have no idea what.

          Comment


          • #6
            The program disables the reset pin and sets the programming clock and data pins to outputs. This usually locks out subsequent in-circuit programming attempts.

            If possible, maintain the programming pins (RB6/7) as inputs:

            TRISB=%11000000

            (Your comment on this line doesn't match the setting. Comment says inputs, code sets outputs.)

            The port behavior on a 2-sec cycle sounds like the watchdog timer resetting the part. Test by disabling the watchdog in the config.
            Charles Leo
            ME Labs, Inc.
            http://melabs.com

            Comment


            • #7
              Originally posted by Charles Leo View Post
              The program disables the reset pin and sets the programming clock and data pins to outputs. This usually locks out subsequent in-circuit programming attempts.

              If possible, maintain the programming pins (RB6/7) as inputs:

              TRISB=%11000000

              (Your comment on this line doesn't match the setting. Comment says inputs, code sets outputs.)

              The port behavior on a 2-sec cycle sounds like the watchdog timer resetting the part. Test by disabling the watchdog in the config.
              Yeah, sorry.
              Because of all the testing and changing the comments are not valid anymore.
              As you will also see some subroutines are never called (like the register_display thingy.
              When I know what goes wrong I will scrap this file and start all over.

              My quess was also that something like the WDT was resetting the PIC.
              But when I wanted to reprogram the chip I had all these other programs.

              I am a bit confused.
              I am not to familiar how the chips are actually programmed.
              -
              Am I to understand that the Programming pins will take the values of actual TRISB setting in the program?
              So a PIC16F88 is in effect a PIC16C88 (OTP) when the previous program had TRISB=%00xxxxxx ?
              I checked and (by pure chance) my other programs, that have no problems, have all TRISB=%11xxxxxx

              Is there a way of undoing this ?

              Comment


              • #8
                Originally posted by Charles Leo View Post
                The program disables the reset pin and sets the programming clock and data pins to outputs. This usually locks out subsequent in-circuit programming attempts.

                If possible, maintain the programming pins (RB6/7) as inputs:

                TRISB=%11000000

                (Your comment on this line doesn't match the setting. Comment says inputs, code sets outputs.)

                The port behavior on a 2-sec cycle sounds like the watchdog timer resetting the part. Test by disabling the watchdog in the config.
                Hi Charles,
                You saved the day!
                I thought about your comment and found it rather convincing and logical so I chanced one of my last 2 PIC16F88's.
                Set TRISB to %11xxxxxxxx and programmed it.

                Guess what, problem solved!
                I can reprogram them!

                I just have to change PORTB.7/6 to inputs in my design and all is OK.
                I was just lucky that all these years PORTB was mainly inputs (remember the misleading remark "set to inputs" beside the TRISB statement in the program?)

                So if you make PGD- and/or PGC-pin an output you effectively create an OTP chip of your Flash device.
                Never knew that!
                Is there a way to undo that ?... I have 6 OTP PIC16F88 devices on my desk...

                Btw, I disabled the watchdog timer and the PORT behave normal now.

                Anyway, thank you very much for the good advice
                Have a nice weekend, Jan.

                Comment


                • #9
                  If you configure MCLR as a reset, the programmer can reset the part and cause the programming pins to become inputs momentarily to allow entry into programming mode. It's the combination of no reset and output conditions on the pins that lock you out.

                  The locked chips can usually be recovered if you place them in a programming adapter connected to one of our programmers. This allows the programmer to cycle Vdd as a substitute for reset. The lockout condition is evident when programming in-circuit with a constant Vdd voltage.
                  Charles Leo
                  ME Labs, Inc.
                  http://melabs.com

                  Comment

                  Working...
                  X