[DemoCode下载] PWM的同步模式输出

[复制链接]
 楼主| gejigeji521 发表于 2020-5-21 22:08 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

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

  10. #include "ML51.h"

  11. /**
  12. * [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
  13. * @param       None
  14. * [url=home.php?mod=space&uid=266161]@return[/url]      None
  15. * [url=home.php?mod=space&uid=1543424]@Details[/url]     Channel 0 high duty 10%, Channel 2 high duty 30% , Channel 4 high duty 50%.
  16. */

  17. void main (void)
  18. {

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

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

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





 楼主| 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 | 显示全部楼层
优美的代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

195

主题

2460

帖子

8

粉丝
快速回复 在线客服 返回列表 返回顶部