arduino_sensor/LowPower.cpp
void	LowPowerClass::adcNoiseReduction(period_t period, adc_t adc, 
										 timer2_t timer2)
{
	// Temporary clock source variable 
	unsigned char clockSource = 0;
	
	#if !defined(__AVR_ATmega32U4__)
	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);
	}
	#endif
	
	if (adc == ADC_OFF)	ADCSRA &= ~(1 << ADEN);
	
	if (period != SLEEP_FOREVER)
	{
		wdt_enable(period);
		WDTCSR |= (1 << WDIE);	
	}
	
	lowPowerBodOn(SLEEP_MODE_ADC);
	
	if (adc == ADC_OFF) ADCSRA |= (1 << ADEN);
	
	#if !defined(__AVR_ATmega32U4__)
	if (timer2 == TIMER2_OFF)
	{
		if (clockSource & CS22) TCCR2B |= (1 << CS22);
		if (clockSource & CS21) TCCR2B |= (1 << CS21);
		if (clockSource & CS20) TCCR2B |= (1 << CS20);
		
	}
	#endif
}
/*******************************************************************************
* Name: adcNoiseReduction
* Description: Putting microcontroller into ADC noise reduction state. This is
*			         a very useful state when using the ADC to achieve best and low 
*              noise signal.
*
* Argument  	Description
* =========  	===========
* 1. period   Duration of low power mode. Use SLEEP_FOREVER to use other wake
*				up resource:
*				(a) SLEEP_15MS - 15 ms sleep
*				(b) SLEEP_30MS - 30 ms sleep
*				(c) SLEEP_60MS - 60 ms sleep
*				(d) SLEEP_120MS - 120 ms sleep
*				(e) SLEEP_250MS - 250 ms sleep
*				(f) SLEEP_500MS - 500 ms sleep
*				(g) SLEEP_1S - 1 s sleep
*				(h) SLEEP_2S - 2 s sleep
*				(i) SLEEP_4S - 4 s sleep
*				(j) SLEEP_8S - 8 s sleep
*				(k) SLEEP_FOREVER - Sleep without waking up through WDT
*
* 2. adc		ADC module disable control. Turning off the ADC module is
*				basically removing the purpose of this low power mode.
*				(a) ADC_OFF - Turn off ADC module
*				(b) ADC_ON - Leave ADC module in its default state
*
* 3. timer2		Timer 2 module disable control:
*				(a) TIMER2_OFF - Turn off Timer 2 module
*				(b) TIMER2_ON - Leave Timer 2 module in its default state
*
*******************************************************************************/
adcNoiseReduction
Description: Putting microcontroller into ADC noise reduction state. This is
a very useful state when using the ADC to achieve best and low
noise signal.

Argument       Description

1. period   Duration of low power mode.

2. adc         ADC module disable control. Turning off the ADC module is
basically removing the purpose of this low power mode.
(a) ADC_OFF - Turn off ADC module
(b) ADC_ON - Leave ADC module in its default state

3. timer2              Timer 2 module disable control:
(a) TIMER2_OFF - Turn off Timer 2 module
(b) TIMER2_ON - Leave Timer 2 module in its default state
adcNoiseReduction Description : Putting microcontroller into ADC noise reduction state . This is a very useful state when using the ADC to achieve best and low noise signal . Argument Description 1 . period Duration of low power mode . 2 . adc ADC module disable control . Turning off the ADC module is basically removing the purpose of this low power mode . ( a ) ADC_OFF - Turn off ADC module ( b ) ADC_ON - Leave ADC module in its default state 3 . timer2 Timer 2 module disable control : ( a ) TIMER2_OFF - Turn off Timer 2 module ( b ) TIMER2_ON - Leave Timer 2 module in its default state
void	LowPowerClass::adcNoiseReduction(period_t period, adc_t adc, 
										 timer2_t timer2)
{
	unsigned char clockSource = 0;
	#if !defined(__AVR_ATmega32U4__)
	if (timer2 == TIMER2_OFF)
	{
		if (TCCR2B & CS22) clockSource |= (1 << CS22);
		if (TCCR2B & CS21) clockSource |= (1 << CS21);
		if (TCCR2B & CS20) clockSource |= (1 << CS20);
		TCCR2B &= ~(1 << CS22);
		TCCR2B &= ~(1 << CS21);
		TCCR2B &= ~(1 << CS20);
	}
	#endif
	if (adc == ADC_OFF)	ADCSRA &= ~(1 << ADEN);
	if (period != SLEEP_FOREVER)
	{
		wdt_enable(period);
		WDTCSR |= (1 << WDIE);	
	}
	lowPowerBodOn(SLEEP_MODE_ADC);
	if (adc == ADC_OFF) ADCSRA |= (1 << ADEN);
	#if !defined(__AVR_ATmega32U4__)
	if (timer2 == TIMER2_OFF)
	{
		if (clockSource & CS22) TCCR2B |= (1 << CS22);
		if (clockSource & CS21) TCCR2B |= (1 << CS21);
		if (clockSource & CS20) TCCR2B |= (1 << CS20);
	}
	#endif
}
void LowPowerClass :: adcNoiseReduction ( period_t period , adc_t adc , timer2_t timer2 ) { unsigned char clockSource = 0 ; #if ! defined ( __AVR_ATmega32U4__ ) if ( timer2 == TIMER2_OFF ) { if ( TCCR2B & CS22 ) clockSource |= ( 1 << CS22 ) ; if ( TCCR2B & CS21 ) clockSource |= ( 1 << CS21 ) ; if ( TCCR2B & CS20 ) clockSource |= ( 1 << CS20 ) ; TCCR2B &= ~ ( 1 << CS22 ) ; TCCR2B &= ~ ( 1 << CS21 ) ; TCCR2B &= ~ ( 1 << CS20 ) ; } #endif if ( adc == ADC_OFF ) ADCSRA &= ~ ( 1 << ADEN ) ; if ( period != SLEEP_FOREVER ) { wdt_enable ( period ) ; WDTCSR |= ( 1 << WDIE ) ; } lowPowerBodOn ( SLEEP_MODE_ADC ) ; if ( adc == ADC_OFF ) ADCSRA |= ( 1 << ADEN ) ; #if ! defined ( __AVR_ATmega32U4__ ) if ( timer2 == TIMER2_OFF ) { if ( clockSource & CS22 ) TCCR2B |= ( 1 << CS22 ) ; if ( clockSource & CS21 ) TCCR2B |= ( 1 << CS21 ) ; if ( clockSource & CS20 ) TCCR2B |= ( 1 << CS20 ) ; } #endif }
Name: adcNoiseReduction
Description: Putting microcontroller into ADC noise reduction state.
Name : adcNoiseReduction Description : Putting microcontroller into ADC noise reduction state .
// Temporary clock source variable  // Remove the clock source to shutdown Timer2