Created
February 22, 2017 16:15
-
-
Save anonymous/0838f1f71187e23a8fb7ac48fb002f13 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
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. | |
* | |
* The information contained herein is property of Nordic Semiconductor ASA. | |
* Terms and conditions of usage are described in detail in NORDIC | |
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. | |
* | |
* Licensees are granted free, non-transferable use of the information. NO | |
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from | |
* the file. | |
* | |
*/ | |
/** @file | |
* @defgroup pwm_example_main main.c | |
* @{ | |
* @ingroup pwm_example | |
* | |
* @brief PWM Example Application main file. | |
* | |
* This file contains the source code for a sample application using PWM. | |
* | |
* | |
*/ | |
#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. | |
int main(void) | |
{ | |
ret_code_t err_code; | |
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(2000L, 28); | |
pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_LOW; | |
/* Initialize and enable PWM. */ | |
err_code = app_pwm_init(&PWM1,&pwm1_cfg,NULL); | |
APP_ERROR_CHECK(err_code); | |
app_pwm_enable(&PWM1); | |
while(true) | |
{ | |
int dutyCycle = 0; | |
/* Set the duty cycle - keep trying until PWM is ready... */ | |
while(app_pwm_channel_duty_set(&PWM1, 0, dutyCycle) == NRF_ERROR_BUSY); | |
// enter into sleep mode | |
__SEV(); | |
__WFE(); | |
__WFE(); | |
} | |
} | |
/** @} */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment