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

📄 acindmain.c

📁 U15873EE1V0AN00 aplication note
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************
 *	File: acindMain.c
 *
 *	DESCRIPTION:	AC Induction Motor control demonstration
 *			(using constant V/Hz principle)
 *
 *  AUTHOR:	S.Redpath 
 *
 *  HISTORY:   	Original	28th August 2001
 *		V1.1		12th October 2001
 *				Added GHS compiler options
 *
 *******************************************************************/

/** include files **/
#include <stdlib.h>

#include "tools.h"

#ifdef IAR	/*use IAR compiler*/
#include <intrv850.h>
#include <io_v850e_df3116.h>
#else    /*greeenhills*/
#include "df3116.h"
#endif

#include "acind.h"

/** local definitions **/

/* default settings */
  
/** external functions **/
extern void PWMcalc(void);

/** external data **/



/** public data **/

UINT8 amplitude=0; /*amplitude of pwm sine wave*/
UINT8 tableInc=0;	 /* increment value for wave pointer update*/


UINT8 direction = CW;               /*direction of rotation of motor*/

/** private data **/
static UINT16 speedDemand[SPEED_READS]; /*array for storing speed demand readings*/
static UINT16 speedDemandAv=0; /*running average of speed readings*/
static UINT16 rpmReads[DISPLAY_UPDATE_RATE];  /*array for storing RPM readings*/



/** public functions **/
#ifdef GREENHILLS
void int_cc30(void);
void int_cm4(void);
#endif


/** private functions **/
void basicConfig(void);
void hinit();
void setVFprofile(UINT16);
UINT16 getSpeedDemand(void);
UINT16 getActualSpeed(void);
UINT16 getAnalogOrderedSpeed(void);
UINT16 getDigitalOrderedSpeed(void);
UINT16 PIControl(SINT32);
void display();



/*------------------------------------------------------------------------- 
 * Function:    main
 * Description: Main entry point for 3 Phase Induction motor controller
 *				      using V850E/IA1
 * Parameter:	None
 * Returns:     None
 ---------------------------------------------------------------------------*/
void main()
   {
	int i;
	
	/*configure clocks*/
	basicConfig();
   	
	/*initialize timers, ports etc*/
	hinit();

	/* */
	__EI() ; /* Interrupt enabled */

	
	for ( i = 40000 ; i != 0 ; i-- ) ;

        POER0 = 0x3f ; /* All phases active */

  	while( 1 ) 
		{
		} /*end while*/

	
	}/*end of main*/

/*------------------------------------------------------------------------- 
 * Function:    TM4 interrupt servicing (200uS Interval)
 * Description:  Calls PWM calculation
 * Parameter:	None
 * Returns:     None
 ---------------------------------------------------------------------------*/
#ifdef IAR
#pragma vector=INTCM4_vector
__interrupt void int_cm4(void)
#else
#pragma ghs interrupt
void int_cm4(void)
#endif
    {
    P2BIT0 ^= 1;  /*toggle ouput DEBUG*/

    PWMcalc();
    
    P2BIT0 ^= 1;  /*toggle ouput DEBUG*/

    }/*end of imt_cm4*/

/*------------------------------------------------------------------------- 
 * Function:    CC30 interrupt servicing (10 ms interval)
 * Description: 
 * Parameter:	None
 * Returns:     None
 ---------------------------------------------------------------------------*/
#ifdef IAR
#pragma vector = INTCC30_vector
__interrupt void int_cc30(void)
#else
#pragma ghs interrupt
void int_cc30(void)
#endif
   {
   UINT16 orderedSpeed, actualSpeed;
   static UINT8 i=0,j;
   UINT32 rpmAverage;
   
   P2BIT2 ^= 1;  /*toggle ouput DEBUG*/
      
   actualSpeed = getActualSpeed(); /*determine present speed of motor in units of rpm*/

   orderedSpeed = getDigitalOrderedSpeed(); /*determined ordered speed in units of rpm*/

   if(!(P3BIT5)) /*if P3.5=0 (switch 'ON') do PI control*/
      speedDemandAv=PIControl(orderedSpeed - actualSpeed);  /* use PI algorithm for speed control*/

   setVFprofile(speedDemandAv); /*set Voltage/Frequency according to speed demand*/

   rpmReads[i]=actualSpeed; /*store current RPM reading*/


   /*if sw timer expired update rpm display*/
   if(++i==DISPLAY_UPDATE_RATE){
       
       rpmAverage=0; /*clear previous average value*/
      
      for(j=0;j<DISPLAY_UPDATE_RATE;j++)  /*add all RPM readings together*/
         {
         rpmAverage+=rpmReads[j];
         }

      rpmAverage/= DISPLAY_UPDATE_RATE; /*calculate average*/

      if(P3BIT4) /*if P3.4 set display actual speed*/
	  display(rpmAverage);
      else
	  display(orderedSpeed);

      i=0; /* reset update counter*/
      }

      P2BIT2 ^= 1;  /*toggle ouput DEBUG*/
           
	}/*end of int_cc30*/



