📄 main.c
字号:
/* ===================================================================== */
/* File name : MAIN.C */
/* Author: HU QINGBO */
/* Data: 2006.9.29 */
/* Version: 1.0 */
/* Organization: DSP MOTO CONTROL PROGROM
/* Zhejiang Tianhuang Techonology Industry Ltd., */
/* Description : C-PROGRAM TO CONTROL A DC USE F2407A */
/* ================================================================== */
/* 头文件 */
#include "F2407_c.H"
#include "CONSTANT.H"
#include <stdio.h>
#include <math.h>
extern int ia,ib,thet,speed_test,t2_sum;
extern unsigned cmp1,cmp2,cmp3;
int current_counter=CUR_COUNTER_CON,speed_counter=SPEED_COUNTER_CON;
int t2count_new=0,t2count_old=0,t2count_err=0,t2count_sum=0;
/* =============================================================== */
/* =============================================================== */
main()
{
system_initial(); //系统时钟建立
ad_initial();
io_initial();
spi_initial(); //SPI初始化
ev_initial();
cap_initial();
sci_initial();
xint_initial();
variable_initial();
current_counter = CUR_COUNTER_CON; //电流PI循环次数
speed_counter = SPEED_COUNTER_CON; //速度PI循环次数
IMR=0X22;
T1CON = T1CON | 0x0040; //开启定时器1
asm(" clrc INTM"); //中断使能
while(1)
{
}
}
/* ==================================================================*/
/* 定时器1周期中断子程序 */
void interrupt T1INT() //定时器1周期中断----测试用
{
asm(" CLRC SXM");
ia=RESULT0>>6;
ib=RESULT1>>6;
ADCTRL2=0X4000;
asm(" nop");
ADCTRL2=0X2000;
asm(" SETC SXM");
ia=ia-512;
ib=ib-512;
t2count_new = T2CNT;
t2count_err=t2count_new-t2count_old;
t2count_old=t2count_new;
t2count_sum=t2count_sum+t2count_err;
thet=thet+t2count_err;
if(thet<0)
thet=thet+4096;
else if(thet>=4096)
thet=thet-4096;
Sincos();
current_clarke();
speed_counter--;
if (speed_counter ==0)
{
t2_sum=t2count_sum;
t2count_sum=0;
speed_counter = SPEED_COUNTER_CON; //赋初值
speed_pi_loop();
}
current_pi_loop();
park_inv();
swpwm_modulation();
CMPR1=cmp1;
CMPR2=cmp2;
CMPR3=cmp3;
EVAIFRA = 0X0080; //清中断标志,以进行下次中断
asm(" clrc INTM");
return;
}
/* =================================================================== */
/* 空中断子程序 */
void interrupt nothing()
{
asm(" clrc INTM");
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -