[DemoCode下载] ML51的PWM

[复制链接]
 楼主| xixi2017 发表于 2019-12-29 15:34 | 显示全部楼层 |阅读模式
  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 Complementary mode PWM0 channel 0~5 output demo all with dead zone time insert.
  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.   
  24.     PWM0_ClockSource(PWM_FSYS,128);                                    // define PWM0 clock source and divider.

  25. /* PWM period = 1/HIRC * 128 * 0x6FF =   9552 us
  26. *  high Duty 10% = 955 us  */
  27.     MFP_P05_PWM0_CH0;                                                  // multi function pin define P0.5 as PWM0 channel 0 output
  28.     P05_PUSHPULL_MODE;
  29.     MFP_P24_PWM0_CH1;                                                  // multi function pin define P2.4 as PWM0 channel 1 output
  30.     P24_PUSHPULL_MODE;
  31.     PWM0_ConfigOutputChannel(0,Complementary,EdgeAligned,0x6FF,10);    // setting PWM channel 0 as 10% duty high of 0x6FF PWM period = 0x00B3
  32.   
  33. /* PWM period = 1/HIRC * 128 * 0x6FF =   9552 us
  34. *  high Duty 30% = 2866 us  */
  35.     MFP_P03_PWM0_CH2;                                                  // multi function pin define P0.3 as PWM0 channel 2 output
  36.     P03_PUSHPULL_MODE;
  37.     MFP_P22_PWM0_CH3;                                                  // multi function pin define P2.2 as PWM0 channel 3
  38.     P22_PUSHPULL_MODE;
  39.     PWM0_ConfigOutputChannel(2,Complementary,EdgeAligned,0x6FF,30);    // setting PWM channel 2 as 30% duty high of 0x6FF PWM period = 0x0219
  40.    
  41. /* PWM period = 1/HIRC * 128 * 0x6FF =   9552 us
  42. *  high Duty 50% = 4776 us  */  
  43.     MFP_P01_PWM0_CH4;                                                  // multi function pin define P0.1 as PWM0 channel 4
  44.     P01_PUSHPULL_MODE;
  45.     MFP_P20_PWM0_CH5;                                                  // multi function pin define P0.5 as PWM0 channel 0
  46.     P20_PUSHPULL_MODE;
  47.     PWM0_ConfigOutputChannel(4,Complementary,EdgeAligned,0x6FF,50);    // setting PWM channel 4 as 50% duty high of 0x6FF PWM period = 0x037F
  48.    
  49.     PWM0_DeadZoneEnable(PWM0_CH23,0x155);
  50.    
  51.     PWM0_RUN();
  52.    
  53.     while(1);
  54. }





 楼主| xixi2017 发表于 2019-12-29 15:34 | 显示全部楼层
51也提供了库函数,高级吧
 楼主| xixi2017 发表于 2019-12-29 15:35 | 显示全部楼层
这个是互补输出形式的PWM。。
yiy 发表于 2019-12-29 17:13 | 显示全部楼层
51都集成这么牛的PWM外设了。
wahahaheihei 发表于 2019-12-29 21:12 | 显示全部楼层
niu ,设置管脚,然后设置模式。周期。占空比。
wahahaheihei 发表于 2019-12-29 21:13 | 显示全部楼层
PWM0_ConfigOutputChannel(2,Complementary,EdgeAligned,0x6FF,30);
用了PWM0的不同通道,不知道这个通道是不是固定的。
mintspring 发表于 2019-12-29 23:56 | 显示全部楼层
讲的非常好。
mintspring 发表于 2019-12-29 23:57 | 显示全部楼层
NO,是官方的例子做的好。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

144

主题

2006

帖子

2

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

144

主题

2006

帖子

2

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