PDA

View Full Version : 16F628A current high during sleep



Rubicon
- 4th October 2006, 10:03
Hello,

I have a problem that I'm unfortunately unable to solve on my own.

16F628A with 4MHz Xtal and battery consumption is important.

With Timer1 running I have it set to go straight to a sleep subroutine upon startup with an IF/THEN cycle count compare and @sleep. When an interrupt occurs every 0.5 seconds it goes to the interrupt service routine, updates the cycle count and interrupt timing then back to sleep or every third cycle to the main program where it completes checks within the 0.5 seconds and goes back to the sleep subroutine. If the checks fail then it goes to a shutdown subroutine using the END command.

The thing is that during sleep I measure a current consumption of 1.2mA
while after shutdown it's 0.4mA - the current consumption of the voltage regulator. All the TRISA/PORTA/TRISB/PORTB settings are the same in both the sleep and the shutdown subroutines with voltage comparators turned off and a VRCON bit7 OFF for no current drain. I can't figure out why there's the difference in current.

Going through the archive I tried using a wire to ground through a resistor on the pins to observe the current, measuring the voltage on the pins directly, changing the old pic with a new one, altering TRISA/PORTA/TRISB/PORTB, removing Brown-out detect and all manner of other things to no avail. With older code I've now accidently overwritten that used no Timer1 or interrupts just an inaccurate overall cycle count it was 0.4mA during sleep. Taking practically everything out of the new code and making it just sleep imer1 and interrupts to see if it was them causing it it's still 1.2mA during the sleep cycle.

The only possible clue I have due to a small voltage on the Xtal pins is that the oscillator is still running when it should, I think, be off and using the watchdog timer. Actually pulling the Xtal out when in sleep reduces the current consumption to 0.5mA.

Even when reduced down to the code below it's still 1.2mA during sleep.

DEFINE OSC 4
@ DEVICE PIC16F628A
@ DEVICE PIC16F628A,XT_OSC
@ DEVICE PIC16F628A,WDT_ON
@ DEVICE PIC16F628A,PWRT_ON
@ DEVICE PIC16F628A,MCLR_ON
@ DEVICE PIC16F628A,BOD_OFF
@ DEVICE PIC16F628A,LVP_OFF
@ DEVICE PIC16F628A,CPD_OFF
@ DEVICE PIC16F628A,PROTECT_OFF


' HARDWARE
CMCON = 7 'Disable comparators
VRCON=%01101100 'VRCON bit7 is OFF for no current drain
TRISA = %10011
PORTA = 0
TRISB = %01000101
PORTB = %10000000 'PORTB outputs LOW but RB7 for it's wired directly to 555 trigger pin requiring a high to stop from triggering.

SOUND PORTA.3, [120,10]

CYCLE:
CMCON=7
VRCON=%01101100 'VRCON bit7 is OFF for no current drain
TRISA = %10011
PORTA = 0
TRISB = %01000101
PORTB = %10000000
@SLEEP 'ASM Sleep
GOTO CYCLE

Any help here is greatly appreciated.

Regards,

Rubicon.

Jerson
- 4th October 2006, 14:53
You will need to check if your port pins are going to the inactive state for any peripherals connected to them. for eg: if you have a transistor base via a resistor connected to a port pin, you will need to put this transistor off; ie: try to minimize all the external world drives. A schematic will help to clear this part. Otherwise, sleep should take the current around 40uA.

Jerson

Rubicon
- 6th October 2006, 23:53
Thanks for the reply and the advice.

I don't have a schematic as yet as it's all breadboarded and constantly changing as I learn new things. I really must do one though.

One thing I don't understand is why with the exact same port settings and commands @SLEEP is 1.2mA and END is 0.4mA. Shouldn't they be the same, either both 1.2mA or both 0.4mA?

CYCLE:
CMCON=7
VRCON=%01101100 'VRCON bit7 is OFF for no current drain
TRISA = %10011
PORTA = 0
TRISB = %01000101
PORTB = %10000000
@SLEEP 'ASM Sleep
GOTO CYCLE

SHUTDOWN:
CMCON=7
VRCON=%01101100 'VRCON bit7 is OFF for no current drain
TRISA = %10011
PORTA = 0
TRISB = %01000101
PORTB = %10000000
END

Regards,

Rubicon.

Jerson
- 7th October 2006, 06:35
I am not sure if you have seen this.

Excerpt from the datasheet of PIC16F917. I am sure this applies to the 628 too though I have not checked it.

<Quote>
When the SLEEP instruction is being executed, the next
instruction (PC + 1) is pre-fetched. For the device to
wake-up through an interrupt event, the corresponding
interrupt enable bit must be set (enabled). Wake-up is
regardless of the state of the GIE bit. If the GIE bit is
clear (disabled), the device continues execution at the
instruction after the SLEEP instruction. 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.
</quote>

Perhaps, you need to take care of this

Like this
@ sleep
@ nop
@ nop

I use this for my 628 programs and get the sleep operate correctly.

Jerson

Rubicon
- 7th October 2006, 19:03
Yes I admit to seeing that in the 16F628 datasheet and I tried a single nop without the @ after the sleep command without success. I'll put in what you suggest and see what happens today.

Thanks,

Rubicon.

Rubicon
- 9th October 2006, 10:21
Well that didn't work nor did trying it without the @. Back to looking at the pin states and doing a schematic.

Thanks for your help here. I do appreciate it.

Regards,

Rubicon.