一个奇怪的问题:AI8051U使用追频后,做一个特定的浮点会...
2024-9-11 10:35 来自 zhx 发布 @ 综合讨论
AI8051U追频后,使用TFPU做一个特定的浮点会复位,
不追频,没有问题,
不做浮点计算,也没有问题
不用TFPU,也没有问题
复制代码
不追频,没有问题,
不做浮点计算,也没有问题
不用TFPU,也没有问题
- #include "AI8051U.h"
- #include "stdio.h"
- #include "intrins.h"
- typedef signed char int8_t;
- typedef signed int int16_t;
- typedef signed long int32_t;
- typedef unsigned char uint8_t;
- typedef unsigned int uint16_t;
- typedef unsigned long uint32_t;
- typedef unsigned char u8;
- typedef unsigned int u16;
- typedef unsigned long u32;
- #define MAIN_Fosc 45000000UL
- #define Timer0_Reload (65536UL -(MAIN_Fosc / 1000)) //Timer 0 中断频率, 1000次/秒
- //==========================================================================
- #define HSCK_MCLK 0
- #define HSCK_PLL 1
- #define HSCK_SEL HSCK_PLL
- #define PLL_96M 0
- #define PLL_144M 1
- #define PLL_SEL PLL_96M
- #define CKMS 0x80
- #define HSIOCK 0x40
- #define MCK2SEL_MSK 0x0c
- #define MCK2SEL_SEL1 0x00
- #define MCK2SEL_PLL 0x04
- #define MCK2SEL_PLLD2 0x08
- #define MCK2SEL_IRC48 0x0c
- #define MCKSEL_MSK 0x03
- #define MCKSEL_HIRC 0x00
- #define MCKSEL_XOSC 0x01
- #define MCKSEL_X32K 0x02
- #define MCKSEL_IRC32K 0x03
- #define ENCKM 0x80
- #define PCKI_MSK 0x60
- #define PCKI_D1 0x00
- #define PCKI_D2 0x20
- #define PCKI_D4 0x40
- #define PCKI_D8 0x60
- /************* 本地常量声明 **************/
- #define PWM1_0 0x00 //P:P1.0 N:P1.1
- #define PWM1_1 0x01 //P:P0.0 N:P0.1
- #define PWM1_2 0x02 //P:P2.0 N:P2.1
- #define PWM2_0 0x00 //P:P1.2 N:P1.3
- #define PWM2_1 0x04 //P:P0.2 N:P0.3
- #define PWM2_2 0x08 //P:P2.2 N:P2.3
- #define PWM3_0 0x00 //P:P1.4 N:P1.5
- #define PWM3_1 0x10 //P:P0.4 N:P0.5
- #define PWM3_2 0x20 //P:P2.4 N:P2.5
- #define PWM4_0 0x00 //P:P1.6 N:P1.7
- #define PWM4_1 0x40 //P:P0.6 N:P0.7
- #define PWM4_2 0x80 //P:P2.6 N:P2.7
- #define ENO1P 0x01
- #define ENO1N 0x02
- #define ENO2P 0x04
- #define ENO2N 0x08
- #define ENO3P 0x10
- #define ENO3N 0x20
- #define ENO4P 0x40
- #define ENO4N 0x80
- #define PWM_PERIOD 6750-1 //设置周期值 48 = 7200 6750=7200*45/48
- //原来的 1KHz = 44999次 15K = 3000次 20KHz = 2245次 30K=1499次
- //48/4*12 = 144000
- //144000/7200 = 20K
- //45/4*12 = 135000
- //135000/6570 = 20K
- void delay(void);
- u16 PWM1_Duty;
- u16 PWM2_Duty;
- u16 PWM3_Duty;
- u16 PWM4_Duty;
- bit PWM1_Flag;
- bit PWM2_Flag;
- bit PWM3_Flag;
- bit PWM4_Flag;
- void PllConfig(void);
- void HSPwmConfig(void);
- void UpdatePwm(void);
- /********************** Timer0 1ms中断函数 ************************/
- void timer0(void) interrupt 1
- {
- P41=~P41;
- if(!PWM1_Flag)
- {
- PWM1_Duty++;
- if(PWM1_Duty >= PWM_PERIOD) PWM1_Flag = 1;
- }
- else
- {
- PWM1_Duty--;
- if(PWM1_Duty <= 0) PWM1_Flag = 0;
- }
- if(!PWM2_Flag)
- {
- PWM2_Duty++;
- if(PWM2_Duty >= PWM_PERIOD) PWM2_Flag = 1;
- }
- else
- {
- PWM2_Duty--;
- if(PWM2_Duty <= 0) PWM2_Flag = 0;
- }
- if(!PWM3_Flag)
- {
- PWM3_Duty++;
- if(PWM3_Duty >= PWM_PERIOD) PWM3_Flag = 1;
- }
- else
- {
免责声明:
本平台旨在开源共享精神,请勿发布敏感信息,任何违法信息我们将移交公安机关;