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

📄 ramp.c

📁 3 phase motor driver source code with freescale MCU
💻 C
字号:
/*
 * Project:		 	3-PHASE AC DRIVE
 *
 * Microcontroller: Motorola MC68HC908MR24 
 *
 * Module:			RAMP.C
 * Revision/Date:	2.0 / February 2000  
 * Description:		This module contains two subroutines:
 * 					accel_ramp:	based on speed command (V_command) and 
 *								actual speed calculates new actual speed 
 *								(V_actual)
 *					vhz_ramp: 	based on output from PI controller (V_pi)
 *					        	calculates voltage scale for PWMcalc.c
 *					Both subroutines are called from PI.C routine.  
 *
 * Compiler:		Hiware08 Compiler
 *
 * Author:			Radim VISINKA
 * Company:			MOTOROLA SPS
 *					Motorola Czech Systems Laboratories  
 *					Roznov pod Radhostem, Czech Republic 
 *
 * ===================================================================
 *
 * Copyright (c):	MOTOROLA Inc.,1999, All rights reserved.
 *
 * ====================================================================
 * THIS SOFTWARE IS PROVIDED BY MOTOROLA RSAL "AS IS" AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL MOTOROLA RSAL OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 * ====================================================================
 */


/* DEFINITION_START */


/* Include Header Files */
#include "MR24IO.H"
#include "CONST.H"			/* file contains global constants and
							   definitions */


/* Assembler Subroutine Definitions */

/* Constant Definitions */
								

/* Global Variables (External) - 8 bit */
extern unsigned char Amplitude;		/* 0 to 255 gives 0 to 100% modulation*/
extern unsigned char Mcs_status;	/* Status register of MCS */


/* Global Variables (External) - 16 bit */
extern signed int Table_inc;		/* increment value for wave pointer update*/		
extern signed int V_out;			/* actual ramp speed */
extern signed int V_command;		/* command speed */
extern signed int V_com_actual;		/* actual speed command */
extern unsigned int Boost_slope;	/* Boost slope pre-calculation */
extern signed int Accel;
extern signed int Decel;


/* Local Variables - 8 bit */
unsigned char temp_y;				/* temp. 8 bit variable */
unsigned char temp_z;				/* temp. 8 bit variable */
unsigned int t_amplitude = 0;  

unsigned char flag1 = 0;			/* 8 bit flag register No.1 */ 
#define ramping  	0x01			/* flag for ramping in flag1 register*/

/* Local Variables - 16 bit */
unsigned int Temp_var_16;			/* temporary 2-bit variable */
signed int V_out_abs;				/* temp. ABS (V_pi) */
signed int Dv;						/* temporary ramp variable */
unsigned int Amplitude_16;			/* temporary 16-bit amplitude */

/* Local Variables - 32 bit */			  
unsigned long Temp_var_32;			/* temp. 32-bit variable */




/* DEFINITION_END */


		/*   SUBROUTINE  ACCEL_RAMP   */

void accel_ramp (void)
	{
					
/* determine whether the ramping flag should be set */

	  if (V_command != V_com_actual)
	  {
		flag1 |= ramping;	/* ramping in progress */
		Dv = Decel;
		Mcs_status &= (~(MCS_ACCEL));

		if (!((V_command ^ V_com_actual)&(0x8000)))	
		{					/* if SIGN(V_command) = SIGN(V_com_actual) */  
											
		  if (abs(V_com_actual) < abs(V_command)) 
		  {					/* if ABS(V_com_actual) < ABS(V_command) */
			Dv = Accel;		
			Mcs_status |= MCS_ACCEL;
		  }
		}  					/* now, appropriate dv is loaded */
		if (V_command > V_com_actual)
		{
		  V_com_actual += Dv;
		  if (V_com_actual >= V_command)
		  {					/* if final speed > command
								   finish ramping */
			V_com_actual = V_command;
			flag1 &= ~(ramping); 
		  }
		}
		else 
		{
		  V_com_actual -= Dv;
		  if (V_com_actual <= V_command)
		  {			 		/* if final speed < command
							   	   finish ramping */
			V_com_actual = V_command;
			flag1 &= ~(ramping);
		  }
		}
	  }
	}							

			/* SUBROUTINE VHZ_RAMP */

void vhz_ramp (void)
	{
  		/* Calculate wave increment Table_inc for rolling thru wavetable */
					
		Table_inc = V_out >> 4;	/* divide by 16 to get propper wave increment
									in 8.8 format for PWM reload=PWM/4 */	

		/* Calculate V/Hz ramp */
			
		V_out_abs = abs(V_out);

		if (V_out_abs < FREQ_BOOST)
		{					/* if ABS(V_out) < FREQ_BOOST */

		Temp_var_32 = (long)Boost_slope * (long)V_out_abs;
		Temp_var_16 = Temp_var_32 / FREQ_BOOST;
		Amplitude_16 = Temp_var_16 + (VOLTS_BOOST * 0x028f);
		Amplitude = Amplitude_16>>8; 	/* 16 to 8 bit */
		  	 
		}
		else
		{
		  if (V_out_abs < FREQ_BASE)
		  {				/* if FREQ_BOOST < ABS(V_out) < FREQ_BASE */
			Amplitude = V_out_abs/(FREQ_BASE>>8);			 			
		  }  
		  else				/* if ABS(V_out) > BASE_FREQ*/
		  {
		    Amplitude = 0xff;
		  }
		}   
	}

⌨️ 快捷键说明

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