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

📄 to1.c

📁 用freescale公司的DSP56F8013芯片实现的PMSM的SVPWM 驱动
💻 C
字号:
/** ###################################################################
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : TO1.C
**     Project   : PMSM
**     Processor : 56F8013VFAE
**     Beantype  : TimerOut
**     Version   : Bean 02.147, Driver 01.16, CPU db: 2.87.089
**     Compiler  : Metrowerks DSP C Compiler
**     Date/Time : 2008-1-30, 下午 02:43
**     Abstract  :
**         This bean implements a periodic signal generator 1:1 (Flip-Flop Output).
**         The signal alternates the "0" and "1" output values in exactly
**         regular intervals; that is why the time length of the "0" part
**         of one pulse is equal to the "1" part of one pulse.
**     Settings  :
**         Used output pin             : 
**             ----------------------------------------------------
**                Number (on package)  |    Name
**             ----------------------------------------------------
**                       19            |  GPIOB4_T0_CLKO
**             ----------------------------------------------------
**
**         Timer name                  : TMR0 (16-bit)
**         Compare name                : TMR0_Compare
**           Counter shared            : No
**
**         High speed mode
**             Prescaler               : divide-by-1
**             Clock                   : 32000000 Hz
**           Pulse width
**             Xtal ticks              : 40
**             microseconds            : 5
**             seconds (real)          : 0.0000050
**             Hz                      : 200000
**             kHz                     : 200
**
**         Runtime setting             : none
**
**         Initialization:
**              Output level           : low
**              Timer                  : Enabled
**              Events                 : Enabled
**
**         Timer registers
**              Counter                : TMR0_CNTR [61445]
**              Mode                   : TMR0_CTRL [61446]
**              Run                    : TMR0_CTRL [61446]
**              Prescaler              : TMR0_CTRL [61446]
**
**         Compare registers
**              Compare                : TMR0_CMP1 [61440]
**
**         Flip-flop registers
**              Mode                   : TMR0_SCR  [61447]
**     Contents  :
**         Enable - byte TO1_Enable(void);
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2006
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/

/* MODULE TO1. */

#include "Events.h"
#include "TO1.h"



/* Internal method prototypes */
static void HWEnDi(void);
static void SetCV(word Val);
static void SetPV(byte Val);

/*
** ===================================================================
**     Method      :  SetCV (bean TimerOut)
**
**     Description :
**         Sets compare or preload register value. The method is called 
**         automatically as a part of several internal methods.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void SetCV(word Val)
{
  EnterCritical();                     /* Disable global interrupts */
  setReg(TMR0_CMPLD1,Val);             /* Store given value to the compare preload register */
  setReg(TMR0_CMPLD2,Val);
  ExitCritical();                      /* Enable global interrupts */
}

/*
** ===================================================================
**     Method      :  SetPV (bean TimerOut)
**
**     Description :
**         Sets prescaler value. The method is called automatically as a 
**         part of several internal methods.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void SetPV(byte Val)
{
  setRegBitGroup(TMR0_CTRL,PCS,Val);   /* Store given value to the prescaler */
  setReg(TMR0_CNTR,0);                 /* Reset counter */
}

/*
** ===================================================================
**     Method      :  HWEnDi (bean TimerOut)
**
**     Description :
**         Enables or disables the peripheral(s) associated with the bean.
**         The method is called automatically as a part of the Enable and 
**         Disable methods and several internal methods.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void HWEnDi(void)
{
    setRegBitGroup(TMR0_CTRL,CM,1);    /* Run counter */
}

/*
** ===================================================================
**     Method      :  TO1_Enable (bean TimerOut)
**
**     Description :
**         Enables the bean - it starts the signal generation. Events
**         may be generated ("DisableEvent"/"EnableEvent").
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte TO1_Enable(void)
{
  HWEnDi();                            /* Enable the device */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  TO1_Init (bean TimerOut)
**
**     Description :
**         Initializes the associated peripheral(s) and the beans 
**         internal variables. The method is called automatically as a 
**         part of the application initialization code.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void TO1_Init(void)
{
  /* TMR0_CTRL: CM=0,PCS=0,SCS=0,ONCE=0,LENGTH=1,DIR=0,Co_INIT=0,OM=4 */
  setReg(TMR0_CTRL,36);                /* Set up mode */
  /* TMR0_SCR: TCF=0,TCFIE=1,TOF=0,TOFIE=0,IEF=0,IEFIE=0,IPS=0,INPUT=0,Capture_Mode=0,MSTR=0,EEOF=0,VAL=0,FORCE=0,OPS=0,OEN=1 */
  setReg(TMR0_SCR,16385);
  setReg(TMR0_CNTR,0);                 /* Reset counter register */
  setReg(TMR0_LOAD,0);                 /* Reset load register */
  setReg(TMR0_CMP1,159);               /* Set up compare 1 register */
  setReg(TMR0_CMP2,159);               /* Set up compare 2 register */
  /* TMR0_COMSCR: DBG_EN=0,??=0,??=0,??=0,??=0,??=0,??=0,TCF2EN=0,TCF1EN=0,TCF2=0,TCF1=0,CL2=1,CL1=2 */
  setReg(TMR0_COMSCR,6);               /* Set up comparator control register */
  SetCV((word)159);                    /* Store appropriate value to the compare register according to the selected high speed CPU mode */
  SetPV((byte)8);                      /* Set prescaler register according to the selected high speed CPU mode */
  HWEnDi();                            /* Enable/disable device according to status flags */
}

/*
** ===================================================================
**     Method      :  TO1_Interrupt (bean TimerOut)
**
**     Description :
**         The method services the interrupt of the selected peripheral(s)
**         and eventually invokes the beans event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#pragma interrupt alignsp saveall
void TO1_Interrupt(void)
{
  clrRegBit(TMR0_SCR,TCF);             /* Reset interrupt request flag */
  if (getRegBit(TMR0_COMSCR,TCF2)) {   /* Is this compare 2 event? */
    clrRegBit(TMR0_COMSCR,TCF2);       /* Clear flag */
    TO1_OnFalling();                   /* Invoke user event */
  }
}

/* END TO1. */

/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 2.98 [03.79]
**     for the Freescale 56800 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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