only enter low power mode waitForEvent() in idle if there is no active PWM

This commit is contained in:
hathach committed 2017-04-09 14:42:26 +07:00
1 parent 2963e1dade
commit a335699296
4 files changed
+11 -7

No files matched your search

+4 -3
View File
@@ -51,6 +51,7 @@ HardwarePWM::HardwarePWM(NRF_PWM_Type* pwm)
arrclr(_seq0);
_resolution = 8;
_clock_div = PWM_PRESCALER_PRESCALER_DIV_1; // 16 Mhz
}
#if 0
@@ -90,8 +91,8 @@ void HardwarePWM::setResolution(uint8_t bitnum)
void HardwarePWM::setClockDiv(uint8_t div)
{
div = min8(div, PWM_PRESCALER_PRESCALER_DIV_128);
_pwm->PRESCALER = div;
_clock_div = min8(div, PWM_PRESCALER_PRESCALER_DIV_128);
_pwm->PRESCALER = _clock_div;
}
/**
@@ -137,7 +138,7 @@ void HardwarePWM::begin(void)
// Initialize Registers
_pwm->MODE = PWM_MODE_UPDOWN_Up;
_pwm->COUNTERTOP = bit(_resolution) - 1; // default is 8 bit, can be configured before begin()
_pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_1; // 16MHz
_pwm->PRESCALER = _clock_div;
_pwm->DECODER = PWM_DECODER_LOAD_Individual;
_pwm->LOOP = 0;
+1
View File
@@ -49,6 +49,7 @@ class HardwarePWM
uint16_t _seq0[MAX_CHANNELS];
uint8_t _resolution;
uint8_t _clock_div;
void _start(void);
+6 -1
View File
@@ -88,7 +88,12 @@ extern "C"
void vApplicationIdleHook( void )
{
waitForEvent();
// Enter low-power mode will turn of hardware PWM
// Only go there if no PWM device is active.
if ( !(PWM0.begun() || PWM1.begun() || PWM2.begun() ) )
{
waitForEvent();
}
}
}
-3
View File
@@ -69,9 +69,6 @@ void analogWrite( uint32_t pin, uint32_t value )
// If pin is added (already) in this group
if ( PWMx[i]->addPin(pin) )
{
// begin if not previously
if ( !PWMx[i]->begun() ) PWMx[i]->begin();
PWMx[i]->writePin(pin, value);
return;
}