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

nrf51822 PWM Library on mBed

Hello, I am trying to use the 'nrf51-pwm-library' on mBed with a nrf51822 on RedBearLab Nano.

I copied the nrf_pwm.h/c files and they compile, but I never get any sort of signal out of the PWM pin. (Pin 19 on the RBL Nano is an on board LED.)

I assume there is something simple I am missing?

Here is the main.c code:

#include "mbed.h"
#include "BLEDevice.h"

#include "nrf_gpio.h"
#include "nrf_delay.h"
#include "nrf_pwm.h"




void pwm_init()
{
    nrf_pwm_config_t pwm_config = PWM_DEFAULT_CONFIG;
    
    pwm_config.mode             = PWM_MODE_BUZZER_255;
    pwm_config.num_channels     = 1;
    pwm_config.gpio_num[0]      = 19;
    
    // Initialize the PWM library
    nrf_pwm_init(&pwm_config);       
}


int main(void)
{    
    
    pwm_init();
    
    while (true)
    {
        nrf_pwm_set_value(0, 0);
        
        nrf_delay_us(500000);  
        
        nrf_pwm_set_value(0, 127);  
        
        nrf_delay_us(500000); 
        
        nrf_pwm_set_value(0, 255);  
        
        nrf_delay_us(500000); 
    }

}
Parents Reply Children
Related