Esempio n. 1
0
/********************************************************************//**
 * @brief 		Update value for each PWM channel with update type option
 * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
 * @param[in]	MatchChannel Match channel
 * @param[in]	MatchValue Match value
 * @param[in]	UpdateType Type of Update, should be:
 * 				- PWM_MATCH_UPDATE_NOW: The update value will be updated for
 * 					this channel immediately
 * 				- PWM_MATCH_UPDATE_NEXT_RST: The update value will be updated for
 * 					this channel on next reset by a PWM Match event.
 * @return		None
 *********************************************************************/
void PWM_MatchUpdate(LPC_PWM_TypeDef *PWMx, uint8_t MatchChannel, \
					uint32_t MatchValue, uint8_t UpdateType)
{
	CHECK_PARAM(PARAM_PWMx(PWMx));
	CHECK_PARAM(PARAM_PWM1_MATCH_CHANNEL(MatchChannel));
	CHECK_PARAM(PARAM_PWM_MATCH_UPDATE(UpdateType));

	switch (MatchChannel)
	{
	case 0:
		PWMx->MR0 = MatchValue;
		break;

	case 1:
		PWMx->MR1 = MatchValue;
		break;

	case 2:
		PWMx->MR2 = MatchValue;
		break;

	case 3:
		PWMx->MR3 = MatchValue;
		break;

	case 4:
		PWMx->MR4 = MatchValue;
		break;

	case 5:
		PWMx->MR5 = MatchValue;
		break;

	case 6:
		PWMx->MR6 = MatchValue;
		break;
	}

	// Write Latch register
	PWMx->LER |= PWM_LER_EN_MATCHn_LATCH(MatchChannel);

	// In case of update now
	if (UpdateType == PWM_MATCH_UPDATE_NOW)
	{
		PWMx->TCR |= PWM_TCR_COUNTER_RESET;
		PWMx->TCR &= (~PWM_TCR_COUNTER_RESET) & PWM_TCR_BITMASK;
	}
}
Esempio n. 2
0
/********************************************************************//**
 * @brief 		Update value for each PWM channel with update type option
 * @param[in]	 pwmId			 The Id of the expected PWM component
 *
 * @param[in]	MatchChannel Match channel
 * @param[in]	MatchValue Match value
 * @param[in]	UpdateType Type of Update, should be:
 * 				- PWM_MATCH_UPDATE_NOW: The update value will be updated for
 * 					this channel immediately
 * 				- PWM_MATCH_UPDATE_NEXT_RST: The update value will be updated for
 * 					this channel on next reset by a PWM Match event.
 * @return		None
 *********************************************************************/
void PWM_MatchUpdate(uint8_t pwmId, uint8_t MatchChannel,
										uint32_t MatchValue, uint8_t UpdateType)
{
	LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);

	switch (MatchChannel)
	{
		case 0:
			pPwm->MR0 = MatchValue;
			break;

		case 1:
			pPwm->MR1 = MatchValue;
			break;

		case 2:
			pPwm->MR2 = MatchValue;
			break;

		case 3:
			pPwm->MR3 = MatchValue;
			break;

		case 4:
			pPwm->MR4 = MatchValue;
			break;

		case 5:
			pPwm->MR5 = MatchValue;
			break;

		case 6:
			pPwm->MR6 = MatchValue;
			break;
	}

	// Write Latch register
	pPwm->LER |= PWM_LER_EN_MATCHn_LATCH(MatchChannel);

	// In case of update now
	if (UpdateType == PWM_MATCH_UPDATE_NOW)
	{
		pPwm->TCR |= PWM_TCR_COUNTER_RESET;
		pPwm->TCR &= (~PWM_TCR_COUNTER_RESET) & PWM_TCR_BITMASK;
	}
}