7 years, 7 months ago.

PWMOut Does not let nrf51822 sleep.

Hi I am using PwmOut for buzzer on a custom board built with nrf51822. We are using nrf51822 with mbed API. so if I have

include the mbed library with this snippet

#include <BLE_API.h>
#include "ble/GattCharacteristic.h"

PwmOut buzz(p13);
void setup()
{
//all bye related setup and button related setup

}
void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(now());//just display current time on Serial(only used as Debugging to ensure device is running normally)
  if(Serial.available()>0)
  {
    Serial.println(Serial.readString());
  }
  if(bEvent.button!=0) //Button has been pressed.
    {
     Serial.println("StoreButton Press");
      if(bEvent.pressType==SHORT_PRESS)  //type of event on button SHORT PRESS Save it LONG PRESS go to defined modes
       {
        storeData(bEvent.button,now()); //Store
        //Clear Event
        bEvent.button=0; bEvent.button=NOPRESS;
        //start Advertisment
        ble.startAdvertising();
      }else
      {
        //set things as the modes you want
      }
    }
  if(INDICATOR)
    {
     led1 =1;delay(500);led1 =0;delay(500);
     led1 =1;delay(500);led1 =0;delay(500);
     led1 =1;delay(500);led1 =0; 
     INDICATOR=false;     
    }
  Serial.println("Sleeping..");
  ble.waitForEvent();
}

if I remove PwmOut it sleeps so I think somewhere inside PwmOut the interrupt keeps waking up the device. how can I stop pwm when I don't need it. I use it to drive a pizzo buzzer for a second. buzz.write(0.2); delay and then buzz.write(0);....

1 Answer

7 years, 7 months ago.

You have more control over the PWM pins through functions like pwmout_init and pwmout_free function. Look at mbed-os/hal/api/PwmOut.h for information on how to use it.

Accepted Answer

You can also delete the object if you use new and delete keywords to make the PwmOut. Then you can stick to the C++ functions. However shouldn't it still be able to go to regular sleep?

posted by Erik - 05 Sep 2016