⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 temptest03.c

📁 基于DSP的温度控制系统(开发环境:CCS)
💻 C
字号:
/*
  This programme to test the relation between temperature feedback and PWM
  Keep speed in 4s, Test speed in 1s, then change PWM
  This test will last 91*5s, the temperature of furnace will higher and higher,
  when the speed slow down, the test is OK!
  The result is in the temp array!
*/
#pragma CODE_SECTION(vect,"vect")
#include <stdio.h>

void TEMPcontrol(void);
void testint1(void);

#define IMR   *(pmem+0x0000)  
#define IFR   *(pmem+0x0001)  
#define PMST  *(pmem+0x001D)  
#define SWCR  *(pmem+0x002B)  
#define SWWSR *(pmem+0x0028)  

/* timer 0 */
#define TIM0  *(pmem+0x0024)  /* timer0 register */
#define PRD0  *(pmem+0x0025)  /* timer0 period register */
#define TCR0  *(pmem+0x0026)  /* timer0 control register */

#define Len1 1500
#define Len2 50
unsigned int  *pmem=0;
unsigned int  flagc,flagt;
int i,j,n,m;
int TIMER1,TIMER2;           /* 1s counter and 5s counter  */
int pw,nw;                   /* positive pulse width and negative pulse width */
int feedback1 = 0;                /* INT1 counter to count the speed */
int feedback2 = 0;
int *feed =(int *)0x1006;
int temp1[Len1],temp2[Len2];               /* To store the speed in different PWM during 1s */

void cpu_init()
{
	asm(" NOP");
	asm(" STM #0, CLKMD");   
	asm(" STM #0, CLKMD");   
	asm(" STM #0xf007, CLKMD");
//	asm(" STM #0x97ff, CLKMD"); //set C5402 DSP clock to 100MHz	 
	asm(" rpt  #0ffffh");
	asm(" nop");
	
	PMST=0x3FA0;
	SWWSR=0x7fff;
	SWCR=0x0000;
	IMR=0;
	IFR=IFR;
	asm(" stm 1000h,ar1");
	asm(" stm 1006h,ar6");
	asm(" stm 1008h,ar7");
} 

interrupt void int1()   
{
	asm (" portr 800ch , *ar6");
	
	feedback2 = *feed;
	
	flagc=flagc^1;	
	
	if(flagc==1)
	{ 	asm(" st 0h,*ar7");
		asm(" portw *ar6,800ah");}
	else
	{	asm(" st 0ffffh,*ar7");
	 	asm(" portw *ar6,800ah");}

} 

void set_int()    
{
	asm(" ssbx intm");
	TCR0=0x0b1b;
	PRD0=0x4e1f;       
	IMR=IMR|0x000a;  
	IFR=IFR;
	TCR0=0x0b29;
	asm(" rsbx intm");  
}

interrupt void tint0()
{
	TIMER1++;

	if(TIMER1==50)       /* 1s */
	{	
		flagt = flagt^1;
		TIMER2++;
		TIMER1 = 0;
		
		feedback1 = *feed;         /* Read AD, to get the feedback */
	
		if (feedback1==feedback2)
		  
		{temp1[m] = feedback1;}

		m++;

		if (TIMER2==30)   /* 30s */  
		{
			if (n<Len2)
			{	
			    temp2[n] = feedback1;
				feedback1 = TIMER2 = 0;
				n++;
			}
		}
	}

	feedback1 = feedback2 = 0;                 
} 

void TEMPcontrol()
{	
	asm(" st  0ffh,*ar2");
	asm( " portw  *ar2,800bh");
	for(i=0;i<=pw;i++) 
	{
      	j=0;
      	j=0;
      	j=0;
      	j=0;
      	j=0;
	}
		
	asm(" st  80h,*ar2");
	asm( " portw  *ar2,800bh");
    for(j=0;j<=nw;j++) 
	{
        i=0;
      	i=0;	
      	i=0;
      	i=0;
      	i=0;
	 }
}

void main(void)
{
	cpu_init();

	pw = 10000*0.1;
	nw = 10000*0.9;

	for (i=0; i<Len1; i++)
	{temp1[i]=0;}
	for (i=0; i<Len2; i++)
	{temp2[i]=0;}
	flagc = flagt = 0;
	i=j=m=n=feedback1 = feedback2 = 0;
	TIMER1 = TIMER2 =0;

	set_int();

	for(;;)
	{
		if(flagt==1) {asm(" ssbx xf");}
		else         {asm(" rsbx xf");}

		TEMPcontrol();
	}
}

void vect()
{
   asm(" .ref _c_int00");/*pseudoinstruction*/
   asm(" .ref _int1");

   asm(" b _c_int00");/* reset */  
   asm(" nop");
   asm(" nop");
   asm(" rete");        
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");       /* int0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" b _int1");       /* int1 */
   asm(" nop");
   asm(" nop");
   asm(" rete");       /* int2 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" b _tint0");      /* tint0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");       /* brint0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");       /* bxint0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");      /* dmac0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");       /* tint1 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");       /* int3 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");       /* hpint */
   asm(" nop");
   asm(" nop");
   asm(" rete");       /* brint1 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");       /* bxint1 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");       /* dmac4 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");      /* dmac5 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -