Exemplo n.º 1
0
/*********************************************************************//**
 * @brief		Configures each channel in MCPWM peripheral according to the
 * 				specified parameters in the MCPWM_CHANNEL_CFG_Type.
 * @param[in]	MCPWMx 	Motor Control PWM peripheral selected, should be: LPC_MCPWM
 * @param[in]	channelNum	Channel number, should be: 0..2.
 * @param[in]	channelSetup Pointer to a MCPWM_CHANNEL_CFG_Type structure
 * 				that contains the configuration information for the specified
 * 				MCPWM channel.
 * @return		None
 **********************************************************************/
void MCPWM_ConfigChannel(LPC_MCPWM_Type *MCPWMx, uint32_t channelNum,
                         MCPWM_CHANNEL_CFG_Type * channelSetup)
{
    if (channelNum <= 2) {
        if (channelNum == MCPWM_CHANNEL_0) {
            MCPWMx->TC[0] = channelSetup->channelTimercounterValue;
            MCPWMx->LIM[0] = channelSetup->channelPeriodValue;
            MCPWMx->MAT[0] = channelSetup->channelPulsewidthValue;
        } else if (channelNum == MCPWM_CHANNEL_1) {
            MCPWMx->TC[1] = channelSetup->channelTimercounterValue;
            MCPWMx->LIM[1] = channelSetup->channelPeriodValue;
            MCPWMx->MAT[1] = channelSetup->channelPulsewidthValue;
        } else if (channelNum == MCPWM_CHANNEL_2) {
            MCPWMx->TC[2] = channelSetup->channelTimercounterValue;
            MCPWMx->LIM[2] = channelSetup->channelPeriodValue;
            MCPWMx->MAT[2] = channelSetup->channelPulsewidthValue;
        } else {
            return;
        }

        if (channelSetup->channelType == MCPWM_CHANNEL_CENTER_MODE) {
            MCPWMx->CON_SET = MCPWM_CON_CENTER(channelNum);
        } else {
            MCPWMx->CON_CLR = MCPWM_CON_CENTER(channelNum);
        }

        if (channelSetup->channelPolarity == MCPWM_CHANNEL_PASSIVE_HI) {
            MCPWMx->CON_SET = MCPWM_CON_POLAR(channelNum);
        } else {
            MCPWMx->CON_CLR = MCPWM_CON_POLAR(channelNum);
        }

        if (channelSetup->channelDeadtimeEnable == ENABLE) {
            MCPWMx->CON_SET = MCPWM_CON_DTE(channelNum);

            MCPWMx->DT &= ~(MCPWM_DT(channelNum, 0x3FF));

            MCPWMx->DT |= MCPWM_DT(channelNum, channelSetup->channelDeadtimeValue);
        } else {
            MCPWMx->CON_CLR = MCPWM_CON_DTE(channelNum);
        }

        if (channelSetup->channelUpdateEnable == ENABLE) {
            MCPWMx->CON_CLR = MCPWM_CON_DISUP(channelNum);
        } else {
            MCPWMx->CON_SET = MCPWM_CON_DISUP(channelNum);
        }
    }
}
Exemplo n.º 2
0
/*********************************************************************//**
 * @brief		Configures each channel in MCPWM peripheral according to the
 * 				specified parameters in the MCPWM_CHANNEL_CFG_Type.
 * @param[in]	MCPWMx 			Motor Control PWM peripheral selected
 * 								should be: LPC_MCPWM
 * @param[in]	channelNum		Channel number, should be: 0..2.
 * @param[in]	channelSetup	Pointer to a MCPWM_CHANNEL_CFG_Type structure
*                    			that contains the configuration information for the
*                    			specified MCPWM channel.
 * @return		None
 **********************************************************************/
void MCPWM_ConfigChannel(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channelNum,
						MCPWM_CHANNEL_CFG_Type * channelSetup)
{
	if ((channelNum >= 0) && (channelNum <= 2)) {
		if (channelNum == 0) {
			MCPWMx->MCTIM0 = channelSetup->channelTimercounterValue;
			MCPWMx->MCPER0 = channelSetup->channelPeriodValue;
			MCPWMx->MCPW0 = channelSetup->channelPulsewidthValue;
		} else if (channelNum == 1) {
			MCPWMx->MCTIM1 = channelSetup->channelTimercounterValue;
			MCPWMx->MCPER1 = channelSetup->channelPeriodValue;
			MCPWMx->MCPW1 = channelSetup->channelPulsewidthValue;
		} else if (channelNum == 2) {
			MCPWMx->MCTIM2 = channelSetup->channelTimercounterValue;
			MCPWMx->MCPER2 = channelSetup->channelPeriodValue;
			MCPWMx->MCPW2 = channelSetup->channelPulsewidthValue;
		} else {
			return;
		}

		if (channelSetup->channelType /* == MCPWM_CHANNEL_CENTER_MODE */){
			MCPWMx->MCCON_SET = MCPWM_CON_CENTER(channelNum);
		} else {
			MCPWMx->MCCON_CLR = MCPWM_CON_CENTER(channelNum);
		}

		if (channelSetup->channelPolarity /* == MCPWM_CHANNEL_PASSIVE_HI */){
			MCPWMx->MCCON_SET = MCPWM_CON_POLAR(channelNum);
		} else {
			MCPWMx->MCCON_CLR = MCPWM_CON_POLAR(channelNum);
		}

		if (channelSetup->channelDeadtimeEnable /* == ENABLE */){
			MCPWMx->MCCON_SET = MCPWM_CON_DTE(channelNum);
			MCPWMx->MCDEADTIME &= ~(MCPWM_DT(channelNum, 0x3FF));
			MCPWMx->MCDEADTIME |= MCPWM_DT(channelNum, channelSetup->channelDeadtimeValue);
		} else {
			MCPWMx->MCCON_CLR = MCPWM_CON_DTE(channelNum);
		}

		if (channelSetup->channelUpdateEnable /* == ENABLE */){
			MCPWMx->MCCON_CLR = MCPWM_CON_DISUP(channelNum);
		} else {
			MCPWMx->MCCON_SET = MCPWM_CON_DISUP(channelNum);
		}
	}
}