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

📄 pwmart.lst

📁 该程序是ST7MC驱动三洋压缩机(交流)
💻 LST
📖 第 1 页 / 共 2 页
字号:
ANSI-C/cC++ Compiler for ST7 V-5.0.7, Aug 21 2001

    1:  /**************** (c) 2004  STMicroelectronics ********************************
    2:       
    3:  PROJECT  : 3-phase AC induction motor drive Software Library
    4:  COMPILER : COSMIC / METROWERKS
    5:  
    6:  MODULE  :  pwmart.c
    7:  VERSION :  1.0.0
    8:  
    9:  CREATION DATE : April 2004
   10:  
   11:  AUTHOR :	V. Onde / Microcontroller Division Applications
   12:  			Consumer & Micro Group
   13:  
   14:  -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
   15:  
   16:  DESCRIPTION :   PWM Auto Reload timer low level routines
   17:                
   18:  -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
   19:  
   20:  MODIFICATIONS :
   21:                        
   22:  *******************************************************************************
   23:   THE SOFTWARE INCLUDED IN THIS FILE IS FOR GUIDANCE ONLY. ST MICROELECTRONICS
   24:   SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES
   25:   WITH RESPECT TO ANY CLAIMS ARISING FROM USE OF THIS SOFTWARE.
   26:  ******************************************************************************/
   27:  
   28:  #include "lib.h"		/* General purpose typedefs and macros */
   29:  #include "ST7FMC2N6.h"	/* ST7FMC peripherals Hardware Registers declaration */
   30:  #include "pwmart.h"		/* Public PWMART function prototypes */
   31:  
   32:  
   33:  #define TB_UNIT		((u8)0x06)	/* 1ms Time base given by 250 (256-6) clock 
   34:  												cycles @ Fin/32 (250kHz) */
   35:  
   36:  volatile u8 DebounceButton;
   37:  
   38:  /*--------------- Private Variables declaration section ---------------------*/
   39:  
   40:  static volatile u8  TimeBaseStatus;
   41:  static volatile u8  Status;
   42:  
   43:  static volatile u8  RegCounter;
   44:  static volatile u8  RegTimeBase;
   45:  
   46:  static volatile u8  WdgTimeBase;
   47:  static volatile u8  WdgCounter;
   48:  
   49:  static volatile u16 TimeOutCounter;
   50:  static volatile u16 TimeOutPeriod;
   51:  
   52:  static volatile u16 SequenceCounter;
   53:  static volatile u16 SequencePeriod;
   54:  
   55:  static volatile u16 ms_Counter;
   56:  static volatile u16 ms_TimeBase;
   57:  
   58:  static volatile u16  MainCounter;
   59:  static volatile u16  MainTimeBase;
   60:  
   61:  /* TimeBaseStatus flags description */
   62:  #define TIMEOUT_ELAPSED			((u8)0x01)
   63:  #define REG_PERIOD_ELAPSED		((u8)0x02)
   64:  #define SEQUENCE_COMPLETED		((u8)0x04)
   65:  #define MS_TIME_ELAPSED			((u8)0x08)
   66:  #define TIMEOUT_LOCK			((u8)0x10)
   67:  #define SEQUENCE_LOCK			((u8)0x20)
   68:  #define MS_TIME_LOCK			((u8)0x40)
   69:  #define MAIN_TIMEBASE_ELAPSED	((u8)0x80)
   70:  
   71:  // Status flag
   72:  #define WDG_TIMEBASE_ELAPSED ((u8)0x01)
   73:  /*-----------------------------------------------------------------------------
   74:  ROUTINE NAME : ART_Init
   75:  INPUT/OUTPUT : None
   76:  
   77:  DESCRIPTION  : 
   78:  
   79:  COMMENTS     : 
   80:  -----------------------------------------------------------------------------*/ 
   81:  void ART_Init(void)
   82:  {

Function: ART_Init
Source  : ..\..\source\pwmart.c
Options : -Cc -F7 -Lasm=%n.lst -Ml -N -Os -Ou -Of -Ol0 -OnPMNC -Or

   83:  	ARTICCSR = 0;	// No capture
  0000 3f00     CLR   ARTICCSR
   84:  	PWMCR = 0;		// No PWM
  0002 3f00     CLR   PWMCR
   85:  	ARTCAR = 0;		// Reset counter
  0004 3f00     CLR   ARTCAR
   86:  	ARTCSR = 0;		// Clr pending OVF interrupt
  0006 3f00     CLR   ARTCSR
   87:  	
   88:  	ARTARR = TB_UNIT;		// Time base Unit also depends from CLK prescaler below
  0008 a606     LD    A,#6
  000a b700     LD    ARTARR,A
   89:  	// Set clock Fin by 32, force reload, enable OVF int
   90:  	ARTCSR = ARTCSR_CC2_OR + ARTCSR_CC0_OR + ARTCSR_FCRL_OR + ARTCSR_OIE_OR;
  000c a656     LD    A,#86
  000e b700     LD    ARTCSR,A
   91:  
   92:  	// Init software time bases variables
   93:  	TimeBaseStatus	= 0;
  0010 4f       CLR   A
  0011 c70000   LD    TimeBaseStatus,A
   94:  	Status = 0;
  0014 c70000   LD    Status,A
   95:  	TimeOutCounter	= U16_MAX;
  0017 43       CPL   A
  0018 c70001   LD    TimeOutCounter:1,A
  001b c70000   LD    TimeOutCounter,A
   96:  	TimeOutPeriod	= U16_MAX;
  001e c70001   LD    TimeOutPeriod:1,A
  0021 c70000   LD    TimeOutPeriod,A
   97:  	RegCounter		= U8_MAX;
  0024 c70000   LD    RegCounter,A
   98:  	RegTimeBase		= U8_MAX;
  0027 c70000   LD    RegTimeBase,A
   99:  	SequenceCounter	= U16_MAX;
  002a c70001   LD    SequenceCounter:1,A
  002d c70000   LD    SequenceCounter,A
  100:  	SequencePeriod	= U16_MAX;
  0030 c70001   LD    SequencePeriod:1,A
  0033 c70000   LD    SequencePeriod,A
  101:  	ms_Counter		= U16_MAX; 
  0036 c70001   LD    ms_Counter:1,A
  0039 c70000   LD    ms_Counter,A
  102:  	ms_TimeBase		= U16_MAX;
  003c c70001   LD    ms_TimeBase:1,A
  003f c70000   LD    ms_TimeBase,A
  103:  	MainTimeBase 	= U16_MAX;
  0042 c70001   LD    MainTimeBase:1,A
  0045 c70000   LD    MainTimeBase,A
  104:  	MainCounter 	= U16_MAX;
  0048 c70001   LD    MainCounter:1,A
  004b c70000   LD    MainCounter,A
  105:  
  106:  	WdgTimeBase		= U8_MAX;
  004e c70000   LD    WdgTimeBase,A
  107:  	WdgCounter		= U8_MAX;
  0051 c70000   LD    WdgCounter,A
  108:  	
  109:  	DebounceButton 	= 0;
  0054 4f       CLR   A
  0055 c70000   LD    DebounceButton,A
  110:  }
  0058 81       RET   
  111:  
  112:  
  113:  /*-----------------------------------------------------------------------------
  114:  ROUTINE NAME : ART_Start
  115:  INPUT/OUTPUT : None
  116:  
  117:  DESCRIPTION  : 
  118:  
  119:  COMMENTS     : 
  120:  -----------------------------------------------------------------------------*/ 
  121:  void ART_Start(void)
  122:  {

Function: ART_Start
Source  : ..\..\source\pwmart.c
Options : -Cc -F7 -Lasm=%n.lst -Ml -N -Os -Ou -Of -Ol0 -OnPMNC -Or

  123:  	ARTCSR |= ARTCSR_TCE_OR;			// Start timer
  0000 1600     BSET  ARTCSR,#3
  124:  }
  0002 81       RET   
  125:  
  126:  
  127:  /*-----------------------------------------------------------------------------
  128:  ROUTINE NAME : ART_SetTimeOutDuration
  129:  INPUT/OUTPUT : 
  130:  
  131:  DESCRIPTION  : Set Time Out Duration and clear related flag.
  132:  Description : Initialize counters, Flags and autoreload values for process
  133:                sequencing. Start time decounting once called.
  134:  
  135:  COMMENTS     : A protection/lock mechanism is implemented for 16-bit Time bases
  136:  				in order to prevent any collision if the time base interrupt 
  137:  				occurs during the MSB/LSB load sequence.
  138:  				Maximum jitter is 1ms if OVF occurs just after Counter set.
  139:  -----------------------------------------------------------------------------*/
  140:  void ART_SetTimeOutDuration(u16 Duration)
  141:  {

Function: ART_SetTimeOutDuration
Source  : ..\..\source\pwmart.c
Options : -Cc -F7 -Lasm=%n.lst -Ml -N -Os -Ou -Of -Ol0 -OnPMNC -Or

  0000 b701     LD    _ART_SetTimeOutDurationp0:1,A
  0002 bf00     LD    _ART_SetTimeOutDurationp0,X
  142:  	if ( Duration == 0)
  0004 b601     LD    A,_ART_SetTimeOutDurationp0:1
  0006 ba00     OR    A,_ART_SetTimeOutDurationp0
  0008 2606     JRNE  *8 ;abs = 0010
  143:  	{
  144:  		Duration = 1;	// Min value is 1ms
  000a a601     LD    A,#1
  000c b701     LD    _ART_SetTimeOutDurationp0:1,A
  000e 3f00     CLR   _ART_SetTimeOutDurationp0
  145:  	}
  146:  	TimeBaseStatus |= TIMEOUT_LOCK;		// Lock TimeOut handling in interrupt
  0010 c60000   LD    A,TimeBaseStatus
  0013 aa10     OR    A,#16
  0015 c70000   LD    TimeBaseStatus,A
  147:  	TimeOutPeriod = Duration;				// Value autoreloaded when counter = 0
  0018 9097     LD    Y,A
  001a b601     LD    A,_ART_SetTimeOutDurationp0:1
  001c c70001   LD    TimeOutPeriod:1,A
  001f b600     LD    A,_ART_SetTimeOutDurationp0
  0021 c70000   LD    TimeOutPeriod,A
  148:  	TimeOutCounter = Duration;  			// Reset counter to new value
  0024 ce0001   LD    X,TimeOutPeriod:1
  0027 cf0001   LD    TimeOutCounter:1,X
  002a c70000   LD    TimeOutCounter,A
  149:  	TimeBaseStatus &= (u8)(~TIMEOUT_ELAPSED); //	Clear Flag
  002d 909f     LD    A,Y
  002f a4fe     AND   A,#-2
  0031 c70000   LD    TimeBaseStatus,A
  150:  	TimeBaseStatus &= (u8)(~TIMEOUT_LOCK);		// Unlock TimeOut handling in interrupt
  0034 a4ef     AND   A,#-17
  0036 c70000   LD    TimeBaseStatus,A
  151:  }
  0039 81       RET   
  152:  
  153:  void ART_SetSpeedRegPeriod(u8 Period)
  154:  {

Function: ART_SetSpeedRegPeriod
Source  : ..\..\source\pwmart.c
Options : -Cc -F7 -Lasm=%n.lst -Ml -N -Os -Ou -Of -Ol0 -OnPMNC -Or

  0000 b700     LD    _ART_SetSpeedRegPeriodp0,A
  0002 2604     JRNE  *6 ;abs = 0008
  155:  	if ( Period == 0) Period = 1;	// Min value is 1ms
  0004 a601     LD    A,#1
  0006 b700     LD    _ART_SetSpeedRegPeriodp0,A
  156:  	RegTimeBase = Period;			// Value autoreloaded when counter = 0
  0008 b600     LD    A,_ART_SetSpeedRegPeriodp0
  000a c70000   LD    RegTimeBase,A
  157:  	RegCounter = Period;  			// Reset counter to new value
  000d c70000   LD    RegCounter,A
  158:  	TimeBaseStatus &= (u8)(~REG_PERIOD_ELAPSED); //	Clear Flag
  0010 c60000   LD    A,TimeBaseStatus
  0013 a4fd     AND   A,#-3
  0015 c70000   LD    TimeBaseStatus,A
  159:  }
  0018 81       RET   
  160:  
  161:  void ART_SetSequenceDuration(u16 Duration)
  162:  {

Function: ART_SetSequenceDuration
Source  : ..\..\source\pwmart.c
Options : -Cc -F7 -Lasm=%n.lst -Ml -N -Os -Ou -Of -Ol0 -OnPMNC -Or

  0000 b701     LD    _ART_SetSequenceDurationp0:1,A
  0002 bf00     LD    _ART_SetSequenceDurationp0,X
  163:  	if ( Duration == 0)
  0004 b601     LD    A,_ART_SetSequenceDurationp0:1
  0006 ba00     OR    A,_ART_SetSequenceDurationp0
  0008 2606     JRNE  *8 ;abs = 0010
  164:  	{
  165:  		Duration = 1;	// Min value is 1ms
  000a a601     LD    A,#1
  000c b701     LD    _ART_SetSequenceDurationp0:1,A
  000e 3f00     CLR   _ART_SetSequenceDurationp0
  166:  	}
  167:  	TimeBaseStatus |= SEQUENCE_LOCK;		// Lock TimeOut handling in interrupt
  0010 c60000   LD    A,TimeBaseStatus
  0013 aa20     OR    A,#32
  0015 c70000   LD    TimeBaseStatus,A
  168:  	SequencePeriod = Duration;				// Value autoreloaded when counter = 0
  0018 9097     LD    Y,A
  001a b601     LD    A,_ART_SetSequenceDurationp0:1
  001c c70001   LD    SequencePeriod:1,A
  001f b600     LD    A,_ART_SetSequenceDurationp0
  0021 c70000   LD    SequencePeriod,A
  169:  	SequenceCounter = Duration;  			// Reset counter to new value
  0024 ce0001   LD    X,SequencePeriod:1
  0027 cf0001   LD    SequenceCounter:1,X
  002a c70000   LD    SequenceCounter,A
  170:  	TimeBaseStatus &= (u8)(~SEQUENCE_COMPLETED);	//	Clear Flag
  002d 909f     LD    A,Y
  002f a4fb     AND   A,#-5
  0031 c70000   LD    TimeBaseStatus,A
  171:  	TimeBaseStatus &= (u8)(~SEQUENCE_LOCK);	// Unlock TimeOut handling in interrupt
  0034 a4df     AND   A,#-33
  0036 c70000   LD    TimeBaseStatus,A
  172:  }
  0039 81       RET   
  173:  
  174:  void ART_Set_TimeInMs(u16 Duration)
  175:  {

Function: ART_Set_TimeInMs
Source  : ..\..\source\pwmart.c
Options : -Cc -F7 -Lasm=%n.lst -Ml -N -Os -Ou -Of -Ol0 -OnPMNC -Or

  0000 b701     LD    _ART_Set_TimeInMsp0:1,A
  0002 bf00     LD    _ART_Set_TimeInMsp0,X
  176:  	if ( Duration == 0)
  0004 b601     LD    A,_ART_Set_TimeInMsp0:1
  0006 ba00     OR    A,_ART_Set_TimeInMsp0
  0008 2606     JRNE  *8 ;abs = 0010
  177:  	{
  178:  		Duration = 1;	// Min value is 1ms
  000a a601     LD    A,#1
  000c b701     LD    _ART_Set_TimeInMsp0:1,A
  000e 3f00     CLR   _ART_Set_TimeInMsp0
  179:  	}
  180:  	TimeBaseStatus |= MS_TIME_LOCK;	// Lock TimeOut handling in interrupt
  0010 c60000   LD    A,TimeBaseStatus
  0013 aa40     OR    A,#64
  0015 c70000   LD    TimeBaseStatus,A
  181:  	ms_TimeBase = Duration;				// Value autoreloaded when counter = 0
  0018 9097     LD    Y,A
  001a b601     LD    A,_ART_Set_TimeInMsp0:1
  001c c70001   LD    ms_TimeBase:1,A
  001f b600     LD    A,_ART_Set_TimeInMsp0
  0021 c70000   LD    ms_TimeBase,A
  182:  	ms_Counter = Duration;  			// Reset counter to new value
  0024 ce0001   LD    X,ms_TimeBase:1
  0027 cf0001   LD    ms_Counter:1,X
  002a c70000   LD    ms_Counter,A
  183:  	TimeBaseStatus &= (u8)(~MS_TIME_ELAPSED);	//	Clear Flag
  002d 909f     LD    A,Y
  002f a4f7     AND   A,#-9
  0031 c70000   LD    TimeBaseStatus,A
  184:  	TimeBaseStatus &= (u8)(~MS_TIME_LOCK);	// Unlock TimeOut handling in interrupt
  0034 a4bf     AND   A,#-65
  0036 c70000   LD    TimeBaseStatus,A
  185:  }
  0039 81       RET   
  186:  
  187:  void ART_SetMainTimeBase(u8 Period)
  188:  {

Function: ART_SetMainTimeBase
Source  : ..\..\source\pwmart.c
Options : -Cc -F7 -Lasm=%n.lst -Ml -N -Os -Ou -Of -Ol0 -OnPMNC -Or

  0000 b700     LD    _ART_SetMainTimeBasep0,A
  0002 2604     JRNE  *6 ;abs = 0008
  189:  	if ( Period == 0) Period = 1;	// Min value is 1ms
  0004 a601     LD    A,#1
  0006 b700     LD    _ART_SetMainTimeBasep0,A
  190:  	MainTimeBase = Period*10;		// Value autoreloaded when counter = 0
  0008 b600     LD    A,_ART_SetMainTimeBasep0
  000a 97       LD    X,A
  000b a60a     LD    A,#10
  000d 42       MUL   X,A
  000e c70001   LD    MainTimeBase:1,A
  0011 cf0000   LD    MainTimeBase,X
  191:  	MainCounter = Period*10;  		// Reset counter to new value
  0014 c70001   LD    MainCounter:1,A
  0017 cf0000   LD    MainCounter,X
  192:  	TimeBaseStatus &= (u8)(~MAIN_TIMEBASE_ELAPSED); //	Clear Flag
  001a c60000   LD    A,TimeBaseStatus
  001d a47f     AND   A,#-129
  001f c70000   LD    TimeBaseStatus,A
  193:  }
  0022 81       RET   
  194:  
  195:  void ART_SetWdgRfrshTime(u8 Period)
  196:  {

Function: ART_SetWdgRfrshTime
Source  : ..\..\source\pwmart.c
Options : -Cc -F7 -Lasm=%n.lst -Ml -N -Os -Ou -Of -Ol0 -OnPMNC -Or

  0000 b700     LD    _ART_SetWdgRfrshTimep0,A
  0002 2604     JRNE  *6 ;abs = 0008
  197:  	if ( Period == 0) Period = 1;	// Min value is 1ms
  0004 a601     LD    A,#1
  0006 b700     LD    _ART_SetWdgRfrshTimep0,A
  198:  	WdgTimeBase = Period;		// Value autoreloaded when counter = 0
  0008 b600     LD    A,_ART_SetWdgRfrshTimep0
  000a c70000   LD    WdgTimeBase,A
  199:  	WdgCounter = Period;  		// Reset counter to new value
  000d c70000   LD    WdgCounter,A
  200:  	Status &= (u8)(~WDG_TIMEBASE_ELAPSED); //	Clear Flag
  0010 c60000   LD    A,Status
  0013 a4fe     AND   A,#-2
  0015 c70000   LD    Status,A
  201:  }
  0018 81       RET   
  202:  
  203:  
  204:  /*-----------------------------------------------------------------------------
  205:  ROUTINE NAME : ART_IsTimeOutElapsed

⌨️ 快捷键说明

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