PIC keeps resetting when executing subroutine


Closed Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Dec 2003
    Location
    WI
    Posts
    13

    Default PIC keeps resetting when executing subroutine

    All,

    I am having problems with the below code when the subroutine warning is executed. PortA.0 is pulled high with a 1k. When the bin is full the limit switch pulls PortA.0 low. The buzzer and light will blink 2 times then the PIC will reset. I have used 2 different PIC's. - F84A and F819. Both PIC's do the same thing. 5V is solid and I have plenty of decoupling and bulk capacitance sprinkled throught the circuit. For the warning lamp and buzzer driver I use 1k to the base of a 2N4401 transistor's to drive the light and buzzer. I tried Tris statements and ADCON setup with the F819 with no help. I have tried HC and XT osc drive settings. Both parts are rated for 20MHz operation. I set power up timer to off and brownout off. All I want is the buzzer and light wo toggle 5 times then if the switch is still low at PORTA.0 then just have the binlight on until PORTA.0 hoes high. I'm about to smash this with a hammer soon as something this simple should not cause this much trouble.

    Any help here is appreciated.


    Code:
    '****************************************************************
    '*  Name    : Combine.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 8/15/09                                           *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
    define OSC 20
    
    'ADCON0 = %11000001
    'ADCON1 = %10001110
    
    'trisa = %00001110
    'trisb = %11110111
    
    binlight    var     porta.1
    buzzer      var     portb.2
    backup      var     porta.2
    alarm       var     byte
    
    define LCD_DREG PORTB
    DEFINE LCD_DBIT 4  
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 1
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 0
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
     
    low buzzer
    low binlight
    low backup
    
    PAUSE 500
    alarm = 0
    high buzzer
    high binlight
    high backup
    pause 500
    toggle buzzer
    toggle binlight
    toggle backup
    
    LCDOUT $FE,1
    LCDOUT $FE,$80, "TattleTale X"
    LCDOUT $FE,$C0, "   Monitor"
    pause 5000
    LCDOUT $FE,1
    
    monitor:
    
    LCDOUT $FE,$80, "  No Alarms"
    LCDOUT $FE,$C0, " "
    if alarm = 1 then
    goto light
    endif
    if PORTA.0 = 0 thEN
    alarm = 1
    GOsub warning
    ELSE 
    GOto monitor
    endif
    
    
    warning:
    LCDOUT $FE,1
    LCDOUT $FE,$80, " BIN FULL!!!"
    LCDOUT $FE,$C0, " "
    high binlight
    high buzzer
    pause 200
    toggle binlight
    toggle buzzer
    pause 200
    toggle binlight
    toggle buzzer
    pause 200
    toggle binlight
    toggle buzzer
    'pause 200
    'high binlight
    'high buzzer
    'pause 200
    'low buzzer
    'low binlight
    RETURN
    
    
    light:
    
    if PORTA.0 = 0 then
    high binlight
    else
    alarm = 0 
    GOTO monitor
    endif

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    monitor:
    LCDOUT $FE,$80, " No Alarms"
    LCDOUT $FE,$C0, " "
    if alarm = 1 then
    goto light
    endif

    if PORTA.0 = 0 thEN
    alarm = 1
    GOsub warning
    endif
    GOto monitor


    This might be better.

  3. #3
    Join Date
    Dec 2003
    Location
    WI
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    It still resets when the warning subroutine is run. I am going to try another computer to compile and generate the hex code. I am currently useing an ancient laptop with 98SE.

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


    Did you find this post helpful? Yes | No

    Default

    Just for fun, replace the tranistor driveres, buzzers, lamps with LEDs.
    Could still be a hardware problem and this will tell.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jbirnsch View Post
    I am currently using an ancient laptop with 98SE.
    All I use is win98se. Maybe you are browning out due to inadequate power supply.
    Last edited by Archangel; - 26th August 2009 at 04:56.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6
    Join Date
    Dec 2003
    Location
    WI
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    I can remove the buzzer and lamps by unplugging a connector and the PIC still resets as I can see what's going on with the LCD screen. I tried a different computer and the result is the same.....

  7. #7
    Join Date
    Dec 2003
    Location
    WI
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Maybe you are browning out due to inadequate power supply
    I checked that also with my scope. Power is solid.

    I am using a 2A DC/DC converter PT6212E-5 on my circuit board with plenty of bulk capacitance. I have used these parts on many of my other PIC projects without problems. I am using a 3S1P Lipoly battery pack that can supply 30A cont current for my 12V input until it can be installed. I am using PBP V2.46 with the patch installed and the latest beta programming software with my epic programmer. The epic software on CD V3.30 gives the same reset problem...

    Jason

  8. #8
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    I know the following is commented out, but not sure what is going on here:
    Code:
    'ADCON0 = %11000001
    'ADCON1 = %10001110
    
    'trisa = %00001110
    'trisb = %11110111
    You want to make sure all the analog inputs (ADC and Comparators) are set to digital. Also I think your TRIS directives are backwards (i.e. desired output are inputs and viceversa). Again this is commented out, but you should be defining these things at the beginning.

    Not sure what the real problem is, but somehow I think you are having a stack overflow.

    Try replacing the "GOsub warning" with "GOto warning"; and "RETURN" with "GOto monitor".

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    Try the attached file removing the .txt

    Also as languer noted, your TRIS set up is commended out. Why? According to your variables, there is a conflict with the TRIS settings. Perhaprs an input is not biased and seen as high or low irrelevant what you really do on the pin.

    Ioannis
    Attached Files Attached Files
    Last edited by Ioannis; - 26th August 2009 at 10:39.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Ioannis, I would also modify label light as per the attached code, because otherwise if portA.0 is zero then program will put high binlight and end.

    Code:
    light:
    if PORTA.0 = 0 then
    high binlight
    else
    alarm = 0 
    endif
    GOTO Monitor
    
    end
    Al.
    Last edited by aratti; - 26th August 2009 at 12:16.
    All progress began with an idea

  11. #11
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    Nice Al. I missed that!

    Ioannis

  12. #12
    Join Date
    Dec 2003
    Location
    WI
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    I will try this tonight when I get home from work.

    I had commented the ADCON out when I switch from a 16F819 to a 16F84A. The 84A does not have a A/D conveter.

    Having the TRIS commented or uncommented did not make a difference.

    If I cant get this to work I will switch to a SX28 processor. I have the code working on my DEV board with LED's with SX/B.

    Jason

  13. #13
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    It is absolutely necessary to define the state of the Inputs and Outputs. On Reset the controller set all pins as inputs.

    Give special attention as to which pins you define inputs and outputs. There are cases that pins are not only inputs but set as analog input too!

    So,

    1. Read with extreme attention to the details the datasheet for the MCU you use.

    2. Set if any analog/comparator inputs accordingly

    3. Set the pins as inputs and outputs (unused as outputs and unconnected)

    Ioannis

  14. #14
    Join Date
    Dec 2004
    Location
    USA
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Have you disabled the watchdog timer?

  15. #15
    Join Date
    Dec 2003
    Location
    WI
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Got it working. Thank's Ioannis and every one else. It must have been stack overflow. I'm getting rusty. Used to do 5 or 6 PIC projects a year but haven't done one in 2 years.

    Jason

  16. #16
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,806


    Did you find this post helpful? Yes | No

    Default

    You are welcome.

    Ioannis

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 10:00
  2. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 21:01
  3. PIC chip resetting. Very weird
    By The Master in forum Off Topic
    Replies: 0
    Last Post: - 28th October 2007, 17:07
  4. Pic resetting
    By malc-c in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 1st January 2007, 21:00
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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