Won't go back to SLEEP after 1st Interrupt


Closed Thread
Results 1 to 33 of 33

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    948


    Did you find this post helpful? Yes | No

    Default

    Jellis

    This may be totally irrelevant. How do you measure the sleep current? Are you measuring only the CPU current or the total circuit including all its peripherals. Maybe you are measuring the total current of all peripherals included. In that case, you should also look at the possibility that some peripheral is getting biased due to the active state of your PIC output to it.

    I have many devices in the field that use the sleep mode and the total system current is in the region of 40-100uA. 40uA is typical for the PIC. Rest should be related to your circuit and its peripherals.

    It will be helpful if you can post a schematic to assist in identifying your issue.

    Jerson

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Hi,Jerson

    You're right ...

    Code:
    ' Perform following steps to save power during Sleep mode
        OPTION_REG.7 = 1    ' Disable PortA/PortB pull-ups 
        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 = %00001101   ' Set RA0, RA2 & RA3 as inputs
        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
    seen any ADC power down in those lines ???

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default Measuring SLEEP Power

    Quote Originally Posted by Jerson View Post
    Jellis

    This may be totally irrelevant. How do you measure the sleep current? Are you measuring only the CPU current or the total circuit including all its peripherals. Maybe you are measuring the total current of all peripherals included. In that case, you should also look at the possibility that some peripheral is getting biased due to the active state of your PIC output to it.

    I have many devices in the field that use the sleep mode and the total system current is in the region of 40-100uA. 40uA is typical for the PIC. Rest should be related to your circuit and its peripherals.

    It will be helpful if you can post a schematic to assist in identifying your issue.

    Jerson
    I am measuring the SLEEP power by inserting in series my ampmeter at the Vcc input to the MCU. I am not measuring the circuit power to peripherals because they are either not connected during my test or for those that are powered by a pin from the PIC, they are shut down.

    I am also enclosing a copy of the schematic for my design, including peripherals, per your request. If you see any precautions I should take as far as setting interfaces to peripherals before SLEEP to save power, I would greatly appreciate your suggestions.
    Attached Images Attached Images  

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    948


    Did you find this post helpful? Yes | No

    Default

    Schematic is not really readable, but looks ok to me.

    I'd like to know if you can get proper sleep when you put the INTCON=% instruction just before the @sleep instruction : it clears the flags and sets up for the next interrupt.

    Another item which causes me a little worry is the RESUME main. Why shouldn't it resume where it interrupted??

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


    Did you find this post helpful? Yes | No

    Default Tried your suggestions

    Thanks for reply, Jerson.
    I tried both of your suggestions and don't see any change in current....350 microamps on power up and 350 microamps after ISR and return to SLEEP.
    It is getting frustrating to figure out why the SLEEP power is so high. I would suspect my ampmeter giving high readings except for the fact that when the ISR is running I see it fluctuating in current between about 1.200 and 4.4 milliamps, which is what I would expect during ops.
    Any additional suggestions greatly welcomed!

  6. #6
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    948


    Did you find this post helpful? Yes | No

    Default

    You need to keep the timer interrupt off till it is started by the FLUSH button press. Once you're done with the flushing, you should turn off the TIMER0 interrupt again before sleeping.

    Right now, the timer is interrupting even when it is not needed. That may be the cause .....

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


    Did you find this post helpful? Yes | No

    Default Tried your suggestions

    Thanks again Jerson for your help on this.
    I implemented your suggestions by keeping TMR0 disabled during the MAIN and Interrupt Service Routine until just before the IF-THEN block starts checking for pulse inputs from the FlowMeter. However, I see no changes in the current flow on PowerUp or on return to SLEEP after the ISR......350 microamps in both modes. I have included my latest code that includes these changes so you can see how I did it. If I didn't do it right, please advise.
    Still very frustrated on solving this problem.
    Code:
    ' -----[ Device Declaration ]----------------------------------------------
    ' For MSASM assembler use following:
    @ __config _INTRC_OSC_NOCLKOUT & _BOR_SBODEN  & _WDT_OFF & _MCLRE_OFF & _CP_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).   
      
    ' -----[ Revision History ]------------------------------------------------
    ' Version 1.0.7 on 6/21/09: Eliminated @ NOP in MAIN; Reformated Port
    '                           Assignments list; Changed IntCloc from 4 to 1 MHz;
    '                           WDT_OFF and comparators off to save power.
    ' Version 1.0.8 on 6/22/09: Changes to MAIN to minimize power during Sleep:  
    '                           Set BOR_SBODEN; set PCON.4 =0; ANSEL =%11110011, 
    '                           TRISA = %00001101..Set RA0, RA2 & RA3 as inputs in 
    '                           MAIN before SLEEP permits return to SLEEP after ISR.
    ' Version 1.0.9 on 6/25/09: Moved INTCON statement to just before SLEEP in MAIN.
    ' Version 1.0.10 on 6/27/09: Delayed turning on TMR0 until after Flush interrupt
    ' -----[ 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 enabled, 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 Setting Alias'
    TMR0_Enable VAR INTCON.5     ' Alias for On_Off switch of TMR0 counter
    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
    
    ' Set INT Handler
    ON INTERRUPT GOTO Int_handler   
    
    '-----[ Main Code Starts Here ]------------------------------------------------
    MAIN:
      ' Perform following steps to save power during Sleep mode
        OPTION_REG.7 = 1    ' Disable PortA/PortB pull-ups 
        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 = %00001101   ' Set RA0, RA2 & RA3 as inputs
        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
        ' Interrupt Settings
        INTCON = %10001000  ' Enable interrupts: global & RABIE, but TMR0 disabled
        IOCA = %00001000    ' before SLEEP.  Enable RA3 as on-change-INT
        @ 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
     
    '------{ Begin Interrupt Handler }---------------------------------------------
      DISABLE       ' Disable interrupts during interrupt handler
    Int_handler:                     
        OPTION_REG.7 = 0    ' Enable PortA/PortB Pullups                   
        WDTCON = %0001000   ' Turn WDT on for ops
        'Initialize registers for interrupt ops
      ' A/D & Comparators disabled
        ANSEL=0             ' Set PortA to digital I/O for use with RA2 and RA3
        ANSELH=0            ' Analog module disabled
        CM1CON0=0           ' Disable comparators
        CM2CON0=0 
      ' Port Settings
        TRISA = %11111111   ' Set all PORTA pins to inputs...RA0, RA2 & RA3 are used
        TRISB = %00000000   ' Set all PORTB pins to outputs
        TRISC = %11110000   ' Set lower 4 pins of PartB as outputs for LEDs
        PORTA = %00000000   ' PortA pins all set to Low
        PORTC = %00000000   ' LEDs off, PULSOUT RC3 provides a high-going pulse
        TMR0_Enable = 1     ' Enable the TMR0 pulse counter for overflow interrupt 
    
      IF FLUSH_INT_FLAG = 1 Then  ' Interrupt was from RA3 on change
        REPEAT
            ' Wait until the external Flush interrupt is at high level...limits
            ' interrupt to switch closure only and not also for switch opening 
        Until flush = 1 
        PULSOUT open_valve,2000*2   ' Generate 20 msec pulse to RC3 to open valve
        'HIGH led1              ' Light indicator that valve is open & water flowing  
        Write  7, flush        ' Write FLUSH value..remove comment for test only  
        ' Put code here to start a timer to run for 50 secs as a fail safe 
        ' to prevent overflow of toilet tank in case of sensor failure.
            'PULSOUT close_valve,2000 ' Generate 20 msec
                                      ' pulse to RC4 to close valve      
      Endif
      ' Valve is open and water is flowing
      REPEAT
            ' Wait for flow to reach 1.6 gallons
            ' Flash flow light while water flowinguntil pulse counter overflows
            High led1
            Pause 125/10
            Low led1
            Pause 500/10
            If diff > 2 Then   ' Battery is low..flash the low battery monitor light
                HIGH led2      ' while water is flowing
                PAUSE 125/10        
                Low led2
                Pause 500/10
            ENDIF                                            
            'Write 5, bat_mon  ' Remove comment for test only 
      Until TMR0_INT_FLAG = 1  ' Until flow meter pulse counter overflows
      PULSOUT close_valve,2000*2 ' Generate 20 msec pulse to RC4 to close valve  
      WRITE 11, TMR0_INT_FLAG ' Write TMR0 value..remove comment for test only
      dummy = flush            ' Clear mismatch condition                   
      FLUSH_INT_FLAG = 0       ' Clear interrupt flag & enable RA3 on interrupt
      TMR0_INT_FLAG = 0        ' Clear overflow flag
      TMR0 = 256 - k           ' Reload TMR0 to overflow after k counts
      RESUME                   ' Resume Main Program                 
      ENABLE   
      '-------{ End of Interrupt Handler }-----------------------------------------
          
        ' If the user program ends by getting to the last statement of the program
        ' at an END instruction, the MCU will SLEEP and await a wakeup.
    END

  8. #8
    Join Date
    Jan 2009
    Posts
    78


    Did you find this post helpful? Yes | No

    Default @ nop

    take a look..(DS41262C-page 210)

    "If the GIE bit
    is set (enabled), the device executes the instruction
    after the SLEEP instruction
    , then branches to the interrupt
    address (0004h). In cases where the execution of
    the instruction following SLEEP is not desirable, the
    user should have a NOP after the SLEEP instruction"

    ...did you try

    @ sleep
    @ nop

    ?

    I'm not expert neither....

  9. #9
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    948


    Did you find this post helpful? Yes | No

    Default

    Jellis

    Can you try it this way ? What I'm suggesting is to clear the mismatch, enable the mismatch interrupt and then sleep

    Code:
        IOCA = %00001000    ' Enable RA3 as on-change-INT ***this could be made permanent before main***
        ' clear the mismatch condition
        dummy = flush
        INTCON = %10001000  ' Enable interrupts: global & RABIE, but TMR0 disabled ** and RABIF is cleared **
        @ 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

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