PDA

View Full Version : Status after @ SLEEP Command



sayzer
- 14th June 2011, 12:30
Hi There,

I am using " @ SLEEP" and processor wakes up when Int RB0 pin goes high.
After the wake up, my lcd is behaving weird.

If I use, DT's instant interrupt, it works as expected; if I only use Int flag and intcon enable bit to go to sleep and wake up from there, then I get LCD issue.

What register should I take care of?
Before getting into sleep, I used "CLEAR" but this time, RB0 int pin does not see 1 or 0. Like it is not even an input pin.

Thank you.

cncmachineguy
- 14th June 2011, 12:40
Hi Sayzer, There are likely several possible causes. The first that comes to mind is context saving. Depending on what chip you are using, it is not done automaticly for you. Have a look at the interrupt section of the datasheet.

DT_INT tends to context saving for you which is one of the things that make it so easy to use and powerful. :)

sayzer
- 14th June 2011, 14:07
Hi Bert,

Actually, there is no interrupt routine.
And I can not use DTs instant int. routine because the pic is almost full.
No more space.

I am using 16F628A.
there is a button on RB0.

PIC is always in sleep using @ SLEEP

When the pin goes high, PIC turns on LCD (LCD Vdd pin is connected to PIC pin, draws 2mA).

All works ok with DTs routine.
But, since I onlly need to wake up the PIC, DTs routine is too much to use for code saving purposes.
So I use the traditional way.



OPTION_REG.6 = 1 ' Int on rising edge.
INTCON = %00010000
IntFlag VAR INTCON.1



Using intflag here, system wakes up ok.
Turns on LCD ok.
But what on LCD is not correct.
random things.

Again, all works ok with DTs.

Bruce
- 14th June 2011, 15:13
If you power down the LCD before sleep you will need to reinitialize it on wakeup. Try placing flags = 0 just before @ SLEEP so PBP will reinitialize it first.

Or, if you're using an external oscillator, you might need a short delay after wakeup for it to stabilize before sending data to the display.

mister_e
- 14th June 2011, 17:52
motion seconded

sayzer
- 14th June 2011, 20:19
If you power down the LCD before sleep you will need to reinitialize it on wakeup. Try placing flags = 0 just before @ SLEEP so PBP will reinitialize it first.

Or, if you're using an external oscillator, you might need a short delay after wakeup for it to stabilize before sending data to the display.

Thank you Bruce.

I am using internal osc.

Here is my simplified code.

Would you please indicate where do I need to put the flags and what exactly o I need to do?
IF I put CLEAR command before sleep, it helps but does not solve the issue completely.




LCDVdd var PORTA.0
Switch var PORTB.0
Input switch ' An external 220K is tied to Vdd. Draws approx. 0.12mA.
OPTION_REG.6 = 1 ' Int on rising edge.
INTCON = %00010000
IntFlag VAR INTCON.1
START:

low lcdvdd ' Turn off lcd.

' Keep all pins low to draw minimum current.
low LCD_DB5
low LCD_DB6
low LCD_DB7
low LCD_RS
low LCD_E

IntFlag = 0
@ SLEEP ; Sleeping now. If switch is released, then processor will wake up.
@ NOP
high lcdvdd ' Power up LCD.
pause 250 ' LCD wakes up.

ChkBtn:
lcdout $fe,1,"Test"
pause 1000


if Switch then chkbtn ' Loop until Switch is down.
' Here, switch is down now.

goto start

Bruce
- 14th June 2011, 23:11
Try placing FLAGS = 0 just before @ SLEEP.

mister_e
- 15th June 2011, 02:17
From the manual...


The LCD is initialized the first time any character or command is sent to it using LCDOUT. If it is powered down and then powered back up for some reason during operation, an internal flag can be reset to tell the program to reinitialize it the next time it uses LCDOUT:


FLAGS = 0

FLAGS = 0 is a lost children feature... but documented :D

sayzer
- 17th June 2011, 14:10
Thank you Bruce. Problem disappeared.

Steve, lost child saved a life.