找回密码
 立即注册
×

00:00:00

您有一张0.1元限时体验卡,马上领取获得VIP尊享特权。

一个奇怪的问题:AI8051U使用追频后,做一个特定的浮点会...

2024-9-11 10:35 来自 zhx 发布 @ 综合讨论

AI8051U追频后,使用TFPU做一个特定的浮点会复位,

不追频,没有问题,
不做浮点计算,也没有问题
不用TFPU,也没有问题
  1. #include "AI8051U.h"
  2. #include "stdio.h"
  3. #include "intrins.h"

  4. typedef   signed  char int8_t;
  5. typedef   signed  int int16_t;
  6. typedef   signed  long int32_t;

  7. typedef unsigned  char uint8_t;
  8. typedef unsigned  int uint16_t;
  9. typedef unsigned  long uint32_t;      

  10. typedef         unsigned char        u8;
  11. typedef         unsigned int        u16;
  12. typedef         unsigned long        u32;

  13. #define MAIN_Fosc        45000000UL

  14. #define Timer0_Reload   (65536UL -(MAIN_Fosc / 1000))   //Timer 0 中断频率, 1000次/秒
  15. //==========================================================================

  16. #define    HSCK_MCLK        0
  17. #define    HSCK_PLL         1
  18. #define    HSCK_SEL         HSCK_PLL   

  19. #define    PLL_96M          0
  20. #define    PLL_144M         1
  21. #define    PLL_SEL          PLL_96M  

  22. #define    CKMS             0x80
  23. #define    HSIOCK           0x40
  24. #define    MCK2SEL_MSK      0x0c
  25. #define    MCK2SEL_SEL1     0x00
  26. #define    MCK2SEL_PLL      0x04
  27. #define    MCK2SEL_PLLD2    0x08
  28. #define    MCK2SEL_IRC48    0x0c
  29. #define    MCKSEL_MSK       0x03
  30. #define    MCKSEL_HIRC      0x00
  31. #define    MCKSEL_XOSC      0x01
  32. #define    MCKSEL_X32K      0x02
  33. #define    MCKSEL_IRC32K    0x03

  34. #define    ENCKM            0x80
  35. #define    PCKI_MSK         0x60
  36. #define    PCKI_D1          0x00
  37. #define    PCKI_D2          0x20
  38. #define    PCKI_D4          0x40
  39. #define    PCKI_D8          0x60

  40. /*************  本地常量声明    **************/

  41. #define PWM1_0      0x00    //P:P1.0  N:P1.1
  42. #define PWM1_1      0x01    //P:P0.0  N:P0.1
  43. #define PWM1_2      0x02    //P:P2.0  N:P2.1

  44. #define PWM2_0      0x00    //P:P1.2  N:P1.3
  45. #define PWM2_1      0x04    //P:P0.2  N:P0.3
  46. #define PWM2_2      0x08    //P:P2.2  N:P2.3

  47. #define PWM3_0      0x00    //P:P1.4  N:P1.5
  48. #define PWM3_1      0x10    //P:P0.4  N:P0.5
  49. #define PWM3_2      0x20    //P:P2.4  N:P2.5

  50. #define PWM4_0      0x00    //P:P1.6  N:P1.7
  51. #define PWM4_1      0x40    //P:P0.6  N:P0.7
  52. #define PWM4_2      0x80    //P:P2.6  N:P2.7

  53. #define ENO1P       0x01
  54. #define ENO1N       0x02
  55. #define ENO2P       0x04
  56. #define ENO2N       0x08
  57. #define ENO3P       0x10
  58. #define ENO3N       0x20
  59. #define ENO4P       0x40
  60. #define ENO4N       0x80

  61. #define PWM_PERIOD   6750-1   //设置周期值  48  = 7200  6750=7200*45/48

  62. //原来的  1KHz = 44999次  15K = 3000次 20KHz = 2245次 30K=1499次

  63. //48/4*12 = 144000
  64. //144000/7200 = 20K
  65. //45/4*12 = 135000
  66. //135000/6570 = 20K
  67. void  delay(void);

  68. u16 PWM1_Duty;
  69. u16 PWM2_Duty;
  70. u16 PWM3_Duty;
  71. u16 PWM4_Duty;

  72. bit PWM1_Flag;
  73. bit PWM2_Flag;
  74. bit PWM3_Flag;
  75. bit PWM4_Flag;

  76. void PllConfig(void);
  77. void HSPwmConfig(void);
  78. void UpdatePwm(void);

  79. /********************** Timer0 1ms中断函数 ************************/
  80. void timer0(void) interrupt 1
  81. {
  82.     P41=~P41;
  83.     if(!PWM1_Flag)
  84.     {
  85.         PWM1_Duty++;
  86.         if(PWM1_Duty >= PWM_PERIOD) PWM1_Flag = 1;
  87.     }
  88.     else
  89.     {
  90.         PWM1_Duty--;
  91.         if(PWM1_Duty <= 0) PWM1_Flag = 0;
  92.     }

  93.     if(!PWM2_Flag)
  94.     {
  95.         PWM2_Duty++;
  96.         if(PWM2_Duty >= PWM_PERIOD) PWM2_Flag = 1;
  97.     }
  98.     else
  99.     {
  100.         PWM2_Duty--;
  101.         if(PWM2_Duty <= 0) PWM2_Flag = 0;
  102.     }

  103.     if(!PWM3_Flag)
  104.     {
  105.         PWM3_Duty++;
  106.         if(PWM3_Duty >= PWM_PERIOD) PWM3_Flag = 1;
  107.     }
  108.     else
  109.     {
  110.    
复制代码

免责声明:

本平台旨在开源共享精神,请勿发布敏感信息,任何违法信息我们将移交公安机关;

热门标签 更多

QQ|手机版|小黑屋|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-5-14 19:21 , Processed in 0.072438 second(s), 28 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

返回顶部