Won't go back to SLEEP after 1st Interrupt


Closed Thread
Results 1 to 33 of 33

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Angry WDT_OFF didn't let it go to SLEEP after 1st Interrupt

    Thanks, Joe. I changed the @ _config to WDT_OFF and it lowered power consumption slightly during the operations while in the Int_Handler sequence, but MCU still doesn't go back into SLEEP mode after the 1st Interrupt is serviced....still at 1700 uamps as opposed to 400 uamps after power up into MAIN sequence.
    Anyone else have any ideas?

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


    Did you find this post helpful? Yes | No

    Default

    Yes, turn off the WDT ... and the BOR ... and the PORTAB Pull-Ups.
    400uA is too high for sleep mode.

    But the real problem is with ANSEL.
    As trivial as it might seem, I think this will make a huge difference.

    In the Main loop ...
    Code:
    ANSEL= %11110011
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Yes, turn off the WDT ... and the BOR ... and the PORTAB Pull-Ups.
    400uA is too high for sleep mode.

    But the real problem is with ANSEL.
    As trivial as it might seem, I think this will make a huge difference.

    In the Main loop ...
    Code:
    ANSEL= %11110011
    I have the demo board he's using, and found changing Tris to TRISA = %00001000 instead of all inputs helped too. Pinned out the ports and found the Ports A & B to be hot without turning WPUA & WPUB off, but as no load didnt affect sleep draw all that much, the thing is my trusty ElCheapo low impeadance $6.00 Chinese meter gives me much higher numbers than 400 µA , but it does indicate the change reliably.
    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.

  4. #4
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Some power reduction...still won't SLEEP after Interrupt

    Darrell and Joe, thanks so much for both of your inputs. I have experimented with your suggested changes and the lowest I was able to get the current to on Power Up was 350 microamps with the settings shown in my latest Main code excerpt listed below.
    Here is the experiment sequence I went thru and the resultant current loads as shown on my Micronta Multimeter:
    1) My Original Code + WDT_off: 400 microamps on powerup; settled to 1070 microamps after 1st interrupt sequence. (Note: all PortAB pullups were already off, as suggested by Darrell, in my original code by virtue of the OPTION_REG = %00111000 setting in my Initialization code)
    2) Previous 1) + BOR_OFF by setting BOR_SBODEN in _config and PCON.4 = 0 in MAIN: 350 microamps on powerup; settled to 1020 microamps after 1st interrupt service.
    3) Previous 2) + ANSEL=%1110011 as suggested by Darrell: no apparent changes...350 microamps on powerup; settled to 1020 microamps after 1st interrupt service. This was lowest case power achieved.
    l4) Previous 3) + TRISA = %00001000 as suggested by Joe: current on powerup went back up to 1020 microamps and settled to 1020 microamps after 1st interrupt service.
    Obviously Cases 2 & 3) were lowest power condition achieved by your suggested changes, but still in excess of what I expected, although the impedance of my meter may be making these reading higher than actual.

    However, none of these changes solved my real problem which is "how to get the MCU to return to SLEEP mode at same current as on powerup after the 1st interrupt service is processed". Although all apparent steps in the code stop after the 1st interrupt and it appears the MCU is in SLEEP, the current never returns to the lower power up condition.
    Neither of your comments mentioned anything that appeared in my code to be preventing return to the SLEEP mode in the MAIN loop after the 1st interrupt service. Any ideas????
    Code:
    ' -----[ Device Declaration ]----------------------------------------------
    ' For MSASM assembler use following:
    @ __config _INTRC_OSC_NOCLKOUT & _BOR_SBODEN  & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    ' For PM assembler only use following instead
    '@device pic16F690, intrc_osc_noclkout, _bor_sboden, pwrt_off, wdt_off, mclr_off,
    ' protect_off
    ' The above config  is inteded to set CONFIG = %0000110111010100 for hex 0DD4 or
    ' FCMEN on (1), IESO on(1), BOREN (01), CPD off (1), CP off (1), /MCLR is  
    ' digital input (0), /PWRTE off (1), WDTE off (0), INTOSCIO (100).                                                                           
    
    ' -----[ Declare Variables & Aliases ]-----------------------------
    '
    diff    VAR Byte      ' Difference between bat_mon and Vthr
    dummy   VAR Byte      ' For read of on-interrupt port & clear mismatch condition
    flush   VAR PORTA.3   ' Set RA3 as input for sensing flush switch closure Int
    i       VAR Byte      ' Index used in Gallon counter loop
    led1    VAR PORTC.0   ' Set RC0 as LED indicator of valve open..water flowing
    led2    VAR PORTC.1   ' Set RC1 as LED indicator of low battery
    bat_mon VAR PortA.0   ' Set RA0 as battery low power monitor
    meter   VAR PORTA.2   ' Set RA2 as input for Hall Sensor meter pulse Interrupt
    open_valve    VAR PORTC.2   ' Set RC2 as valve solenoid open command
    close_valve   VAR PORTC.3   ' Set RC3 as valve solenoid close command
    
    ' -----[ Declare Constants ]----------------------------------------
    '
     k             CON 10   ' Calibration factor for flow meter...# pulses per gal
     Vthr          CON 3    ' Assumes Low Battery Monitor threshold = 3 volts
     
    ' -----[ Initialization ]-------------------------------------------  
    Init: 
    ' Setup Timer0 as an 8-bit counter with the clock input on RA2.
    ' 1:1 TMR0 prescaler
    ' TMR0 counts on high-to-low transitions
      OPTION_REG = %00111000   ' PORTA/B pullups disabled, Interrupt on falling
                               ' edge of RA2/INT, TMR0 clock source is RA2,
                               ' increment on high-to-low transitions, prescaler to 
                               ' TMR0, TMR0 Rate 1:2
      TMR0 = 256 - k           ' preload TMR0 to overflow after k counts
      
    ' Initialization of inputs/outputs
      open_Valve = 0    ' Initialize RC2 (open_valve) at Low value
      close_valve = 0   ' Intialize RC3 (close_valve) at Low value
      TRISA.2 = 1       ' Set RA2 as input port for clock to TMR0
      TRISA.3 = 1       ' Set RA3 as input port for sensing Flush switch closure
      meter = 1         ' Initialize RA2 (meter) at High for METER pulse inputs
                        ' RA2 = TMR0 clock input for simulated meter pulse inputs
      flush = 1         ' Initialize RA3 (flush) at High value for flush interrupt
      
    ' Interrupts Settings
    FLUSH_INT_FLAG VAR INTCON.0 ' Alias RA3(FLUSH) On-change-interrupt flag bit
    TMR0_INT_FLAG VAR INTCON.2  ' Alias Timer0 overflow flag bit
    INTCON = %10101000          ' Enable interrupts: global, TMR0 overflow, & RABIE
    IOCA = %00001000            ' Enable RA3 as on-change-INT
    
    ' Set INT Handler
    ON INTERRUPT GOTO Int_handler   
    
    '-----[ Main Code Starts Here ]------------------------------------------------
    MAIN:
      ' Perform following steps to save power during Sleep mode
        OSCCON = %0100011   ' Switch to 1 MHz internal oscillator
        VRCON = %00100000   ' Set Voltage Reference for minimum power consumption
                            ' Disable CVref
        ANSEL= %11110011    ' Set PortA to Analog I/O to save power during Sleep but
                            ' leave Bits 2 & 3 as digital for RA2 pulse count
                            ' TMR0 overflow interrupt & RA3 On-Change intterupt.
        ANSELH= %11111111   ' Analog module enabled to save power during Sleep
        CM1CON0.7 = 0       ' Turn off comparators during Sleep
        CM2CON0.7 = 0
        PCON.4 = 0          ' Turn off BOR during Sleep
        WDTCON = %00010110  ' Turn WDT off to SLEEP indefinitely
        'TRISA = %00001000   ' Trick from Joe S. to reduce SLEEP power...why???
        TRISB = %11111111   ' Set all PORTB pins to inputs during Sleep
        TRISC = %11111111   ' Set all PORTC pins to input during Sleep
        PortA = %11111111   ' Write Port A all High to clear mismatch and save
                            ' power during SLEEP  
        PortB = %11111111   ' Set all Port B and C pins High to save power
        PortC = %11111111   ' in Sleep mode
        @ sleep                  
        ' Microcontroller is in Sleep State waiting for external FLUSH Interrupt
            ' Valve should be closed at this point and no water flowing
       GOTO Main    ' Loop to Main to wait for next Flush interrupt on RA3 change

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jellis00 View Post
    (Note: all PortAB pullups were already off, as suggested by Darrell, in my original code by virtue of the OPTION_REG = %00111000 setting in my Initialization code)
    Actually, when OPTION_REG.7 = 0, the pull-ups are ENABLED.
    A single pin with a 0V input can easily draw 250uA from the pull-up.

    Neither of your comments mentioned anything that appeared in my code to be preventing return to the SLEEP mode in the MAIN loop after the 1st interrupt service.
    That's what my ANSEL point was about.

    By turning ON/OFF the analog function on PORTA.3 (flush), you were inadvertently triggering PORTA change interrupts when no changes were made to the input state of the RA3 pin.
    That alone would cause it to lock up in the ISR.

    Perhaps there are more problems as well.
    For sure, there's an awful lot of stuff that doesn't need to be there.

    I will look further.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    And if AN3 had been on RA3 ... That might have made sense.

    But it isn't
    On a 690, it's on RA4, so my ANSEL point was stupid.

    Still looking though.
    <br>
    DT

  7. #7
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default Here are the current pinout assignments for your info

    To hopefully assist you in identifying why my code doesn't put the MCU into sleep after the execution of the 1st interrupt service, I am including here the pinouts in my current configuration. These are the same pinouts I had for the powere consumption summary of 4 cases I previously posted.
    Code:
    '------------------------- 16F690 Port Assignments ----------------------------
    ' I/O pin connections to the PIC16F690 MCU are as follows:
    ' PORTA.0 (19) RA0 connected as ICSPDAT when used for ICSP & also to a low
    '              battery monitor R/C circuit for normal ops.
    ' PORTA.1 (18) RA1 connected as ICSPCLK when used for ICSP.
    ' PORTA.2 (17) RA2 connected to external Flush contact limit switch which  
    '              connects to ground when activated and serves as On-change Interup   
    '              During testing connects to a grounded momentary-on switch on the
    '              PICkit2 board to simulate external limit switch On-change Interup
    ' PORTA.3 (04) RA3 connected during testing to an external flow meter to detect  
    '              flow meter pulse inputs. 
    '              During testing it connects to a grounded momentary-on switch  
    '              on the PICkit2 board as a clock input to TMR0 for counting of  
    '              pulses and as an overflow interrupt.   
    ' PORTA.4 (03) RA4 connected to pin 6 of the ICSP header for use in programming. 
    ' PORTA.5 (02) RA5 not connected.  
    ' PORTB.0 (  ) RB0 not connected. 
    ' PORTB.1 (  ) RB1 not connected.  
    ' PORTB.2 (  ) RB2 not connected. 
    ' PORTB.3 (  ) RB3 not connected.
    ' PORTB.4 (13) RB4 connected via a 10 ohm resistor to power the Wireless option. 
    ' PORTB.5 (12) RB5 connected to Hall Effect sensor circuit #2. 
    ' PORTB.6 (08) RB6 connected to Hall Effect sensor circuit #1.
    ' PORTB.7 (09) RB7 connected to pin R/T SEL on the TRM-XXX-LT transceiver.      
    ' PORTC.0 (11) RC0 connected as an output to an LED & is on when the valve 
    '              is opened.
    ' PORTC.1 (12) RC1 connected as an output to an LED & is on when battery is low.
    ' PORTC.2 (13) RC2 connected as an output to relay RL1 that actuates the   
    '              + latching line of a solenoid to open the valve.  
    '              During program testing on the PICkit2 demo board it is connected 
    '              to an LED to show when the pulse is sent.
    ' PORTC.3 (14) RC3 connected as an output to relay RL2 that actuates the   
    '              - latching line of a solenoid to close the valve.
    '              During program testing on the PICkit2 demo baord it is connected
    '              to an LED to show when the pulse is sent. 
    ' PORTC.4 (15) RC4 not connected.
    ' PORTC.5 (16) RC5 connected to pin PDN on the TRM-XXX-LT transceiver. 
    ' PORTC.6 (17) RC6 connected to pin RSSI on the TRM-XXX-LT transceiver. 
    ' PORTC.7 (18) RB7 connected to pin R/T SEL on the TRM-XXX-LT transceiver.
    
    ' -----[ Device Declaration ]----------------------------------------------
    ' For MSASM assembler use following:
    @ __config _INTRC_OSC_NOCLKOUT & _BOR_SBODEN  & _WDT_OFF & _MCLRE_OFF & _CP_OFF

Similar Threads

  1. Pin won't stay high during Repeat...Until loop??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th August 2009, 23:57
  2. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 07:12
  3. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  4. Using Sleep
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th August 2008, 04:05
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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