[Icc-avr] Interrupt Help Please (Happy New Year)
Andrew
andrew_166 at msn.com
Thu Jan 3 06:27:35 PST 2008
Hi john/anybody ,
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.
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.
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: -
CODE
NOTE : -
#define USB_CONNECTED (PIND & 0x01)
#define BAT_CONNECTED (PIND & 0x02)
are defined in a sepearte c file.
void sleep(void);
void wake(void);
//-----------------------------------------------------------------------------
//
// Function name : Sleep
//
// Returns : None
//
// Parameters : None
//
// Purpose : Send the processor into sleep mode (Low power)
//
//-----------------------------------------------------------------------------
void sleep(void)
{
SPCR = 0x00; // Power Down the SPI
UCSRB = 0x00; // NOT FOUND THIS IN THe DATASHEET
REGCR = 0x01; // Disable the USB Regulator
RTC_POWER_OFF // Turn the Power too the RTC OFF (PORTD4)
EICRA = 0x08; // Change INT1 Pin Interrupt to Falling Edge (INT1)
PRR1 = 0x81; // Turn Off the USB and USART using the power reduction register
SMCR = 0; // Clear SMCR Register
SMCR = 0x05; // Configure Sleep Register for Deep Sleep
asm("sleep"); // Put Processor into Deep Sleep
}
//-----------------------------------------------------------------------------
//
// Function name : Wake
//
// Returns :
//
// Parameters :
//
// Purpose : Return from Sleep mode and restart devices
//
//-----------------------------------------------------------------------------
void wake (void)
{
PRR1 = 0x00; // Restart the USB from Power Reduction Mode
EICRA = 0x0C; // Change the Battery on pin to interrupt on rising edge (INT1)
RTC_POWER_ON // Turn the RTC Power Supply back on (PORTD4)
UCSRB = 0x98; // HAVE NO IDEA WHAT THIS REGISTRY IS FOR
SPCR = 0x5C; // Restart the SPI
Usb_enable_regulator(); // Enable the USB regulator
}
//-----------------------------------------------------------------------------
// Main Program Loop
//-----------------------------------------------------------------------------
void main(void)
{
init_devices(); // Initilise all the devices
Usb_enable_regulator(); // Enable the USB Regulator
usb_scheduler_init(); // Set up the USB Scheduler
while (1)
{
if(USB_CONNECTED) // If the USB Connected Pin is High
{
usb_scheduler_tasks(); // Schedule the USB tasks
}
if(BAT_CONNECTED) // If the Battery Connected Pin is high
{
sleep(); // Call the Sleep function
NOP(); // Small Delay
NOP(); // Small Delay
wake(); // Wake from Sleep and restart USB and SPI
}
}
}
Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20080103/2df00386/attachment.html
More information about the Icc-avr
mailing list