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

📄 acindmainstartware.c

📁 U15873EE1V0AN00 aplication note
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************
 *	File: acindMainStartWare.c
 *
 *	DESCRIPTION:	AC Induction Motor control demonstration
 *			(using constant V/Hz principle)for use on
 *			IA1 startWare board
 *
 *  AUTHOR:	S.Redpath 
 *
 *  HISTORY:   	Original	30th October 2001
 *		
 *
 *******************************************************************/

/** 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 **/
#define LED_LO  *((volatile UINT8*)0x400000) /*startWare MS display*/
#define LED_HI  *((volatile UINT8*)0x400001) /*startWare LS display*/

/* 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*/
static UINT8 softwareTimer=0;		/*Timer used for 10mS software timer*/
const UINT8 sevenSeg[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98}; /*seven segment display values*/
   



/** public functions **/
#ifdef GREENHILLS
void int_cc30(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 displayStartWare(UINT32 rpmData);
void speedCalc(void);



/*------------------------------------------------------------------------- 
 * 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:    CC30 interrupt servicing (200uS 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
   {
   #ifdef DEBUG
   P4BIT0 ^= 1;  /*toggle ouput DEBUG*/
   #endif

   PWMcalc();	 /*calculate PWM values*/

   #ifdef DEBUG
   P4BIT0 ^= 1;  /*toggle ouput DEBUG*/
   #endif
   
   if(++softwareTimer==50)/*10mS*/
       {
       #ifdef DEBUG
       P4BIT2 ^= 1;  /*toggle ouput DEBUG*/
       #endif
       
       speedCalc();	/*software timer has expired so do speed calc*/
       softwareTimer=0;	/*reset software timer*/
       
       #ifdef DEBUG
       P4BIT2 ^= 1;  /*toggle ouput DEBUG*/
       #endif
       }
           
   }/*end of int_cc30*/

/*------------------------------------------------------------------------- 
 * Function:    speedCalc
 * Description:  determines actual & orderd speeds and sets value for display
 * Parameter:	None
 * Returns:     None
 ---------------------------------------------------------------------------*/
 void speedCalc(void)
   {
   UINT16 orderedSpeed, actualSpeed;
   static UINT8 i=0,j;
   UINT32 rpmAverage;

   
   actualSpeed = getActualSpeed(); /*determine present speed of motor in units of rpm*/

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

   if(!(P2BIT1)) /*if P2.1=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 update count expired update rpm display value*/
   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(P2BIT0) /*if P2.0 set display actual speed*/
	      displayStartWare(rpmAverage);
      else
	      displayStartWare(orderedSpeed);

      i=0; /* reset update counter*/

      } /*end for i*/

   

   }/*end speedCalc()*/

/*------------------------------------------------------------------------- 
 * 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 */

	#ifdef DEBUG
	PMC4 = 0x00 ;
	PM4 = 0xF0 ; /* Sets DEBUG ports (3:0) to output*/
	#endif
		
	/*** Timer 3 mode setting for RTOS***********************************/
	PRM03 = 0 ; /* fclk = f/2 */
		
	#ifdef CLK40M
	TMC30 = 0x41; /* fclk/32  set TMC30 before TMC31 */
	TMC31 = 0x09 ; /* Selects compare mode */
	CC30 = 125 ; /* _int_cc30 200uS interval for 40MHz*/
	TMC30 = 0x43; /* Starts timer */
	#else
	TMC30 = 0x21; /* fclk/8 set TMC30 before TMC31 */
	TMC31 = 0x09 ; /* Selects compare mode */
	CC30 = 625 ; /* _int_cc30 200uS interval for 50MHz*/
	TMC30 = 0x23; /* Starts timer */
	#endif

	
	CC3IC0 = 0x03; /* Resets cc30 interrupt mask - level 3*/

	/*** Initial settings for ADC0 ******************************************************/
	ADSCM00 = 0x0000 ;
	ADSCM01 = 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*/

⌨️ 快捷键说明

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