/*------------------------------------------------------------------------- 
 * Function:    hinit
 * Description:  Peripheral I/O initialization
 * Parameter:	None
 * Returns:     None
 ---------------------------------------------------------------------------*/
void hinit( void )
	{
	//void led_out( int ) ;
	/*** Port mode register initialization *********************************************************/
	PMC1 = 0x07 ; /* Selects encoder input */
	PMC2 = 0x00 ;
	PM2 = 0x00 ; /* Sets LED display port */
	PMC4 = 0x00 ;
	PM4 = 0x00 ; /* Sets LED display blanking port */
		
	/*** Timer 3 mode setting ****************************************************************/
	PRM03 = 0 ; /* fclk = f/2 */
	TMC30 = 0x51; /* fclk/128 (5.12 uS(50MHz) or 6.4uS(40MHz)) */
	TMC31 = 0x09 ; /* Selects compare mode */
	#ifdef CLK40M
	CC30 = 3125 ; /* _int_cc30 10 ms interval for 40MHz*/
	#else
	CC30 = 3906 ; /* _int_cc30 10 ms interval for 50MHz*/
	#endif
	TMC30 = 0x53; /* Starts timer */
	CC3IC0 = 0x03; /* Resets cc30 interrupt mask - level 3*/

	/*** Timer 4 mode setting ****************************************************************/
	TMC4 = 0x51 ; /* f (4 or 5 MHz)*10/128 ( 6.4uS or 5.12 uS) */
   #ifdef CLK40M
	CM4 = 62 ; /* _int_cm4 200uS interval for 40MHz*/
   #else
	CM4 = 78 ; /* _int_cm4 200uS interval for 50MHz*/
	#endif

	TMC4 = 0x53 ; /* Starts timer */
	CM4IC0 = 0x02 ; /* Clears cm4 interrupt mask - level 2*/

	/*** Initial settings for ADC0 and ADC1 ******************************************************/
	ADSCM00 = 0x0000 ;
	ADSCM01 = 0x0000 ;

	/*** Initial setting for ANI10 ***************************************************************/
	ADSCM10 = 0x0000 ;
	ADSCM11 = 0x0000 ;
	
	/*start ADC Conversion*/
   ADSCM00 = 0x9801; /*select mode, A/D polling mode channel ANI01*/
	
	
	/*** Timer 00 (TM00) initialization **********************************************************/
	PRM01 = 0 ; /* f m = f /2 */
	SPEC0 = 0x0000 ; /* TOMR0 write enabled */
	
	#ifdef SINE_INVERT
	TOMR0 = 0x88 ; /* Output mode setting*/
	#else
	TOMR0 = 0xF8 ; /* Output mode setting*/
	#endif
	
	PSTO0 = 0x00 ; /* Real-time output prohibited */
	BFCM00 = BFCM_DATA/2 ; /* Sets 50% duty */
	BFCM01 = BFCM_DATA/2 ; /* Sets 50% duty */
	BFCM02 = BFCM_DATA/2 ; /* Sets 50% duty */
	BFCM03 = CM3_DATA ; /* Sets PWM cycle */
	
	#ifdef SINE_INVERT
	DTRR0 = 50 ; /* Dead time: 2 uS */
	#endif
	
	POER0 = 0x3f ; /* All phases active */
	
	#ifdef SINE_INVERT
	TMC00 = 0x8018 ; /* Starts TM00 timer with dead timer enabled*/
	#else
	TMC00 = 0x8038 ; /* Starts TM00 timer with dead timer disabled*/
	#endif

	/*** Timer 10 (TM10) initialization **********************************************************/
	PRM02 = 1 ; /* f m = f /4 */
	NRC10 = 0x03 ; /* Selects noise elimination clock */
	TUM0 = 0x80 ; /* Selects UDC mode A*/
	PRM10 = 0x07 ; /* Select operation mode 4 */
	SESA10 = 0x00 ; /* Selects falling edge */
	TMC10 = 0x40 ; /* Starts count */

	}/*end of hwinit*/

 /*------------------------------------------------------------------------- 

⌨️ 快捷键说明

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