RTL8762DK PWM(七)

本文档详细介绍了在RTL8762DK开发板上使用PWM的步骤,包括环境配置、工程创建、源文件组织和运行结果。通过实例演示,帮助开发者了解如何在keil IDE中操作。
摘要由CSDN通过智能技术生成

概述

        本示例,只要介绍,如何使用PWM,又离成功进了一步 ^_^。

一、环境

1、硬件  (RTL8762DK + 128M Bits Falsh)

2、软件(keil IDE)

二、PWM的使用

1、创建examples_ble_pwm工程,基于《examples_ble_wdg工程》来创建,创建步骤请参考第二篇文章。

2、新建pwm文件夹,分别存放pwm.c与pwm.h这两个文件

 1)、分别添加pwm.c与pwm.h到工程中

3、pwm.h

#ifndef _PWM_H_
#define _PWM_H_


#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include "board.h"
#include "rtl876x_tim.h"
#include "rtl876x_rcc.h"

/* Defines --------------------------------------------------------------*/
/** Define pwm output pin.
  * P0_1 is connected to LED0 on the EVB.
  */
#define PWM_OUT_PIN             P0_1
/** Define pwm complementary output pin.
  * P0_2 is connected to LED1 on the EVB.
  */
#define PWM_OUT_P_PIN           P0_2
#define PWM_OUT_N_PIN           P2_2


/** Define TIM num and pinmux of PWM output.
  * Timer2 to Timer7 all have PWM output function.
  * But only Timer2 and Timer3 support PWM complementary output function, other timers do not support it.
  * When the complementary output function is turned on, when the dead time is not set,
  * the complementary output PWM2_P of timer2 is in phase with PWM2, and PWM2_N and PWM2 are  inverted.
  * Timer3 is the same as timer2.
  */
#define PWM_TIMER_NUM           TIM2
#define PWM_OUT_PIN_PINMUX      timer_pwm2
#define PWM_OUT_P_PIN_PINMUX    PWM2_P
#define PWM_OUT_N_PIN_PINMUX    PWM2_N

/* Config PWM_PERIOD and PWM_DUTY_CYCLE */
#define PWM_PERIOD              1000000 //uint:us
#define PWM_DUTY_CYCLE          50      //uint:percent
/* PWM_HIGH_COUNT =  */
#define PWM_HIGH_COUNT          (((PWM_PERIOD)*((PWM_DUTY_CYCLE*40)/100))-1)    //PWM CLOCK = 40000000
#define PWM_LOW_COUNT           (((PWM_PERIOD)*(((100-PWM_DUTY_CYCLE)*40)/100))-1)

/** Config PWM_DEAD_ZONE_TIME. Max 8ms.
  * When dead time is set, PWM2_P and PWM2_N will
  * delay one dead time longer than PWM2 at high output level.
  * When the dead_zone time is longer than the high-level time of PWM,
  * PWM_P will always output low-level.
  * When the dead_zone time is longer than the low-level time of PWM,
  * PWM_N will always output low-level.
  */
#define PWM_DEAD_ZONE_TIME      1 //uint:ms
#define PWM_DEAD_ZONE_SIZE      ((PWM_DEAD_ZONE_TIME)*32-1)


void pwm_demo(void);

#ifdef __cplusplus
}
#endif


#endif

4、pwm.c

#include "pwm.h"




/**
  * @brief  Initialization of pinmux settings and pad settings.
  * @param  No parameter.
  * @return void
*/
void board_pwm_init(void)
{
    Pad_Config(PWM_OUT_PIN, PAD_PINMUX_MODE, PAD_IS_PWRON, PAD_PULL_NONE, PAD_OUT_ENABLE, PAD_OUT_HIGH);
    Pad_Config(PWM_OUT_P_PIN, PAD_P
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ch_champion

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值