1.在sdk_config.h中加入宏
// PWM_ENABLED - nrf_drv_pwm - PWM peripheral driver - legacy layer //========================================================== #ifndef PWM_ENABLED #define PWM_ENABLED 1 #endif // PWM_DEFAULT_CONFIG_OUT0_PIN - Out0 pin
#ifndef PWM_DEFAULT_CONFIG_OUT0_PIN #define PWM_DEFAULT_CONFIG_OUT0_PIN 31 #endif
// PWM_DEFAULT_CONFIG_OUT1_PIN - Out1 pin
#ifndef PWM_DEFAULT_CONFIG_OUT1_PIN #define PWM_DEFAULT_CONFIG_OUT1_PIN 31 #endif
// PWM_DEFAULT_CONFIG_OUT2_PIN - Out2 pin
#ifndef PWM_DEFAULT_CONFIG_OUT2_PIN #define PWM_DEFAULT_CONFIG_OUT2_PIN 31 #endif
// PWM_DEFAULT_CONFIG_OUT3_PIN - Out3 pin
#ifndef PWM_DEFAULT_CONFIG_OUT3_PIN #define PWM_DEFAULT_CONFIG_OUT3_PIN 31 #endif
// PWM_DEFAULT_CONFIG_BASE_CLOCK - Base clock // 16 MHz // 8 MHz // 4 MHz // 2 MHz // 1 MHz // 500 kHz // 250 kHz // 125 kHz
#ifndef PWM_DEFAULT_CONFIG_BASE_CLOCK #define PWM_DEFAULT_CONFIG_BASE_CLOCK 4 #endif
// PWM_DEFAULT_CONFIG_COUNT_MODE - Count mode // Up // Up and Down
#ifndef PWM_DEFAULT_CONFIG_COUNT_MODE #define PWM_DEFAULT_CONFIG_COUNT_MODE 0 #endif
// PWM_DEFAULT_CONFIG_TOP_VALUE - Top value #ifndef PWM_DEFAULT_CONFIG_TOP_VALUE #define PWM_DEFAULT_CONFIG_TOP_VALUE 1000 #endif
// PWM_DEFAULT_CONFIG_LOAD_MODE - Load mode // Common // Grouped // Individual // Waveform
#ifndef PWM_DEFAULT_CONFIG_LOAD_MODE #define PWM_DEFAULT_CONFIG_LOAD_MODE 0 #endif
// PWM_DEFAULT_CONFIG_STEP_MODE - Step mode // Auto // Triggered
#ifndef PWM_DEFAULT_CONFIG_STEP_MODE #define PWM_DEFAULT_CONFIG_STEP_MODE 0 #endif
// PWM_DEFAULT_CONFIG_IRQ_PRIORITY - Interrupt priority
// Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice // 0 (highest) // 1 // 2 // 3 // 4 // 5 // 6 // 7
#ifndef PWM_DEFAULT_CONFIG_IRQ_PRIORITY #define PWM_DEFAULT_CONFIG_IRQ_PRIORITY 6 #endif
// PWM0_ENABLED - Enable PWM0 instance
#ifndef PWM0_ENABLED #define PWM0_ENABLED 1 #endif
// PWM1_ENABLED - Enable PWM1 instance
#ifndef PWM1_ENABLED #define PWM1_ENABLED 1 #endif
// PWM2_ENABLED - Enable PWM2 instance
#ifndef PWM2_ENABLED #define PWM2_ENABLED 1 #endif
// PWM_NRF52_ANOMALY_109_WORKAROUND_ENABLED - Enables nRF52 Anomaly 109 workaround for PWM.
// The workaround uses interrupts to wake up the CPU and ensure // it is active when PWM is about to start a DMA transfer. For // initial transfer, done when a playback is started via PPI, // a specific EGU instance is used to generate the interrupt. // During the playback, the PWM interrupt triggered on SEQEND // event of a preceding sequence is used to protect the transfer // done for the next sequence to be played. //========================================================== #ifndef PWM_NRF52_ANOMALY_109_WORKAROUND_ENABLED #define PWM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 0 #endif // PWM_NRF52_ANOMALY_109_EGU_INSTANCE - EGU instance used by the nRF52 Anomaly 109 workaround for PWM. // EGU0 // EGU1 // EGU2 // EGU3 // EGU4 // EGU5
#ifndef PWM_NRF52_ANOMALY_109_EGU_INSTANCE #define PWM_NRF52_ANOMALY_109_EGU_INSTANCE 5 #endif
2.导入文件nrfx_pwm.c到工程中
3.引入头文件
#include "nrf_drv_pwm.h"
4.定义PWM实例
static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0);
5.定义变量
// This is for tracking PWM instances being used, so we can unintialize only // the relevant ones when switching from one demo to another. #define USED_PWM(idx) (1UL
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?