<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16587" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial>Hi john/anybody ,</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>I have a intresting/anoying problem. to recap. I have an
AT90USB162. i am basically trying to send the processor to sleep if Bit 1 on
PORTD is high and wake when the PIN goes low. The basically tells the processor
it has lost main power and is now running on a battery.</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>I have the code working well and i am getting 7.12uA when
the Processor is asleep.and my pin interrupt routine works and wakes the
processor if PORTD BIT1 is low and returns back to the 7.12uA when PORTD BIT1 is
high. The problem i have is when i pug the USB in. This also has the same
effect on PORTD BIT 1 as it now takes over powring the system from the battery.
</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>So as before if the USB connector is pugged in PORDT BIT 1
goes low and the processor resumes from sleep. this also works and i can
use the USB port as a serial emulator using some atmel exmaple code. The probelm
comes when i unplug the USB connector. Which sends PORTD BIT 1 high
and thus the processor goes to sleep but it only goes down to 119uA not the
7.12uA i was getting before. I have checked and the processor is asleep as
the external oscillator is turnned off. So some part of the USB must
be still enabled. Can anybody suggest a solution: -</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>CODE</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>NOTE : - </FONT></DIV>
<DIV><FONT size=3>
<P>#define USB_CONNECTED (PIND & 0x01)<BR>#define BAT_CONNECTED (PIND &
0x02)</P>
<P>are defined in a sepearte c file.</P></FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><B><FONT size=3>
<P>void</B> sleep(<B>void</B>);<BR><B>void</B>
wake(<B>void</B>);<BR><BR></FONT><FONT color=#008000
size=3>//-----------------------------------------------------------------------------</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>//</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>// Function name :
Sleep</FONT><FONT size=3><BR></FONT><FONT color=#008000 size=3>//</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>// Returns : None</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>//</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>// Parameters : None</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>//</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>// Purpose : Send the processor
into sleep mode (Low power)</FONT><FONT size=3><BR></FONT><FONT color=#008000
size=3>//</FONT><FONT size=3><BR></FONT><FONT color=#008000
size=3>//-----------------------------------------------------------------------------</FONT><FONT
size=3><BR><B>void</B> sleep(<B>void</B>)<BR>{<BR><BR>SPCR =
0x00;
</FONT><FONT color=#008000 size=3>//
Power Down the SPI</FONT><FONT size=3><BR>UCSRB = 0x00;
</FONT><FONT
color=#008000 size=3>// NOT FOUND THIS IN THe DATASHEET </FONT><FONT
size=3><BR><BR>REGCR = 0x01; <FONT color=#008000>
</FONT></FONT><FONT
color=#008000 size=3>// Disable the USB Regulator</FONT><FONT
size=3><BR>RTC_POWER_OFF </FONT><FONT color=#008000 size=3>
// Turn the Power too the RTC OFF (PORTD4) </FONT><FONT
size=3><BR><BR>EICRA = 0x08;
</FONT><FONT color=#008000 size=3>//
Change INT1 Pin Interrupt to Falling Edge (INT1)</FONT><FONT size=3><BR><BR>PRR1
= 0x81;
</FONT><FONT color=#008000 size=3>// Turn
Off the USB and USART using the power reduction register</FONT><FONT
size=3><BR><BR>SMCR = 0; <FONT color=#008000>
</FONT></FONT><FONT color=#008000 size=3>// Clear SMCR
Register </FONT><FONT size=3><BR>SMCR = 0x05; <FONT
color=#008000> </FONT></FONT><FONT
color=#008000 size=3>// Configure Sleep Register for Deep Sleep</FONT><FONT
size=3><BR>asm(<I>"sleep"</I>); <FONT color=#008000>
</FONT></FONT><FONT color=#008000 size=3>// Put Processor into Deep
Sleep</FONT><FONT size=3><BR><BR>}<BR><BR></FONT><FONT color=#008000
size=3>//-----------------------------------------------------------------------------</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>//</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>// Function name : Wake</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>//</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>// Returns : </FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>//</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>// Parameters : </FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>//</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>// Purpose : Return from Sleep mode
and restart devices</FONT><FONT size=3><BR></FONT><FONT color=#008000
size=3>//</FONT><FONT size=3><BR></FONT><FONT color=#008000
size=3>//-----------------------------------------------------------------------------</FONT><FONT
size=3><BR><B>void</B> wake (<B>void</B>)<BR>{<BR>PRR1 = 0x00; <FONT
color=#008000>
</FONT></FONT><FONT color=#008000 size=3>// Restart the USB
from Power Reduction Mode</FONT><FONT size=3><BR>EICRA = 0x0C; </FONT><FONT
color=#008000 size=3>
// Change the Battery on pin to interrupt on rising
edge (INT1)</FONT><FONT size=3><BR>RTC_POWER_ON <FONT
color=#008000> </FONT></FONT><FONT
color=#008000 size=3>// Turn the RTC Power Supply back on (PORTD4)</FONT><FONT
size=3><BR><BR>UCSRB = 0x98; <FONT color=#008000>
</FONT></FONT><FONT
color=#008000 size=3>// HAVE NO IDEA WHAT THIS REGISTRY IS FOR</FONT><FONT
size=3><BR>SPCR = 0x5C; <FONT color=#008000>
</FONT></FONT><FONT
color=#008000 size=3>// Restart the SPI </FONT><FONT
size=3><BR>Usb_enable_regulator();<FONT color=#008000>
</FONT></FONT><FONT color=#008000 size=3>// Enable the USB regulator</FONT><FONT
size=3><BR>}<BR><BR></FONT><FONT color=#008000
size=3>//-----------------------------------------------------------------------------</FONT><FONT
size=3><BR></FONT><FONT color=#008000 size=3>// Main Program Loop</FONT><FONT
size=3><BR></FONT><FONT color=#008000
size=3>//-----------------------------------------------------------------------------</FONT><FONT
size=3><BR><B>void</B> main(<B>void</B>)<BR>{ <BR>init_devices(); <FONT
color=#008000>
</FONT></FONT><FONT color=#008000 size=3>// Initilise all the
devices </FONT><FONT size=3><BR><BR>Usb_enable_regulator(); </FONT><FONT
color=#008000 size=3>// Enable the USB Regulator</FONT><FONT
size=3><BR>usb_scheduler_init(); <FONT
color=#008000> </FONT></FONT><FONT color=#008000
size=3>// Set up the USB Scheduler</FONT><FONT size=3><BR><BR><B>while</B>
(1)<BR>{ <BR><BR><B>if</B>(USB_CONNECTED) </FONT><FONT color=#008000 size=3>//
If the USB Connected Pin is High</FONT><FONT
size=3><BR>{<BR>usb_scheduler_tasks();<FONT color=#008000>
</FONT></FONT><FONT color=#008000 size=3>// Schedule the USB tasks </FONT><FONT
size=3><BR>}<BR><BR><B>if</B>(BAT_CONNECTED)<FONT color=#008000>
</FONT></FONT><FONT color=#008000 size=3>// If the Battery Connected Pin is high
</FONT><FONT size=3><BR>{<BR>sleep(); </FONT><FONT color=#008000 size=3>// Call
the Sleep function</FONT><FONT size=3><BR>NOP(); </FONT><FONT color=#008000
size=3>// Small Delay </FONT><FONT size=3><BR>NOP(); </FONT><FONT color=#008000
size=3>// Small Delay</FONT><FONT size=3><BR>wake(); </FONT><FONT color=#008000
size=3>// Wake from Sleep and restart USB and SPI</FONT><FONT
size=3><BR><BR>}<BR><BR>}<BR>}<BR></P></FONT></DIV>
<DIV><FONT face=Arial size=2> Andy</FONT></DIV></BODY></HTML>