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

using pwm 1khz square wave generate with 50% duty cycle

i m new in nrf51822 controller so help me for coding of my question. any help will be appriciate. thank you.

  • Hi,

    Take a look at the PWM library example in the SDK. It's located in the folder <SDK_InstallFolder>\examples\peripheral\pwm_library. You can get a 1kHz square wave by setting the period to 1000 us:

    // 2-channel PWM as used in the example
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(1000L, BSP_LED_0, BSP_LED_1);
    
    // 1-channel PWM
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1000L, PIN_NUMBER); 
    

    Use the function app_pwm_channel_duty_set() to set the desired duty cycle:

    while (app_pwm_channel_duty_set(&PWM1, 0, 50) == NRF_ERROR_BUSY); // 50%
    
Related