找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3054|回复: 0
打印 上一主题 下一主题
收起左侧

STM32 6路相位相差60度PWM输出实验

[复制链接]
跳转到指定楼层
楼主
ID:293035 发表于 2020-3-25 09:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
6路相位相差60度PWM输出实验,STM32F4版  可供参考使用,也可移植

单片机源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "usart.h"
  6. #include "timer.h"
  7. #include "math.h"
  8. u32 SIN_LUT_index = 0;
  9. u32 Cnt_Dir = 0;
  10. s32 Sin_Lut[360]= {0};
  11. u8 LowRangeFlag= 0;
  12. u8 HighRangeFlag= 0;
  13. u16 SetUpPara= 1;
  14. u16 Amp1= 500;
  15. u16 Amp2= 1000;

  16. vu8 sign=0;
  17. uint64_t Inverter_i;
  18. uint64_t Inverter_V;
  19. uint64_t bridge_i;
  20. uint64_t Photovoltaic_i;
  21. uint64_t Photovoltaic_V;


  22. ErrorStatus HSEStartUpStatus;

  23. void RCC_Configuration(void);
  24. void TIM_APP_Config(void);
  25. void ADC_APP_Config(void);

  26. void PWM_Init( void )
  27. {
  28.   for( SIN_LUT_index=0; SIN_LUT_index<360; SIN_LUT_index++)
  29.   {
  30.     Sin_Lut[SIN_LUT_index] = 1000*sin(2*3.1415926*(2*SIN_LUT_index+1)/720.0);
  31.   }

  32. }
  33. int main(void)
  34. {
  35.     #ifdef DEBUG
  36.     debug();
  37.     #endif
  38.         PWM_Init();
  39.   /* System Clocks Configuration */
  40.     RCC_Configuration();  
  41.    
  42.     TIM_APP_Config();               
  43.            while(1)
  44.         {                  
  45.         }         
  46. }

  47. void RCC_Configuration(void)
  48. {
  49.   /* RCC system reset(for debug purpose) */
  50.   RCC_DeInit();

  51.   /* Enable HSE */
  52.   RCC_HSEConfig(RCC_HSE_ON);

  53.   /* Wait till HSE is ready */
  54.   HSEStartUpStatus = RCC_WaitForHSEStartUp();

  55.   if (HSEStartUpStatus == SUCCESS)
  56.   {
  57.     /* Enable Prefetch Buffer */
  58. //    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

  59.     /* Flash 2 wait state */
  60. //    FLASH_SetLatency(FLASH_Latency_2);

  61.     /* HCLK = SYSCLK */
  62.     RCC_HCLKConfig(RCC_SYSCLK_Div1);

  63.     /* PCLK2 = HCLK */
  64.     RCC_PCLK2Config(RCC_HCLK_Div1);

  65.     /* PCLK1 = HCLK/2 */
  66.     RCC_PCLK1Config(RCC_HCLK_Div2);

  67.         /* ADCCLK = PCLK2/4 */
  68.     RCC_ADCCLKConfig(RCC_PCLK2_Div6);

  69.     /* PLLCLK = 8MHz * 9 = 72 MHz */
  70.     RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

  71.     /* Enable PLL */
  72.     RCC_PLLCmd(ENABLE);

  73.     /* Wait till PLL is ready */
  74.     while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
  75.     {}

  76.     /* Select PLL as system clock source */
  77.     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

  78.     /* Wait till PLL is used as system clock source */
  79.     while (RCC_GetSYSCLKSource() != 0x08)
  80.     {}
  81.   }
  82. }
  83. #ifdef  DEBUG
  84. void assert_failed(u8* file, u32 line)
  85. {
  86.   /* User can add his own implementation to report the file name and line number,
  87.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  88.   while (1)
  89.   {}
  90. }
  91. #endif
复制代码

所有资料51hei提供下载:
PWM输出实验.7z (186.05 KB, 下载次数: 32)



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表