This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52840 PWM uninit power consumption

  • nRF52840
  • SDK 15.3
  • Segger Embedded Studio

I PWM a piezo buzzer (with a transistor) , using the PWM peripheral. The problem I encounter is that before I call the PWM function the power consumption is around 5uA, while after the PWM uninit() from the PWM event handler, the power consumption has increased to ~660uA. I checked that the driver is succesfully disabled, but I guess that the DMA is still on? If I go into shutdown mode with nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_STAY_IN_SYSOFF); the power consumption is reduced to 1.1uA as expected (mostly external hardware connected to the nRF52840).

So is there any way to reduce the power consumption after the PWM has been unitialized or is this not possible and should I use a different methode of PWM generation?

Code:

pwm.c

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdbool.h>
#include <stdint.h>
#include "pwm.h"
#include "app_timer.h"
#include "nrf_gpio.h"
#include "boards.h"
#include "gpio-board.h"
#include "nrf_drv_pwm.h"
#include "nrf_drv_clock.h"
#include "nrf_log.h"
#include "app_util.h"
static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0);
void PWM_shutdown(void)
{
if(!nrfx_pwm_is_uninit(&m_pwm0))
{
nrf_drv_pwm_uninit(&m_pwm0);
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

pwm.h

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*!
* \file pwm.h
*
* \brief PWM for the buzzer.
*
*/
#ifndef __PWM_H__
#define __PWM_H__
#include <stdbool.h>
#include <stdint.h>
void PWM_event(uint8_t dutycycle, uint16_t frequency, uint16_t nRepeat);
void PWM_shutdown(void);
#endif // __PWM_H__
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Addition to nrfx_pwm.c to check if the PWM state is equal to NRFX_DRV_STATE_UNINITIALIZED.

Fullscreen
1
2
3
4
5
bool nrfx_pwm_is_uninit(nrfx_pwm_t const * const p_instance)
{
pwm_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
return (p_cb->state == NRFX_DRV_STATE_UNINITIALIZED) ? true : false;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX