[DemoCode下载]

PWM的同步模式输出

[复制链接]
673|13
手机看帖
扫描二维码
随时随地手机跟帖
gejigeji521|  楼主 | 2020-5-21 22:08 | 显示全部楼层 |阅读模式
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

//***********************************************************************************************************
//  Website: http://www.nuvoton.com
//  E-Mail : MicroC-8bit@nuvoton.com
//***********************************************************************************************************

#include "ML51.h"

/**
* [url=home.php?mod=space&uid=247401]@brief[/url]       PWM Synchronous mode PWM0 channel 0/2/4 setting and channel 1/3/4 follow output demo
* @param       None
* [url=home.php?mod=space&uid=266161]@return[/url]      None
* [url=home.php?mod=space&uid=1543424]@Details[/url]     Channel 0 high duty 10%, Channel 2 high duty 30% , Channel 4 high duty 50%.
*/

void main (void)
{

/** PWM0 initial setting  
   * include pwm.c in Library for PWM mode setting
   * @note: the period setting of all PWM0 should be same, for example following 0x6FF.
*/
  
    PWM0_ClockSource(PWM_FSYS,128);                                    // define PWM0 clock source and divider.
  
    MFP_P05_PWM0_CH0;                                                // multi function pin define P0.5 as PWM0 channel 0 output
    P05_PUSHPULL_MODE;  
    MFP_P24_PWM0_CH1;                                                // multi function pin define P2.4 as PWM0 channel 1 output
    P24_PUSHPULL_MODE;  
    PWM0_ConfigOutputChannel(0,Synchronous,EdgeAligned,0x6FF,10);    // setting PWM channel 0&1 as 10% duty high of 0x6FF PWM period = 0x00B3
  

    MFP_P03_PWM0_CH2;                                                // multi function pin define P0.3 as PWM0 channel 2 output
    P03_PUSHPULL_MODE;
    MFP_P22_PWM0_CH3;                                                // multi function pin define P2.2 as PWM0 channel 3
    P22_PUSHPULL_MODE;
    PWM0_ConfigOutputChannel(2,Synchronous,EdgeAligned,0x6FF,30);    // setting PWM channel 2&3 as 30% duty high of 0x6FF PWM period = 0x0219

    MFP_P01_PWM0_CH4;                                                // multi function pin define P0.1 as PWM0 channel 4
    P01_PUSHPULL_MODE;
    MFP_P20_PWM0_CH5;                                                // multi function pin define P0.5 as PWM0 channel 5
    P20_PUSHPULL_MODE;
    PWM0_ConfigOutputChannel(4,Synchronous,EdgeAligned,0x6FF,50);    // setting PWM channel 4&5 as 50% duty high of 0x6FF PWM period = 0x037F
   
    PWM0_RUN();
  
    while(1);
}





使用特权

评论回复
gejigeji521|  楼主 | 2020-5-21 22:09 | 显示全部楼层
同步模式
当PWMMOD[1:0] = [1:0]时,同步模式使能。在该模式, PG0/2/4输出跟独立模式一样的PWM信号。
PG1/3/5输出跟PG02/4一样的PWM信号

使用特权

评论回复
xinpian101| | 2020-5-21 23:55 | 显示全部楼层
新唐的PWM很好学

使用特权

评论回复
antusheng| | 2020-5-22 08:57 | 显示全部楼层
很容易上手

使用特权

评论回复
598330983| | 2020-5-22 13:25 | 显示全部楼层
同步模式,一模一样。

使用特权

评论回复
zhuomuniao110| | 2020-5-22 23:17 | 显示全部楼层
偶尔会用到的一种模式

使用特权

评论回复
xinxianshi| | 2020-5-24 22:27 | 显示全部楼层
这个操作比较容易学。

使用特权

评论回复
zhuotuzi| | 2020-5-25 14:50 | 显示全部楼层
同步模式一般用在什么地方

使用特权

评论回复
huangcunxiake| | 2020-5-25 22:31 | 显示全部楼层
很好入门啊。

使用特权

评论回复
木木guainv| | 2020-6-5 18:15 | 显示全部楼层
非常感谢楼主分享

使用特权

评论回复
磨砂| | 2020-6-5 18:15 | 显示全部楼层
pwm这么多模式啊

使用特权

评论回复
晓伍| | 2020-6-5 18:15 | 显示全部楼层
楼主好厉害啊

使用特权

评论回复
八层楼| | 2020-6-5 18:16 | 显示全部楼层
楼主辛苦了

使用特权

评论回复
观海| | 2020-6-5 18:16 | 显示全部楼层
优美的代码

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

161

主题

2117

帖子

8

粉丝