示例#1
0
/*function to turn off all periferlas of the radian as well as to send uC into low power mode
in the event of a low battery condition
 */
void Radian_power_saver::EnterDeepSleepMode(){
    POWER_OFF;
    if(DEBUG) Serial.println("Entering Deep Sleep Mode");
    //Disable ADC and internal Vref
    digitalWrite(BOOST_EN, LOW);
    POWER_OFF;
    ADMUX &= ~( (1<<REFS1) | (1<<REFS0) );
    ADCSRA &= ~( (1<<ADEN) );
    
    //Disable AnalogComparator
    ACSR |= (1<<ACD); 
    
    DIDR0 = 0xFF;
    //  DIDR1 = 0xFF;
    DIDR2 = 0xFF;
    
    
    
    //disable watchdog timer
    cli();
    wdt_reset();
    // Clear WDRF in MCUSR 
    MCUSR &= ~(1<<WDRF);
    MCUCR |= (1<<JTD);//disable on chip debug system by writing 1 to JTD bit in MCUCR
    // Write logical one to WDCE and WDE 
    // Keep old prescaler setting to prevent unintentional time-out
     
    WDTCSR |= (1<<WDCE) | (1<<WDE);
    // Turn off WDT 
    WDTCSR = 0x00;
    
    //disable port pins by writing to digital input disable register DIDR1
    
    //disable USB
    PRR0 = 0xFF; //turn off all periferals in the power reduction registers
    PRR1 = 0xFF; 
    
    wdt_disable();
    //bod_disable();
    power_usart0_disable();
    power_usart1_disable();
    power_spi_disable();
    power_adc_disable();
    power_all_disable();
    POWER_OFF;
    cli(); //disable all interrupts
    SMCR = B00000101; //enable sleep mode (bit0 set) and set to POWER DOWN mode (lowest consumption)
    sleep_mode(); //go into sleep
    
    
    
}
示例#2
0
/*********************************************************************************************************
** Function name:           pwrDown
** Descriptions:            pwrDown
*********************************************************************************************************/
void xadow::pwrDown(unsigned long tSleep)
{
#if defined(__AVR_ATmega32U4__)
    power_adc_disable();
    power_usart0_disable();
    power_spi_disable();
    power_twi_disable();
    power_timer1_disable();
    power_timer2_disable();
    power_timer3_disable();
    power_usart1_disable();
    power_usb_disable();
#endif
    sleep.pwrDownMode();        //set sleep mode
    sleep.sleepDelay(tSleep);   //sleep for: sleepTime
}
示例#3
0
//---------------------------------------------------------------------------
void SysInit(void)
{
	power_timer2_disable();
	power_adc_disable();
	power_twi_disable();
	power_usart0_disable();
	power_usart1_disable();

	OledInit();
	FrameInit();
	SndInit();
	EepInit();
	KeyInit();
	MathInit();
	RndInit();
	DebugInit();
}
示例#4
0
void	Low_Power::idle(Period_t period, ADC_t adc,
                        Timer4_t timer4, Timer3_t timer3,
                        Timer1_t timer1, Timer0_t timer0,
                        SPI_t spi, USART1_t usart1,	TWI_t twi, usb_t usb)
{
    if (adc == ADC_OFF)
    {
        ADCSRA &= ~(1 << ADEN);
        power_adc_disable();
    }

    if (timer4 == TIMER4_OFF)	power_timer4_disable();
    if (timer3 == TIMER3_OFF)	power_timer3_disable();
    if (timer1 == TIMER1_OFF)	power_timer1_disable();
    if (timer0 == TIMER0_OFF)	power_timer0_disable();
    if (spi == SPI_OFF)				power_spi_disable();
    if (usart1 == USART1_OFF)	power_usart1_disable();
    if (twi == TWI_OFF)				power_twi_disable();
    if (usb == USB_OFF)				power_usb_disable();

    if (period != SLEEP_FOREVER)
    {
        wdt_enable(period);
        WDTCSR |= (1 << WDIE);
    }

    lowPowerBodOn(SLEEP_MODE_IDLE);

    if (adc == ADC_OFF)
    {
        power_adc_enable();
        ADCSRA |= (1 << ADEN);
    }

    if (timer4 == TIMER4_OFF)	power_timer4_enable();
    if (timer3 == TIMER3_OFF)	power_timer3_enable();
    if (timer1 == TIMER1_OFF)	power_timer1_enable();
    if (timer0 == TIMER0_OFF)	power_timer0_enable();
    if (spi == SPI_OFF)				power_spi_enable();
    if (usart1 == USART1_OFF)	power_usart1_enable();
    if (twi == TWI_OFF)				power_twi_enable();
    if (usb == USB_OFF)				power_usb_enable();
}
示例#5
0
int main(void)
{

	unsigned char tmp;
	
	wdt_disable();		/* Disable watchdog if enabled by bootloader/fuses */
	power_usb_disable() ;
	power_usart1_disable();
	power_spi_disable();
	
	Buttons_Init();
	LEDs_Init();
	clock_prescale_set(clock_div_1);	// run at x-tal frequency 16Mhz
	
	
	eeprom_read_block( &EE_data,0,sizeof(EE_data));
		
	if (EE_data.bright_level == 0xff && EE_data.dim_level == 0xff)
	{
		EE_data.bright_level = LED_BRIGHT;
		EE_data.dim_level = LED_DIMM;
		eeprom_write_block(&EE_data,0,sizeof(EE_data));
		eeprom_busy_wait();
	}
	
	OCR0A = EE_data.bright_level;
	OCR0B = EE_data.dim_level;

	// Timer 0 setup for simple count mode, used as timebase LED PWM
	TCCR0A = 0;		// simple count more 		
	TCCR0B = 4;		// system Clock 16Mhz/256 = 16us per counter tick 
	//TCCR0B = 3;		// system Clock 16Mhz/64 = 4us per counter tick 
	//TCCR0B = 5;		// system Clock 16Mhz/1024 = 64us per counter tick 
	//TCCR0B = 2;		// system Clock 1Mhz/8 = 8us per counter tick 
	TIMSK0 = 0x7;	// Enable OverFLow , OCR0A and OCR0B interrupt enables
	
	MCUSR =0; //MCU status register clear 
	
	// Timer 1 setup for  fast PWM mode for servo pulse generation 1 to 2ms 

	TIMSK1 = 0x2;		// Enable OCR1A interrupt 
	TCCR1A = 0x00;		// No pin toggles on compare -- CTC (normal) mode
	TCCR1B = 0x0D;		// CTC mode, F_CPU 16mhz/1024 clock ( 64us)
	//TCCR1B = 0x0B;		// CTC mode, F_CPU 1Mhz/64 clock ( 64us)
	OCR1A = 15625-1;	// counting 15625 counts of 64 us == 1 second

	sei();
		
    while(1)	// for ever
    {
		
		if (IsButtonPressed(BUTTON1) )
		{

			// de-bounce -- 10 consecutive reads of switch open 
			for (tmp =0; tmp<=10; tmp++)
			{
				_delay_ms(2);
				if (IsButtonPressed(BUTTON1))
					tmp = 0;
			}
			
			if ( mode < 3)
				mode++;
			else
			{
				eeprom_write_block(&EE_data,0,sizeof(EE_data));
				eeprom_busy_wait();
				mode = 0; // enter running mode
			}				
		
		}			
				
		if (IsButtonPressed(BUTTON2) ) // increases Minutes and decrease brightness 
		{

			// de-bounce -- 10 consecutive reads of switch open
			for (tmp =0; tmp<=10; tmp++)
			{
				_delay_ms(2);
				if (IsButtonPressed(BUTTON2))
				tmp = 0;
			}
			
			switch (mode) 
			{
				case 1:
					Minutes++;
					ripple();
					break;
					
				case 2:
					if (OCR0B < 0xff )		// dim level
					{
						OCR0B++;
						EE_data.dim_level = OCR0B;
					}						
					break;
					
				case 3:						// bright level
					if (OCR0A < OCR0B-10  )		// make sure that bright is at least 10 counts brighter than dim
					{
						OCR0A +=10;				// step in increments of 10
						EE_data.bright_level =OCR0A;
					}						
					break;
			}			
			
		}	
		
		if (IsButtonPressed(BUTTON3) )	// Increases Hours and increase brightness
		{

			// de-bounce -- 10 consecutive reads of switch open
			for (tmp =0; tmp<=10; tmp++)
			{
				_delay_ms(2);
				if (IsButtonPressed(BUTTON3))
				tmp = 0;
			}
						
			switch (mode)
			{
				case 1:
					Hours++;
					ripple();
					break;
					
				case 2:
					if (OCR0B > OCR0A+10)		// dim level
					{	

						OCR0B--;
						EE_data.dim_level = OCR0B;
					}						
					break;
					
				case 3:						// bright level
					if (OCR0A > 20)	
					{
						OCR0A -=10;		//step in increments of 10
						EE_data.bright_level =OCR0A;
					}						
					break;
			}
		}
				
    } // end of for-ever
}
示例#6
0
void	Low_Power::idle(Period_t period, ADC_t adc, Timer5_t timer5,
                        Timer4_t timer4, Timer3_t timer3, Timer2_t timer2,
                        Timer1_t timer1, Timer0_t timer0, SPI_t spi,
                        USART3_t usart3, USART2_t usart2, USART1_t usart1,
                        USART0_t usart0, TWI_t twi)
{
    // Temporary clock source variable
    unsigned char clockSource = 0;

    if (timer2 == TIMER2_OFF)
    {
        if (TCCR2B & CS22) clockSource |= (1 << CS22);
        if (TCCR2B & CS21) clockSource |= (1 << CS21);
        if (TCCR2B & CS20) clockSource |= (1 << CS20);

        // Remove the clock source to shutdown Timer2
        TCCR2B &= ~(1 << CS22);
        TCCR2B &= ~(1 << CS21);
        TCCR2B &= ~(1 << CS20);

        power_timer2_disable();
    }

    if (adc == ADC_OFF)
    {
        ADCSRA &= ~(1 << ADEN);
        power_adc_disable();
    }

    if (timer5 == TIMER5_OFF)	power_timer5_disable();
    if (timer4 == TIMER4_OFF)	power_timer4_disable();
    if (timer3 == TIMER3_OFF)	power_timer3_disable();
    if (timer1 == TIMER1_OFF)	power_timer1_disable();
    if (timer0 == TIMER0_OFF)	power_timer0_disable();
    if (spi == SPI_OFF)			  power_spi_disable();
    if (usart3 == USART3_OFF)	power_usart3_disable();
    if (usart2 == USART2_OFF)	power_usart2_disable();
    if (usart1 == USART1_OFF)	power_usart1_disable();
    if (usart0 == USART0_OFF)	power_usart0_disable();
    if (twi == TWI_OFF)			  power_twi_disable();

    if (period != SLEEP_FOREVER)
    {
        wdt_enable(period);
        WDTCSR |= (1 << WDIE);
    }

    lowPowerBodOn(SLEEP_MODE_IDLE);

    if (adc == ADC_OFF)
    {
        power_adc_enable();
        ADCSRA |= (1 << ADEN);
    }

    if (timer2 == TIMER2_OFF)
    {
        if (clockSource & CS22) TCCR2B |= (1 << CS22);
        if (clockSource & CS21) TCCR2B |= (1 << CS21);
        if (clockSource & CS20) TCCR2B |= (1 << CS20);

        power_timer2_enable();
    }

    if (timer5 == TIMER5_OFF)	power_timer5_enable();
    if (timer4 == TIMER4_OFF)	power_timer4_enable();
    if (timer3 == TIMER3_OFF)	power_timer3_enable();
    if (timer1 == TIMER1_OFF)	power_timer1_enable();
    if (timer0 == TIMER0_OFF)	power_timer0_enable();
    if (spi == SPI_OFF)			  power_spi_enable();
    if (usart3 == USART3_OFF)	power_usart3_enable();
    if (usart2 == USART2_OFF)	power_usart2_enable();
    if (usart1 == USART1_OFF)	power_usart1_enable();
    if (usart0 == USART0_OFF)	power_usart0_enable();
    if (twi == TWI_OFF)			  power_twi_enable();
}