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

📄 pwm_sync.c

📁 PWM同步
💻 C
📖 第 1 页 / 共 2 页
字号:
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#pragma interrupt alignsp saveall
void PWM_sync_InterruptOnReload(void)
{
  getReg(PWMB_PMCTL);                  /* Read PWM Control Register with PWMF set */
  clrRegBit(PWMB_PMCTL,PWMF);          /* Reset interrupt request flag */
  PWM_sync_OnReload();                 /* Invoke user event */
}

/*
** ===================================================================
**     Method      :  PWM_sync_InterruptOnFault (bean PWMMC)
**
**     Description :
**         The method services the interrupt of the selected peripheral(s)
**         and eventually invokes the bean's event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#pragma interrupt alignsp saveall
void PWM_sync_InterruptOnFault(void)
{
  if (getRegBit(PWMB_PMFSA, FFLAG0)) {
    setReg(PWMB_PMFSA, 1);             /* Reset interrupt request flag */
    PWM_sync_OnFault0();               /* Invoke user event */
  }
  if (getRegBit(PWMB_PMFSA, FFLAG1)) {
    setReg(PWMB_PMFSA, 4);             /* Reset interrupt request flag */
    PWM_sync_OnFault1();               /* Invoke user event */
  }
  if (getRegBit(PWMB_PMFSA, FFLAG2)) {
    setReg(PWMB_PMFSA, 16);            /* Reset interrupt request flag */
    PWM_sync_OnFault2();               /* Invoke user event */
  }
}

/*
** ===================================================================
**     Method      :  PWM_sync_Init (bean PWMMC)
**
**     Description :
**         Initializes the associated peripheral(s) and the bean's 
**         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 PWM_sync_Init(void)
{
  /* PWMB_PMICCR: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,ICC2=0,ICC1=0,ICC0=0 */
  setReg16(PWMB_PMICCR, 0);             
  /* PWMB_PMCTL: LDFQ=3,HALF=0,IPOL2=0,IPOL1=0,IPOL0=0,PRSC=0,PWMRIE=1,PWMF=0,ISENS=0,LDOK=0,PWMEN=0 */
  setReg16(PWMB_PMCTL, 12320);          
  /* PWMB_PMFCTL: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,FIE3=0,FMODE3=0,FIE2=1,FMODE2=1,FIE1=1,FMODE1=1,FIE0=1,FMODE0=1 */
  setReg16(PWMB_PMFCTL, 63);            
  /* PWMB_PMDISMAP1: DISMAP=0 */
  setReg16(PWMB_PMDISMAP1, 0);          
  /* PWMB_PMDISMAP2: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,DISMAP=0 */
  setReg16(PWMB_PMDISMAP2, 0);          
  /* PWMB_PMOUT: PAD_EN=0,??=0,OUTCTL=0,??=0,??=0,OUT=0 */
  setReg16(PWMB_PMOUT, 0);              
  /* PWMB_PMCCR: ENHA=0,nBX=0,MSK=0,??=0,??=0,VLMODE=0,??=0,SWP45=0,SWP23=0,SWP01=0 */
  setReg16(PWMB_PMCCR, 0);              
  /* PWMB_PMCFG: ??=0,DBG_EN=0,WAIT_EN=0,EDG=0,??=0,TOPNEG45=0,TOPNEG23=0,TOPNEG01=0,??=0,BOTNEG45=1,BOTNEG23=1,BOTNEG01=1,INDEP45=0,INDEP23=0,INDEP01=0,WP=0 */
  setReg16(PWMB_PMCFG, 112);            
  EnUser = TRUE;                       /* Enable device */
  /* PWMB_PMDEADTM: ??=0,??=0,??=0,??=0,PWMDT=12 */
  setReg16(PWMB_PMDEADTM, 12);          
  /* PWMB_PWMVAL0: VAL=938 */
  setReg16(PWMB_PWMVAL0, 938);          
  /* PWMB_PWMVAL1: VAL=937 */
  setReg16(PWMB_PWMVAL1, 937);          
  /* PWMB_PWMVAL2: VAL=938 */
  setReg16(PWMB_PWMVAL2, 938);          
  /* PWMB_PWMVAL3: VAL=937 */
  setReg16(PWMB_PWMVAL3, 937);          
  /* PWMB_PWMVAL4: VAL=938 */
  setReg16(PWMB_PWMVAL4, 938);          
  /* PWMB_PWMVAL5: VAL=937 */
  setReg16(PWMB_PWMVAL5, 937);          
  /* PWMB_PWMCM: ??=0,CM=1875 */
  setReg16(PWMB_PWMCM, 1875);           
  HWEnDi();                            /* Enable/disable device according to status flags */
}

