Created
February 20, 2017 16:18
-
-
Save anonymous/e2f1042de352ac749744270a0b75bb34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <stdint.h> | |
#include "nrf.h" | |
#include "app_error.h" | |
#include "bsp.h" | |
#include "nrf_delay.h" | |
#include "app_pwm.h" | |
#define TIMER1_INSTANCE_INDEX (TIMER0_ENABLED) | |
APP_PWM_INSTANCE(PWM1,1); // Create the instance "PWM1" using TIMER1. | |
static volatile bool ready_flag; // A flag indicating PWM status. | |
void pwm_ready_callback(uint32_t pwm_id) // PWM callback function | |
{ | |
ready_flag = true; | |
} | |
int main(void) | |
{ | |
ret_code_t err_code; | |
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(2000L, BSP_LED_0); | |
pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH; | |
APP_ERROR_CHECK(err_code); | |
app_pwm_enable(&PWM1); | |
/* Initialize and enable PWM. */ | |
err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback); | |
while(true) | |
{ | |
int dutyCycle = 0; | |
ready_flag = false; | |
while(!ready_flag) { | |
APP_ERROR_CHECK(app_pwm_channel_duty_set(&PWM1, 0, dutyCycle)); | |
nrf_delay_ms(25); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment