/********************************************************************//** * @brief Update value for multi PWM channel with update type option * at the same time * @param[in] PWMx PWM peripheral selected, should be LPC_PWM1 * @param[in] MatchStruct Structure that contents match value of 7 pwm channels * @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_MultiMatchUpdate(LPC_PWM_TypeDef *PWMx, PWM_Match_T *MatchStruct , uint8_t UpdateType) { uint8_t LatchValue = 0; uint8_t i; CHECK_PARAM(PARAM_PWMx(PWMx)); CHECK_PARAM(PARAM_PWM_MATCH_UPDATE(UpdateType)); //Update match value for(i=0;i<7;i++) { if(MatchStruct[i].Status == SET) { if(i<4) *((volatile unsigned int *)(&(PWMx->MR0) + i)) = MatchStruct[i].Matchvalue; else { *((volatile unsigned int *)(&(PWMx->MR4) + (i-4))) = MatchStruct[i].Matchvalue; } LatchValue |=(1<<i); } } //set update for multi-channel at the same time PWMx->LER = LatchValue; // 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; } }
/********************************************************************//** * @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; } }