6 years, 1 month ago.

Reducing power consumption.

Hello, I need your help to reduce power consumption.

I'm using nordic nrf 51822 board.

I just added our servo class on basic code, HeartRate.

/media/uploads/Smarty/img_3941.jpg

/media/uploads/Smarty/img_3945.jpg

In conclusion, There was power consumption difference like a picture.

Number 1 appears comment in/out,

Number 2 appears connection servo motor(on this test, I didn't connect)

/media/uploads/Smarty/servo.zip

You can get Servo.h library from attachment.

I should reduce power consumption.

What I've tested code to solve this problem,

delete servo class memory when I don't use servo.

1.

void setServo(){

  Servo servo(p1,p2);
  servo.write(90);

}
int main(){
  setServo();
}

2.

int main(){

  Servo *servo = new Servo(p1,p2);
  servo->write(90);
  delete servo;

}

1,2 are just a test code,

Number 1, I declare servo class as local variable,

when the function is returned, the class memory will destroyed.

Number 2, I declare servo class as dynamic memory,

after using servo motor, delete memory.

Both work well at first loop, however, since second loop, it wasn't worked.

I am wondering,

+ I just declare servo class, why I get additional power consumption even I disconnect servo motor from board.

+ Why the servo motor doesn't work since second loop?

+ If I declare power consumption only when I use the motor, it will be solved?

+ How can I control GPIO, if I disconnect GPIO from the chip, it will be solved?

+ What is your recommend to reduce power consumption when I am not using servo motor.

2 Answers

6 years, 1 month ago.

In the constructor for the servo class you define a PWM output:

_servo = new PwmOut(servoPin);

As soon as you do that you will start to drive that pin which will require power.

Your destructor for the servo class is empty, you never delete the PWM output that you created so it keeps going and keeps using power. The second time you create the servo class it will try to create a second PWM output on the same pin. That may cause some problems.

delete _servo in the destructor for your servo class and see if that fixes it.

You should always do this anyway even if you don't plan on ever deleting an object once it's been created, it's simply good practice to include the code to clean up.

.

Thank you for replying.

Do you have any idea to disconnect PWMpin from GPIO?

I tried delete _servo, but I didn't work. Still it's connect to servo pin.

If you have any idea please tell me,

Thanks! :)

posted by Taeyeop Kim 30 Jul 2015
5 years, 12 months ago.

There's a problem with the underlying PwmOut code for the nRF51822 platform. It doesn't delete PwmOut object correctly, so even if you delete your servo object, the PwmOut object is not deleting. This causes programs to potentially crash, and makes it impossible to reduce power by shutting down PwmOut when not needed. I've raised this as an issue, https://developer.mbed.org/forum/bugs-suggestions/topic/16891/ but am still waiting for update.

Looking at the PwmOut object code you can see that there is no destructor, which in itself is not a problem, but means the underlying chip specific pwmout_free is not being called. I've tried adding a destructor which calls this function, and it kinda works, but it still doesn't shutdown the underlying pwm function so no power saving. This is where I get stuck.

You can also raise it on the list of known issues in the mbed-src repository. There are already 112 open issues so one more won't hurt.

https://github.com/mbedmicro/mbed/issues?q=is%3Aissue+is%3Aopen

posted by Andy A 23 Sep 2015