[DemoCode下载] ML51的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 indepedent mode PWM0 channel 0~5 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 1 high duty 20% ..... Channel 5 high duty 60%.
  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.     PWM0_ClockSource(PWM_FSYS,128);                                    // define PWM0 clock source and divider.
  24.   
  25.     MFP_P05_PWM0_CH0;                                                // multi function pin define P0.5 as PWM0 channel 0 output
  26.     P05_PUSHPULL_MODE;                                             
  27.     PWM0_ConfigOutputChannel(0,Independent,EdgeAligned,0x6FF,10);    // setting PWM channel 0 as 10% duty high of 0x6FF PWM period = 0x00B3
  28.   
  29.     MFP_P24_PWM0_CH1;                                                // multi function pin define P2.4 as PWM0 channel 1 output
  30.     P24_PUSHPULL_MODE;
  31.     PWM0_ConfigOutputChannel(1,Independent,EdgeAligned,0x6FF,20);    // setting PWM channel 1 as 20% duty high of 0x6FF PWM period = 0x0166
  32.   
  33.     MFP_P03_PWM0_CH2;                                                // multi function pin define P0.3 as PWM0 channel 2 output
  34.     P03_PUSHPULL_MODE;
  35.     PWM0_ConfigOutputChannel(2,Independent,EdgeAligned,0x6FF,30);    // setting PWM channel 2 as 30% duty high of 0x6FF PWM period = 0x0219
  36.   
  37.     MFP_P22_PWM0_CH3;                                                // multi function pin define P2.2 as PWM0 channel 3
  38.     P22_PUSHPULL_MODE;
  39.     PWM0_ConfigOutputChannel(3,Independent,EdgeAligned,0x6FF,40);    // setting PWM channel 3 as 40% duty high of 0x6FF PWM period = 0x02CC
  40.   
  41.     MFP_P01_PWM0_CH4;                                                // multi function pin define P0.1 as PWM0 channel 4
  42.     P01_PUSHPULL_MODE;
  43.     PWM0_ConfigOutputChannel(4,Independent,EdgeAligned,0x6FF,50);    // setting PWM channel 4 as 50% duty high of 0x6FF PWM period = 0x037F
  44.    
  45.     MFP_P20_PWM0_CH5;                                                // multi function pin define P0.5 as PWM0 channel 0
  46.     P20_PUSHPULL_MODE;
  47.     PWM0_ConfigOutputChannel(5,Independent,EdgeAligned,0x6FF,60);    // setting PWM channel 5 as 60% duty high of 0x6FF PWM period = 0x0432
  48.    
  49.     PWM0_RUN();
  50.    
  51.     while(1);
  52. }





 楼主| gejigeji521 发表于 2020-5-21 22:10 | 显示全部楼层
当PWMMOD[1:0] (PWMnCON1[7:6])设定为 [0:0],独立模式使能。该模式为PWM默认模式, PG0,PG1, PG2, PG3, PG4 及 PG5 独立输出PWM信号。
xinpian101 发表于 2020-5-21 23:56 | 显示全部楼层
可以单独配置,非常好。
antusheng 发表于 2020-5-22 08:58 | 显示全部楼层
非常棒,可以混合模式吗
598330983 发表于 2020-5-22 13:28 | 显示全部楼层
独立模式,每个IO都不同。
wahahaheihei 发表于 2020-5-22 19:48 | 显示全部楼层
例子不错,很容易懂。PWM如此好学。
zhuomuniao110 发表于 2020-5-22 22:07 | 显示全部楼层
操作很棒。很容易懂。
xinxianshi 发表于 2020-5-24 22:01 | 显示全部楼层
所有的只有一个时钟频率啊。
木木guainv 发表于 2020-6-5 18:13 | 显示全部楼层
非常感谢楼主分享
磨砂 发表于 2020-6-5 18:14 | 显示全部楼层
就是相互没有任何影响的 是吗
晓伍 发表于 2020-6-5 18:14 | 显示全部楼层
楼主辛苦了
八层楼 发表于 2020-6-5 18:14 | 显示全部楼层
复制过去试试看
观海 发表于 2020-6-5 18:15 | 显示全部楼层
路过 学习了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

195

主题

2460

帖子

8

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