Pic gets lost after power outage


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2008
    Posts
    52

    Default Pic gets lost after power outage

    Hello,

    I have a program that uses two comparators and Timer0. It is supposed to turn off the led when the voltage from the bridge rectifier drops below Comparator 2 and turn on when it >= Comparator 1. It seems to work like it is supposed to except when the voltage stays below Comparator 2 reference until the super cap discharges and the pic actually shuts down. When the voltage comes back to turn both comparators on the program seems lost. If you vary the voltage above and below Comp1 and Comp2 reference, the program works again. I have tied MCLR to Vdd thru 1k. I have posted the code below. Does anybody know whats going on? Pic is an 18F4550

    Thanks Don

    Code:
    OSCCON = $60                    'Set up oscillator 4mhz
    CMCON = %00000101
    TRISB = %01000000               'Set port B to output
    TRISA = %11001111               'Set port A to input
    T0CON = %01000110               'Set up Timer 0 Config bits prescale 128
    INTCON.6 = 1                    'Enable all unmasked peripheral interrupts
    RCON.7 = 0                      'Disable interrupt priority
    Intcon.5 = 1                     'Timer 0 overflow interrupt enable bit
    
    
    '**  While the output of Cout1 and Cout2 is 0 (Bridge Rectifier voltage is 
    '**  greater than reference) this loops in the While Wend. If one or the
    '**  other changes to a 1 which it does every pulse unless the    
    '**  voltage drops below reference for longer than 20 ms in which case
    '**  Intcon.2  bit is set, it drops down and reloads the timer and loops 
    '**  back to Main. 
                                 
    
    Main:
    TMR0L = $64                    'Preload Timer0 to overflow after 20ms 
    T0con.7 = 1                    'Start Timer0
    Intcon.2 = 0                   'Clear Timer0 overflow interrupt bit
       
    While CMCON.6 = 0 and CMCON.7 = 0  'If it stays in this loop longer than 20ms 
                                       'Intcon.2 bit is set
    
          if Intcon.2 = 1 then gosub Led 'If this bit is set, Timer0 has overflowed 
                                   'meaning Cout1 and Cout2 has remained low for
                                   'longer than 20ms and branches to Led. 
    wend  
          TMR0L = $64              'Reload Timer0 to overflow after 20ms 
          goto main
          
          
    LED:
          Low portb.4             'Turn off Led to signify outage
          Intcon.2 = 0             'Reset Timer0 overflow bit
          
          While CMCON.6 = 0                   'If the voltage is below Comparator 1 
                                              'reference or between Comparator 1 and
                                              'Comparator 2 the program loops here  
                                              'until voltage rises enough to turn on 
                                              'Comparator 1. 
          wend
                                      
          high portb.4              'Turn on Led to signify power on
    return                               
     
    
    End

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Configuration fuses?

    Vdd=?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Oct 2008
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Confiuration fuses and Vdd

    Hi Steve,

    This is the configuration:

    Code:
          NOLIST
        ifdef PM_USED
            LIST
            "Error: PM does not support this device.  Use MPASM."
            NOLIST
        else
            LIST
            LIST p = 18F4550, r = dec, w = -311, f = inhx32
            INCLUDE "P18F4550.INC"	; MPASM  Header
            ;CONFIG    PLLDIV = 1 
            CONFIG    FOSC = INTOSCIO_EC
            CONFIG    WDT = OFF
            CONFIG    PBADEN = OFF
            CONFIG    LVP = off 
            CONFIG   WRTB = ON
            CONFIG    CPB = off
            CONFIG    MCLRE = On
            NOLIST
        endif
            LIST
    EEPROM_START	EQU	0F00000h
    BLOCK_SIZE	EQU	32
    As for Vdd, It slowly goes down as the Super Cap bleeds down (The program needs to perform a couple of other things when the power goes out and the Super Cap is still holding voltage) I don't have this part written yet. When the power comes back on, Vdd comes back while charging the Super Cap up.

    Thanks, Don

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Enable the PowerUp timer and see how bad/good it is.

    Then try to play with different BOR voltage, for now it's 'round 2V.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Pic getting part power from Analog Port
    By ShaneMichael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 22nd April 2009, 10:34
  2. Ideal backup power for PIC micro
    By emavil in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd March 2007, 00:07
  3. PIC power backup with "super capacitor"
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 24th January 2007, 23:51
  4. problems on power up of PIC
    By dmairspotter in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th June 2006, 14:11
  5. Controlling power to a PIC with another PIC
    By jswayze in forum Off Topic
    Replies: 3
    Last Post: - 28th May 2005, 19:44

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