/*
** ===================================================================
**     Method      :  PWM_sync_SetDuty (bean PWMMC)
**
**     Description :
**         Setting duty(value) register of selected channel.  The
**         value is loaded after calling Load() method.
**     Parameters  :
**         NAME            - DESCRIPTION
**         channel         - channel 0-5
**         duty            - Duty value for selected channel.
**                           Writing a number less than or equal to 0
**                           causes the PWM to be off for the entire
**                           PWM period. Writing a number greater
**                           than or equal to the 15 bit (12-bit on
**                           HC08MR32 CPU) modulus causes the PWM to
**                           be on for the entire PWM period.
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_NOTAVAIL - Channel is disabled
**                           ERR_RANGE - Parameter channel is out of
**                           range
** ===================================================================
*/
byte PWM_sync_SetDuty(byte channel,int duty)
{
  switch (channel) {
  case 0 :
      setReg(PWMB_PWMVAL0,duty);       /* Store value to the duty-compare register 0 */
      break;
  case 1 :
      setReg(PWMB_PWMVAL1,duty);       /* Store value to the duty-compare register 1 */
      break;
  case 2 :
      setReg(PWMB_PWMVAL2,duty);       /* Store value to the duty-compare register 2 */
      break;
  case 3 :
      setReg(PWMB_PWMVAL3,duty);       /* Store value to the duty-compare register 3 */
      break;
  case 4 :
      setReg(PWMB_PWMVAL4,duty);       /* Store value to the duty-compare register 4 */
      break;
  case 5 :
      setReg(PWMB_PWMVAL5,duty);       /* Store value to the duty-compare register 5 */
      break;
  default: return ERR_RANGE;
  }
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  PWM_sync_Load (bean PWMMC)
**
**     Description :
**         Apply last setting of the methods SetDuty, SetDutyPercent,
**         SetPeriod and SetPrescaler.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
/*
void PWM_sync_Load(void)

**  This method is implemented as a macro. See PWM_sync.h file.  **

*/

/*
** ===================================================================
**     Method      :  PWM_sync_OutputPadEnable (bean PWMMC)
**
**     Description :
**         Method enables output pads.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
/*
void PWM_sync_OutputPadEnable(void)

**  This method is implemented as a macro. See PWM_sync.h file.  **

*/

/*
** ===================================================================
**     Method      :  PWM_sync_OutputPadDisable (bean PWMMC)
**
**     Description :
**         Method disables output pads.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
/*
void PWM_sync_OutputPadDisable(void)

**  This method is implemented as a macro. See PWM_sync.h file.  **

*/

/*
** ===================================================================
**     Method      :  PWM_sync_SetRatio16 (bean PWMMC)
**
**     Description :
**         This method sets a new duty-cycle ratio for selected
**         channel.
**     Parameters  :
**         NAME            - DESCRIPTION
**         channel         - channel 0 - 5
**         ratio           - Ratio is expressed as an 16-bit
**                           unsigned integer number. 0 - 65535 value
**                           is proportional to ratio 0 - 100%.
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_NOTAVAIL - Channel is disabled
**                           ERR_RANGE - Parameter channel is out of
**                           range
** ===================================================================
*/
byte PWM_sync_SetRatio16(byte channel,word ratio)
{
  register word dutyreg;

  dutyreg = (word)((dword)getReg(PWMB_PWMCM)*ratio/65535); /* Calculate real duty */
  switch (channel) {
  case 0 :
      setReg(PWMB_PWMVAL0,dutyreg);    /* Store ratio value to the duty-compare register 0 */
      break;
  case 1 :
      setReg(PWMB_PWMVAL1,dutyreg);    /* Store ratio value to the duty-compare register 1 */
      break;
  case 2 :
      setReg(PWMB_PWMVAL2,dutyreg);    /* Store ratio value to the duty-compare register 2 */
      break;
  case 3 :
      setReg(PWMB_PWMVAL3,dutyreg);    /* Store ratio value to the duty-compare register 3 */
      break;
  case 4 :
      setReg(PWMB_PWMVAL4,dutyreg);    /* Store ratio value to the duty-compare register 4 */
      break;
  case 5 :
      setReg(PWMB_PWMVAL5,dutyreg);    /* Store ratio value to the duty-compare register 5 */
      break;
  default: return ERR_RANGE;
  }
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  PWM_sync_SetRatio15 (bean PWMMC)
**
**     Description :
**         This method sets a new duty-cycle ratio for selected
**         channel.
**     Parameters  :
**         NAME            - DESCRIPTION
**         channel         - channel 0 - 5
**         ratio           - Ratio is expressed as an 16-bit
**                           signed integer number. 0 - 32767 value
**                           is proportional to ratio 0 - 100%.
**                           Value under 0 corresponds to 0% ratio.
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_NOTAVAIL - Channel is disabled
**                           ERR_RANGE - Parameter channel is out of
**                           range
** ===================================================================
*/
byte PWM_sync_SetRatio15(byte channel,int ratio)
{
  register word dutyreg;

  dutyreg = (word)((dword)getReg(PWMB_PWMCM)*ratio/32767); /* Calculate real duty from percent value */
  switch (channel) {
  case 0 :
      setReg(PWMB_PWMVAL0,dutyreg);    /* Store ratio value to the duty-compare register 0 */
      break;
  case 1 :
      setReg(PWMB_PWMVAL1,dutyreg);    /* Store ratio value to the duty-compare register 1 */
      break;
  case 2 :
      setReg(PWMB_PWMVAL2,dutyreg);    /* Store ratio value to the duty-compare register 2 */
      break;
  case 3 :
      setReg(PWMB_PWMVAL3,dutyreg);    /* Store ratio value to the duty-compare register 3 */
      break;
  case 4 :
      setReg(PWMB_PWMVAL4,dutyreg);    /* Store ratio value to the duty-compare register 4 */
      break;
  case 5 :
      setReg(PWMB_PWMVAL5,dutyreg);    /* Store ratio value to the duty-compare register 5 */
      break;
  default: return ERR_RANGE;
  }
  return ERR_OK;
}

/* END PWM_sync. */

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

⌨️ 快捷键说明

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