📄 bpxz.c
字号:
/* 自动式变频谐振控制箱 */
/****************************************************************/
/* */
/* Auto control bpxz box */
/* Copyright (c) 2004, wuhan huadian Technology Inc */
/* */
/* SCCSID @(#)TMS320F206PZ */
/* */
/* Author : jacky-cheung R&D engineer of huandian */
/* Author email: jacky-cheung@sohu.com */
/* Filename : bpxz.C */
/* osc : 20MHz */
/* Release : 2.0 */
/* Revision History : 2004-08-14 10:00 */
/* */
/****************************************************************/
#include <c:\tic2xx\c2000\cgtools\include\stdio.h>
#include <c:\tic2xx\c2000\cgtools\include\math.h>
#include <c:\tic2xx\c2000\cgtools\include\stdlib.h>
#include "page.h"
#include "f206.h"
#include "tyclh.h"
#define uint unsigned int
#define uchar unsigned char
#define N 64
#define pii 3.1415926535898
#define sqrt_3 1.73205080756887729352744634150587
/*-------------------------------------------------------------------*/
//interrupt void sx_protect(); //失谐保护中断
//interrupt void G_earth(); //接地保护中断
interrupt void time_int(); //定时器中断
/*-------------------------------------------------------------------*/
uint keynSerial;
extern int adt,nNewSysDataRdPreAdr;
extern struct StructKeyNode KeyNode ;
extern Boolean bRefurbish,bNewData,bNewSysRdData,bNewKey;
extern double uktest[10];
extern double avg(double *ap,int n);
long int fall=0x17a0,autoflag=0x0055,autovok=0x0055; //自动调频频率缓存,自动调频结束标志,自动调压结束标志
double autovsav=0.0; //自动调压电压缓存
long int autoff=0x55,autofg=0x55;
uint sa0=0,sa1=0,sa2=0;
double pi[64],pu[64],sffg[4];
int U11[N+5],U12[N+5],fg=0;
int nTbSysTime;
long int vopp,iopp;
double px[64],fr[64],fi[64];
float harm1=0.0,harm3=0.0,harm5=0.0,harm7=0.0,harmall=0.0;
int harm[9]={0,0,0,0,0,0,0,0,0};
/*上传信息*/
double uup=0.0,fup=0.0,cx=0.0,voup=0.0; //实验电压显示,实验频率显示,试品电容显示,实验结果电压显示
long int iup=0,syzt=0,bhflag=0; //试验电流显示,实验状态显示,保护标志显示
long int timeff=0,timemm=0; //试验时间显示分,实验时间显示秒
long int time =0; //定时变量
int sine[100]; //波形数组
long int sinenumber=0;
long int spflag=0;
/*下传信息*/
long int vop,iop,fstart,conduter; //过压整定,过流整定,起始频率,电感设置
long int timef,timem; //试验时间设置分,实验时间设置秒
double vo; //实验设置电压
uint arrow; //0--up,1--down
typedef
volatile unsigned int pointer;
volatile unsigned int *reg_pointer;
void zero_sa4828();
void chuansong();
void sinedisp();
void zero1_sa4828();
void harmonic();
//const int aa[3]={1,2,3 };
/******************************************************************/
/*===========================Initialization DSP============================*/
void InitSystem(void)
{
asm(" setc intm ");
asm(" clrc CNF");
asm(" ldp #0h");
reg_wsgr=0xffff;
reg_pointer=(pointer *)reg_ifr;
*reg_pointer=0xffff;
reg_pointer=(pointer *)reg_greg;
*reg_pointer=0x0000;
TbTxInit();
reg_tcr=0x0c27;
reg_prd=1999;
nTbSysTime=0x5555;
reg_pointer=(pointer *)reg_imr;
*reg_pointer=0x001c;
reg_icr=0x001c;
reg_aspcr=0x0002;
reg_iosr =0xffff;
asm(" clrc intm ");
}
interrupt void nopp()
{
asm(" setc intm ");
asm(" nop ");
asm(" nop ");
asm(" clrc intm ");
}
/*interrupt void sx_protect()
{
asm(" setc intm ");
iRe_sa4828();
iInit_sa4828();
bhflag=0x0003;
asm(" clrc intm ");
}*/
/*interrupt void G_earth()
{
asm(" setc intm ");
earth=0xaa; /*EARTH error*
reg_icr=0x001d;
asm(" clrc intm ");
}*/
interrupt void time_int()
{
asm(" setc intm ");
nTbSysTime++;
if(autovok==0x00aa)
{
time=time+1;
}
asm(" clrc intm ");
}
/*=================================================================*/
void sample()
{
uint i;
uint t=500;
max125=0x01;
for(i=0; i<N+5; i++)
{
while((((reg_iosr)&0x0004)==0x0004)&&(t!=0))
{
t=t-1;
}
if(t==0)
{
for(i=0;i<=N+5;i++)
{
U11[i]=0;
U12[i]=0;
}
}
else
{
U11[i]=(max125&0x3fff);
U12[i]=(max125&0x3fff);
t=1000;
}
}
for(i=0; i<N+5; i++)
{
U11[i]=(U11[i]<<2);
U12[i]=(U12[i]<<2);
}
for(i=0; i<N; i++)
{
pu[i]=(double)U11[i+2]*5.00/32768.0;
pi[i]=(double)U12[i+2]*5.00/32768.0;
}
}
/*========================================================================*/
float rms2()
{
int i,j=0;
double c12=0.0;
for(i=0;i<N;i++)
{
c12=c12+pu[i]*pu[i];
}
c12=8.8*sqrt(c12/N);
/*c12=sqrt(c12/N)*9.334335655;/*2.832861*3.010526;*/
return(c12);
}
uint rms1()
{
uint i,j;
double c11=0.0;
for(i=0;i<N;i++)
{
c11=c11+pi[i]*pi[i];
}
c11=sqrt(c11/N)*10;
j=(uint)(c11);
return(j);
}
void dlus(uint tm)
{
uint a;
for(a=0;a<=tm;a++)
{;}
}
void dlms(uint j)
{
uchar i;
for(i=0;i<j;i++)
{dlus(30000);}
}
void vauto() /*自动调压*/
{
if(autoflag==0x00aa)
{
if((uup<vo*0.99)&&(sa2<=254))
{
sa2=sa2+1;
}
if((uup>vo*1.01)&&(sa2>=1))
{
sa2=sa2-1;
}
if((vo*0.99<=uup)&&(uup<=vo*1.01))
{
autovok=0x00aa;
}
}
Cont_sa4828(sa0,sa1,sa2);
dlus(20000);
}
void preautof()
{
sa0=fall&0x00ff;
sa1=(fall>>8)&0x00ff;
sa2=0x20; /*初始电压*/
Cont_sa4828(sa0,sa1,sa2);
autoff=0xaa;
dlms(80);
}
void autof() /*自动调频*/
{
if(autoflag==0x0055)
{
if(arrow==0)
{
if((autovsav<=(uup+0.01))&&(uup<1.5)&&(autofg==0x55))
{
autovsav=((autovsav>uup)?autovsav:uup);
if(fall<=60400)
{
fall=fall+20;
sa0=fall&0x00ff;
sa1=(fall>>8)&0x00ff;
sa2=0x20; /*初始电压*/
Cont_sa4828(sa0,sa1,sa2);
}
}
else
{ if(autovsav<=(uup+0.01))
{
autovsav=((autovsav>uup)?autovsav:uup);
if(fall<=60400)
{
fall=fall+1;
sa0=fall&0x00ff;
sa1=(fall>>8)&0x00ff;
sa2=0x20; /*初始电压*/
Cont_sa4828(sa0,sa1,sa2);
dlus(30000);
autofg=0xaa;
}
}
else
{autoflag=0xaa;cx =25336.2/(fup*fup*((double)conduter));}
}
}
else
{
if((autovsav<=(uup+0.01))&&(uup<1.5)&&(autofg==0x55))
{
autovsav=((autovsav>uup)?autovsav:uup);
if(fall>=0x17a0)
{
fall=fall-20;
sa0=fall&0x00ff;
sa1=(fall>>8)&0x00ff;
sa2=0x20; /*初始电压*/
Cont_sa4828(sa0,sa1,sa2);
}
}
else
{ if(autovsav<=(uup+0.01))
{
autovsav=((autovsav>uup)?autovsav:uup);
if(fall>=0x17a0)
{
fall=fall-1;
sa0=fall&0x00ff;
sa1=(fall>>8)&0x00ff;
sa2=0x20; /*初始电压*/
Cont_sa4828(sa0,sa1,sa2);
dlus(30000);
autofg=0xaa;
}
}
else
{autoflag=0xaa;cx =25336.2/(fup*fup*((double)conduter));}
}
}
}
else
{
;
}
}
void timedisp(void) /*自动调频计时*/
{
long int i;
if((syzt==0)&&(autovok==0x00aa)&&(bhflag==0))
{
i =time/1000;
timeff=i/60;
timemm=i%60;
}
if((timef==timeff)&&(timem<=timemm))
{
syzt=1;
zero1_sa4828();
//chuansong();
}
else
{;}
}
void sdtf() /*---------------手动调频-----------------*/
{
if(((reg_iosr)&0x0001)==0x0000) /*IO0---+;BIO----_*/
{
if(fall<=60400)
{
fall=fall+20;
sa0=fall&0x00ff;
sa1=(fall>>8)&0x00ff;
if(sa2==0)
{
sa2=0x20;
}
else
{;}
}
}
asm(" BCND execution,BIO ");
asm(" nop ");
asm(" b inexecution ");
asm("execution: ");
if(fall>=6040)
{
fall=fall-20;
sa0=fall&0x00ff;
sa1=(fall>>8)&0x00ff;
if(sa2==0)
{
sa2=0x20;
}
else
{;}
}
else
{;}
asm("inexecution: ");
asm(" nop ");
}
void sdty() /*----------------手动调压-----------------*/
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -