📄 pwmc1.c
字号:
** Parameters : None
** Returns :
** --- - Error code, possible codes:
** ERR_OK - OK
** ERR_SPEED - This device does not work in
** the active speed mode
** ===================================================================
*/
byte PWMC1_Disable(void)
{
if (EnUser) { /* Is the device enabled by user? */
EnUser = FALSE; /* If yes then set the flag "device disabled" */
HWEnDi(); /* Disable the device */
}
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : PWMC1_InterruptOnReload (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
void PWMC1_InterruptOnReload(void)
{
getReg(PWMB_PMCTL); /* Read PWM Control Register with PWMF set */
clrRegBit(PWMB_PMCTL,PWMF); /* Reset interrupt request flag */
PWMC1_OnReload(); /* Invoke user event */
}
/*
** ===================================================================
** Method : PWMC1_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
void PWMC1_InterruptOnFault(void)
{
if (getRegBit(PWMB_PMFSA, FFLAG0)) {
setReg(PWMB_PMFSA, 1); /* Reset interrupt request flag */
PWMC1_OnFault0(); /* Invoke user event */
}
if (getRegBit(PWMB_PMFSA, FFLAG1)) {
setReg(PWMB_PMFSA, 4); /* Reset interrupt request flag */
PWMC1_OnFault1(); /* Invoke user event */
}
if (getRegBit(PWMB_PMFSA, FFLAG2)) {
setReg(PWMB_PMFSA, 16); /* Reset interrupt request flag */
PWMC1_OnFault2(); /* Invoke user event */
}
if (getRegBit(PWMB_PMFSA, FFLAG3)) {
setReg(PWMB_PMFSA, 64); /* Reset interrupt request flag */
PWMC1_OnFault3(); /* Invoke user event */
}
}
/*
** ===================================================================
** Method : PWMC1_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 PWMC1_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=0,HALF=0,IPOL2=0,IPOL1=0,IPOL0=0,PRSC=0,PWMRIE=1,PWMF=0,ISENS=0,LDOK=0,PWMEN=0 */
setReg16(PWMB_PMCTL, 32);
/* PWMB_PMFCTL: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,FIE3=1,FMODE3=1,FIE2=1,FMODE2=1,FIE1=1,FMODE1=1,FIE0=1,FMODE0=1 */
setReg16(PWMB_PMFCTL, 255);
/* 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=1,??=0,OUTCTL=0,??=0,??=0,OUT=0 */
setReg16(PWMB_PMOUT, 32768);
/* 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=180 */
setReg16(PWMB_PMDEADTM, 180);
/* PWMB_PWMVAL0: VAL=1875 */
setReg16(PWMB_PWMVAL0, 1875);
/* PWMB_PWMVAL1: VAL=1875 */
setReg16(PWMB_PWMVAL1, 1875);
/* PWMB_PWMVAL2: VAL=1875 */
setReg16(PWMB_PWMVAL2, 1875);
/* PWMB_PWMVAL3: VAL=1875 */
setReg16(PWMB_PWMVAL3, 1875);
/* PWMB_PWMVAL4: VAL=1875 */
setReg16(PWMB_PWMVAL4, 1875);
/* PWMB_PWMVAL5: VAL=1875 */
setReg16(PWMB_PWMVAL5, 1875);
/* PWMB_PWMCM: ??=0,CM=3750 */
setReg16(PWMB_PWMCM, 3750);
HWEnDi(); /* Enable/disable device according to status flags */
}
/*
** ===================================================================
** Method : PWMC1_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 PWMC1_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 : PWMC1_Load (bean PWMMC)
**
** Description :
** Apply last setting of the methods SetDuty, SetDutyPercent,
** SetPeriod and SetPrescaler.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/*
void PWMC1_Load(void)
** This method is implemented as a macro. See PWMC1.h file. **
*/
/*
** ===================================================================
** Method : PWMC1_OutputPadEnable (bean PWMMC)
**
** Description :
** Method enables output pads.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/*
void PWMC1_OutputPadEnable(void)
** This method is implemented as a macro. See PWMC1.h file. **
*/
/*
** ===================================================================
** Method : PWMC1_OutputPadDisable (bean PWMMC)
**
** Description :
** Method disables output pads.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/*
void PWMC1_OutputPadDisable(void)
** This method is implemented as a macro. See PWMC1.h file. **
*/
/*
** ===================================================================
** Method : PWMC1_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 PWMC1_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 PWMC1. */
/*
** ###################################################################
**
** 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 + -