lpc-field

Template project for programming NXP's LPC1768 MCUs
git clone git://git.mdnr.space/lpc-field
Log | Files | Refs | README | LICENSE

lpc17xx_pwm.c (19966B)


      1 /**********************************************************************
      2 * $Id$		lpc17xx_pwm.c				2011-03-31
      3 *//**
      4 * @file		lpc17xx_pwm.c
      5 * @brief	Contains all functions support for PWM firmware library on LPC17xx
      6 * @version	2.1
      7 * @date		31. Mar. 2011
      8 * @author	NXP MCU SW Application Team
      9 *
     10 * Copyright(C) 2011, NXP Semiconductor
     11 * All rights reserved.
     12 *
     13 ***********************************************************************
     14 * Software that is described herein is for illustrative purposes only
     15 * which provides customers with programming information regarding the
     16 * products. This software is supplied "AS IS" without any warranties.
     17 * NXP Semiconductors assumes no responsibility or liability for the
     18 * use of the software, conveys no license or title under any patent,
     19 * copyright, or mask work right to the product. NXP Semiconductors
     20 * reserves the right to make changes in the software without
     21 * notification. NXP Semiconductors also make no representation or
     22 * warranty that such application will be suitable for the specified
     23 * use without further testing or modification.
     24 * Permission to use, copy, modify, and distribute this software and its
     25 * documentation is hereby granted, under NXP Semiconductors'
     26 * relevant copyright in the software, without fee, provided that it
     27 * is used in conjunction with NXP Semiconductors microcontrollers.  This
     28 * copyright, permission, and disclaimer notice must appear in all copies of
     29 * this code.
     30 **********************************************************************/
     31 
     32 /* Peripheral group ----------------------------------------------------------- */
     33 /** @addtogroup PWM
     34  * @{
     35  */
     36 
     37 /* Includes ------------------------------------------------------------------- */
     38 #include "lpc17xx_pwm.h"
     39 #include "lpc17xx_clkpwr.h"
     40 
     41 /* If this source file built with example, the LPC17xx FW library configuration
     42  * file in each example directory ("lpc17xx_libcfg.h") must be included,
     43  * otherwise the default FW library configuration file must be included instead
     44  */
     45 #ifdef __BUILD_WITH_EXAMPLE__
     46 #include "lpc17xx_libcfg.h"
     47 #else
     48 #include "lpc17xx_libcfg_default.h"
     49 #endif /* __BUILD_WITH_EXAMPLE__ */
     50 
     51 
     52 #ifdef _PWM
     53 
     54 
     55 /* Public Functions ----------------------------------------------------------- */
     56 /** @addtogroup PWM_Public_Functions
     57  * @{
     58  */
     59 
     60 
     61 /*********************************************************************//**
     62  * @brief 		Check whether specified interrupt flag in PWM is set or not
     63  * @param[in]	PWMx: PWM peripheral, should be LPC_PWM1
     64  * @param[in]	IntFlag: PWM interrupt flag, should be:
     65  * 				- PWM_INTSTAT_MR0: Interrupt flag for PWM match channel 0
     66  * 				- PWM_INTSTAT_MR1: Interrupt flag for PWM match channel 1
     67  * 				- PWM_INTSTAT_MR2: Interrupt flag for PWM match channel 2
     68  * 				- PWM_INTSTAT_MR3: Interrupt flag for PWM match channel 3
     69  * 				- PWM_INTSTAT_MR4: Interrupt flag for PWM match channel 4
     70  * 				- PWM_INTSTAT_MR5: Interrupt flag for PWM match channel 5
     71  * 				- PWM_INTSTAT_MR6: Interrupt flag for PWM match channel 6
     72  * 				- PWM_INTSTAT_CAP0: Interrupt flag for capture input 0
     73  * 				- PWM_INTSTAT_CAP1: Interrupt flag for capture input 1
     74  * @return 		New State of PWM interrupt flag (SET or RESET)
     75  **********************************************************************/
     76 IntStatus PWM_GetIntStatus(LPC_PWM_TypeDef *PWMx, uint32_t IntFlag)
     77 {
     78 	CHECK_PARAM(PARAM_PWMx(PWMx));
     79 	CHECK_PARAM(PARAM_PWM_INTSTAT(IntFlag));
     80 
     81 	return ((PWMx->IR & IntFlag) ? SET : RESET);
     82 }
     83 
     84 
     85 
     86 /*********************************************************************//**
     87  * @brief 		Clear specified PWM Interrupt pending
     88  * @param[in]	PWMx: PWM peripheral, should be LPC_PWM1
     89  * @param[in]	IntFlag: PWM interrupt flag, should be:
     90  * 				- PWM_INTSTAT_MR0: Interrupt flag for PWM match channel 0
     91  * 				- PWM_INTSTAT_MR1: Interrupt flag for PWM match channel 1
     92  * 				- PWM_INTSTAT_MR2: Interrupt flag for PWM match channel 2
     93  * 				- PWM_INTSTAT_MR3: Interrupt flag for PWM match channel 3
     94  * 				- PWM_INTSTAT_MR4: Interrupt flag for PWM match channel 4
     95  * 				- PWM_INTSTAT_MR5: Interrupt flag for PWM match channel 5
     96  * 				- PWM_INTSTAT_MR6: Interrupt flag for PWM match channel 6
     97  * 				- PWM_INTSTAT_CAP0: Interrupt flag for capture input 0
     98  * 				- PWM_INTSTAT_CAP1: Interrupt flag for capture input 1
     99  * @return 		None
    100  **********************************************************************/
    101 void PWM_ClearIntPending(LPC_PWM_TypeDef *PWMx, uint32_t IntFlag)
    102 {
    103 	CHECK_PARAM(PARAM_PWMx(PWMx));
    104 	CHECK_PARAM(PARAM_PWM_INTSTAT(IntFlag));
    105 	PWMx->IR = IntFlag;
    106 }
    107 
    108 
    109 
    110 /*****************************************************************************//**
    111 * @brief		Fills each PWM_InitStruct member with its default value:
    112 * 				- If PWMCounterMode = PWM_MODE_TIMER:
    113 * 					+ PrescaleOption = PWM_TIMER_PRESCALE_USVAL
    114 * 					+ PrescaleValue = 1
    115 * 				- If PWMCounterMode = PWM_MODE_COUNTER:
    116 * 					+ CountInputSelect = PWM_COUNTER_PCAP1_0
    117 * 					+ CounterOption = PWM_COUNTER_RISING
    118 * @param[in]	PWMTimerCounterMode Timer or Counter mode, should be:
    119 * 				- PWM_MODE_TIMER: Counter of PWM peripheral is in Timer mode
    120 * 				- PWM_MODE_COUNTER: Counter of PWM peripheral is in Counter mode
    121 * @param[in]	PWM_InitStruct Pointer to structure (PWM_TIMERCFG_Type or
    122 * 				 PWM_COUNTERCFG_Type) which will be initialized.
    123 * @return		None
    124 * Note: PWM_InitStruct pointer will be assigned to corresponding structure
    125 * 		(PWM_TIMERCFG_Type or PWM_COUNTERCFG_Type) due to PWMTimerCounterMode.
    126 *******************************************************************************/
    127 void PWM_ConfigStructInit(uint8_t PWMTimerCounterMode, void *PWM_InitStruct)
    128 {
    129 	PWM_TIMERCFG_Type *pTimeCfg;
    130 	PWM_COUNTERCFG_Type *pCounterCfg;
    131 	CHECK_PARAM(PARAM_PWM_TC_MODE(PWMTimerCounterMode));
    132 
    133 	pTimeCfg = (PWM_TIMERCFG_Type *) PWM_InitStruct;
    134 	pCounterCfg = (PWM_COUNTERCFG_Type *) PWM_InitStruct;
    135 
    136 	if (PWMTimerCounterMode == PWM_MODE_TIMER )
    137 	{
    138 		pTimeCfg->PrescaleOption = PWM_TIMER_PRESCALE_USVAL;
    139 		pTimeCfg->PrescaleValue = 1;
    140 	}
    141 	else if (PWMTimerCounterMode == PWM_MODE_COUNTER)
    142 	{
    143 		pCounterCfg->CountInputSelect = PWM_COUNTER_PCAP1_0;
    144 		pCounterCfg->CounterOption = PWM_COUNTER_RISING;
    145 	}
    146 }
    147 
    148 
    149 /*********************************************************************//**
    150  * @brief 		Initializes the PWMx peripheral corresponding to the specified
    151  *               parameters in the PWM_ConfigStruct.
    152  * @param[in]	PWMx PWM peripheral, should be LPC_PWM1
    153  * @param[in]	PWMTimerCounterMode Timer or Counter mode, should be:
    154  * 				- PWM_MODE_TIMER: Counter of PWM peripheral is in Timer mode
    155  * 				- PWM_MODE_COUNTER: Counter of PWM peripheral is in Counter mode
    156  * @param[in]	PWM_ConfigStruct Pointer to structure (PWM_TIMERCFG_Type or
    157  * 				 PWM_COUNTERCFG_Type) which will be initialized.
    158  * @return 		None
    159  * Note: PWM_ConfigStruct pointer will be assigned to corresponding structure
    160  * 		(PWM_TIMERCFG_Type or PWM_COUNTERCFG_Type) due to PWMTimerCounterMode.
    161  **********************************************************************/
    162 void PWM_Init(LPC_PWM_TypeDef *PWMx, uint32_t PWMTimerCounterMode, void *PWM_ConfigStruct)
    163 {
    164 	PWM_TIMERCFG_Type *pTimeCfg;
    165 	PWM_COUNTERCFG_Type *pCounterCfg;
    166 	uint64_t clkdlycnt;
    167 
    168 	CHECK_PARAM(PARAM_PWMx(PWMx));
    169 	CHECK_PARAM(PARAM_PWM_TC_MODE(PWMTimerCounterMode));
    170 
    171 	pTimeCfg = (PWM_TIMERCFG_Type *)PWM_ConfigStruct;
    172 	pCounterCfg = (PWM_COUNTERCFG_Type *)PWM_ConfigStruct;
    173 
    174 
    175 	CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCPWM1, ENABLE);
    176 	CLKPWR_SetPCLKDiv (CLKPWR_PCLKSEL_PWM1, CLKPWR_PCLKSEL_CCLK_DIV_4);
    177 	// Get peripheral clock of PWM1
    178 	clkdlycnt = (uint64_t) CLKPWR_GetPCLK (CLKPWR_PCLKSEL_PWM1);
    179 
    180 
    181 	// Clear all interrupts pending
    182 	PWMx->IR = 0xFF & PWM_IR_BITMASK;
    183 	PWMx->TCR = 0x00;
    184 	PWMx->CTCR = 0x00;
    185 	PWMx->MCR = 0x00;
    186 	PWMx->CCR = 0x00;
    187 	PWMx->PCR = 0x00;
    188 	PWMx->LER = 0x00;
    189 
    190 	if (PWMTimerCounterMode == PWM_MODE_TIMER)
    191 	{
    192 		CHECK_PARAM(PARAM_PWM_TIMER_PRESCALE(pTimeCfg->PrescaleOption));
    193 
    194 		/* Absolute prescale value */
    195 		if (pTimeCfg->PrescaleOption == PWM_TIMER_PRESCALE_TICKVAL)
    196 		{
    197 			PWMx->PR   = pTimeCfg->PrescaleValue - 1;
    198 		}
    199 		/* uSecond prescale value */
    200 		else
    201 		{
    202 			clkdlycnt = (clkdlycnt * pTimeCfg->PrescaleValue) / 1000000;
    203 			PWMx->PR = ((uint32_t) clkdlycnt) - 1;
    204 		}
    205 
    206 	}
    207 	else if (PWMTimerCounterMode == PWM_MODE_COUNTER)
    208 	{
    209 		CHECK_PARAM(PARAM_PWM_COUNTER_INPUTSEL(pCounterCfg->CountInputSelect));
    210 		CHECK_PARAM(PARAM_PWM_COUNTER_EDGE(pCounterCfg->CounterOption));
    211 
    212 		PWMx->CTCR |= (PWM_CTCR_MODE((uint32_t)pCounterCfg->CounterOption)) \
    213 						| (PWM_CTCR_SELECT_INPUT((uint32_t)pCounterCfg->CountInputSelect));
    214 	}
    215 }
    216 
    217 /*********************************************************************//**
    218  * @brief		De-initializes the PWM peripheral registers to their
    219 *                  default reset values.
    220  * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
    221  * @return 		None
    222  **********************************************************************/
    223 void PWM_DeInit (LPC_PWM_TypeDef *PWMx)
    224 {
    225 	CHECK_PARAM(PARAM_PWMx(PWMx));
    226 
    227 	// Disable PWM control (timer, counter and PWM)
    228 	PWMx->TCR = 0x00;
    229 	CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCPWM1, DISABLE);
    230 
    231 }
    232 
    233 
    234 /*********************************************************************//**
    235  * @brief	 	Enable/Disable PWM peripheral
    236  * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
    237  * @param[in]	NewState	New State of this function, should be:
    238  * 							- ENABLE: Enable PWM peripheral
    239  * 							- DISABLE: Disable PWM peripheral
    240  * @return 		None
    241  **********************************************************************/
    242 void PWM_Cmd(LPC_PWM_TypeDef *PWMx, FunctionalState NewState)
    243 {
    244 	CHECK_PARAM(PARAM_PWMx(PWMx));
    245 	CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
    246 
    247 	if (NewState == ENABLE)
    248 	{
    249 		PWMx->TCR	|=  PWM_TCR_PWM_ENABLE;
    250 	}
    251 	else
    252 	{
    253 		PWMx->TCR &= (~PWM_TCR_PWM_ENABLE) & PWM_TCR_BITMASK;
    254 	}
    255 }
    256 
    257 
    258 /*********************************************************************//**
    259  * @brief 		Enable/Disable Counter in PWM peripheral
    260  * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
    261  * @param[in]	NewState New State of this function, should be:
    262  * 							- ENABLE: Enable Counter in PWM peripheral
    263  * 							- DISABLE: Disable Counter in PWM peripheral
    264  * @return 		None
    265  **********************************************************************/
    266 void PWM_CounterCmd(LPC_PWM_TypeDef *PWMx, FunctionalState NewState)
    267 {
    268 	CHECK_PARAM(PARAM_PWMx(PWMx));
    269 	CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
    270 	if (NewState == ENABLE)
    271 	{
    272 		PWMx->TCR	|=  PWM_TCR_COUNTER_ENABLE;
    273 	}
    274 	else
    275 	{
    276 		PWMx->TCR &= (~PWM_TCR_COUNTER_ENABLE) & PWM_TCR_BITMASK;
    277 	}
    278 }
    279 
    280 
    281 /*********************************************************************//**
    282  * @brief 		Reset Counter in PWM peripheral
    283  * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
    284  * @return 		None
    285  **********************************************************************/
    286 void PWM_ResetCounter(LPC_PWM_TypeDef *PWMx)
    287 {
    288 	CHECK_PARAM(PARAM_PWMx(PWMx));
    289 	PWMx->TCR |= PWM_TCR_COUNTER_RESET;
    290 	PWMx->TCR &= (~PWM_TCR_COUNTER_RESET) & PWM_TCR_BITMASK;
    291 }
    292 
    293 
    294 /*********************************************************************//**
    295  * @brief 		Configures match for PWM peripheral
    296  * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
    297  * @param[in]   PWM_MatchConfigStruct	Pointer to a PWM_MATCHCFG_Type structure
    298 *                    that contains the configuration information for the
    299 *                    specified PWM match function.
    300  * @return 		None
    301  **********************************************************************/
    302 void PWM_ConfigMatch(LPC_PWM_TypeDef *PWMx, PWM_MATCHCFG_Type *PWM_MatchConfigStruct)
    303 {
    304 	CHECK_PARAM(PARAM_PWMx(PWMx));
    305 	CHECK_PARAM(PARAM_PWM1_MATCH_CHANNEL(PWM_MatchConfigStruct->MatchChannel));
    306 	CHECK_PARAM(PARAM_FUNCTIONALSTATE(PWM_MatchConfigStruct->IntOnMatch));
    307 	CHECK_PARAM(PARAM_FUNCTIONALSTATE(PWM_MatchConfigStruct->ResetOnMatch));
    308 	CHECK_PARAM(PARAM_FUNCTIONALSTATE(PWM_MatchConfigStruct->StopOnMatch));
    309 
    310 	//interrupt on MRn
    311 	if (PWM_MatchConfigStruct->IntOnMatch == ENABLE)
    312 	{
    313 		PWMx->MCR |= PWM_MCR_INT_ON_MATCH(PWM_MatchConfigStruct->MatchChannel);
    314 	}
    315 	else
    316 	{
    317 		PWMx->MCR &= (~PWM_MCR_INT_ON_MATCH(PWM_MatchConfigStruct->MatchChannel)) \
    318 					& PWM_MCR_BITMASK;
    319 	}
    320 
    321 	//reset on MRn
    322 	if (PWM_MatchConfigStruct->ResetOnMatch == ENABLE)
    323 	{
    324 		PWMx->MCR |= PWM_MCR_RESET_ON_MATCH(PWM_MatchConfigStruct->MatchChannel);
    325 	}
    326 	else
    327 	{
    328 		PWMx->MCR &= (~PWM_MCR_RESET_ON_MATCH(PWM_MatchConfigStruct->MatchChannel)) \
    329 					& PWM_MCR_BITMASK;
    330 	}
    331 
    332 	//stop on MRn
    333 	if (PWM_MatchConfigStruct->StopOnMatch == ENABLE)
    334 	{
    335 		PWMx->MCR |= PWM_MCR_STOP_ON_MATCH(PWM_MatchConfigStruct->MatchChannel);
    336 	}
    337 	else
    338 	{
    339 		PWMx->MCR &= (~PWM_MCR_STOP_ON_MATCH(PWM_MatchConfigStruct->MatchChannel)) \
    340 					& PWM_MCR_BITMASK;
    341 	}
    342 }
    343 
    344 
    345 /*********************************************************************//**
    346  * @brief 		Configures capture input for PWM peripheral
    347  * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
    348  * @param[in]   PWM_CaptureConfigStruct	Pointer to a PWM_CAPTURECFG_Type structure
    349 *                    that contains the configuration information for the
    350 *                    specified PWM capture input function.
    351  * @return 		None
    352  **********************************************************************/
    353 void PWM_ConfigCapture(LPC_PWM_TypeDef *PWMx, PWM_CAPTURECFG_Type *PWM_CaptureConfigStruct)
    354 {
    355 	CHECK_PARAM(PARAM_PWMx(PWMx));
    356 	CHECK_PARAM(PARAM_PWM1_CAPTURE_CHANNEL(PWM_CaptureConfigStruct->CaptureChannel));
    357 	CHECK_PARAM(PARAM_FUNCTIONALSTATE(PWM_CaptureConfigStruct->FallingEdge));
    358 	CHECK_PARAM(PARAM_FUNCTIONALSTATE(PWM_CaptureConfigStruct->IntOnCaption));
    359 	CHECK_PARAM(PARAM_FUNCTIONALSTATE(PWM_CaptureConfigStruct->RisingEdge));
    360 
    361 	if (PWM_CaptureConfigStruct->RisingEdge == ENABLE)
    362 	{
    363 		PWMx->CCR |= PWM_CCR_CAP_RISING(PWM_CaptureConfigStruct->CaptureChannel);
    364 	}
    365 	else
    366 	{
    367 		PWMx->CCR &= (~PWM_CCR_CAP_RISING(PWM_CaptureConfigStruct->CaptureChannel)) \
    368 					& PWM_CCR_BITMASK;
    369 	}
    370 
    371 	if (PWM_CaptureConfigStruct->FallingEdge == ENABLE)
    372 	{
    373 		PWMx->CCR |= PWM_CCR_CAP_FALLING(PWM_CaptureConfigStruct->CaptureChannel);
    374 	}
    375 	else
    376 	{
    377 		PWMx->CCR &= (~PWM_CCR_CAP_FALLING(PWM_CaptureConfigStruct->CaptureChannel)) \
    378 					& PWM_CCR_BITMASK;
    379 	}
    380 
    381 	if (PWM_CaptureConfigStruct->IntOnCaption == ENABLE)
    382 	{
    383 		PWMx->CCR |= PWM_CCR_INT_ON_CAP(PWM_CaptureConfigStruct->CaptureChannel);
    384 	}
    385 	else
    386 	{
    387 		PWMx->CCR &= (~PWM_CCR_INT_ON_CAP(PWM_CaptureConfigStruct->CaptureChannel)) \
    388 					& PWM_CCR_BITMASK;
    389 	}
    390 }
    391 
    392 
    393 /*********************************************************************//**
    394  * @brief 		Read value of capture register PWM peripheral
    395  * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
    396  * @param[in]	CaptureChannel: capture channel number, should be in
    397  * 				range 0 to 1
    398  * @return 		Value of capture register
    399  **********************************************************************/
    400 uint32_t PWM_GetCaptureValue(LPC_PWM_TypeDef *PWMx, uint8_t CaptureChannel)
    401 {
    402 	CHECK_PARAM(PARAM_PWMx(PWMx));
    403 	CHECK_PARAM(PARAM_PWM1_CAPTURE_CHANNEL(CaptureChannel));
    404 
    405 	switch (CaptureChannel)
    406 	{
    407 	case 0:
    408 		return PWMx->CR0;
    409 
    410 	case 1:
    411 		return PWMx->CR1;
    412 
    413 	default:
    414 		return (0);
    415 	}
    416 }
    417 
    418 
    419 /********************************************************************//**
    420  * @brief 		Update value for each PWM channel with update type option
    421  * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
    422  * @param[in]	MatchChannel Match channel
    423  * @param[in]	MatchValue Match value
    424  * @param[in]	UpdateType Type of Update, should be:
    425  * 				- PWM_MATCH_UPDATE_NOW: The update value will be updated for
    426  * 					this channel immediately
    427  * 				- PWM_MATCH_UPDATE_NEXT_RST: The update value will be updated for
    428  * 					this channel on next reset by a PWM Match event.
    429  * @return		None
    430  *********************************************************************/
    431 void PWM_MatchUpdate(LPC_PWM_TypeDef *PWMx, uint8_t MatchChannel, \
    432 					uint32_t MatchValue, uint8_t UpdateType)
    433 {
    434 	CHECK_PARAM(PARAM_PWMx(PWMx));
    435 	CHECK_PARAM(PARAM_PWM1_MATCH_CHANNEL(MatchChannel));
    436 	CHECK_PARAM(PARAM_PWM_MATCH_UPDATE(UpdateType));
    437 
    438 	switch (MatchChannel)
    439 	{
    440 	case 0:
    441 		PWMx->MR0 = MatchValue;
    442 		break;
    443 
    444 	case 1:
    445 		PWMx->MR1 = MatchValue;
    446 		break;
    447 
    448 	case 2:
    449 		PWMx->MR2 = MatchValue;
    450 		break;
    451 
    452 	case 3:
    453 		PWMx->MR3 = MatchValue;
    454 		break;
    455 
    456 	case 4:
    457 		PWMx->MR4 = MatchValue;
    458 		break;
    459 
    460 	case 5:
    461 		PWMx->MR5 = MatchValue;
    462 		break;
    463 
    464 	case 6:
    465 		PWMx->MR6 = MatchValue;
    466 		break;
    467 	}
    468 
    469 	// Write Latch register
    470 	PWMx->LER |= PWM_LER_EN_MATCHn_LATCH(MatchChannel);
    471 
    472 	// In case of update now
    473 	if (UpdateType == PWM_MATCH_UPDATE_NOW)
    474 	{
    475 		PWMx->TCR |= PWM_TCR_COUNTER_RESET;
    476 		PWMx->TCR &= (~PWM_TCR_COUNTER_RESET) & PWM_TCR_BITMASK;
    477 	}
    478 }
    479 
    480 /********************************************************************//**
    481  * @brief 		Update value for multi PWM channel with update type option
    482  * 				at the same time
    483  * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
    484  * @param[in]	MatchStruct Structure that contents match value of 7 pwm channels
    485  * @param[in]	UpdateType Type of Update, should be:
    486  * 				- PWM_MATCH_UPDATE_NOW: The update value will be updated for
    487  * 					this channel immediately
    488  * 				- PWM_MATCH_UPDATE_NEXT_RST: The update value will be updated for
    489  * 					this channel on next reset by a PWM Match event.
    490  * @return		None
    491  *********************************************************************/
    492 void PWM_MultiMatchUpdate(LPC_PWM_TypeDef *PWMx, PWM_Match_T *MatchStruct , uint8_t UpdateType)
    493 {
    494 	uint8_t LatchValue = 0;
    495 	uint8_t i;
    496 
    497 	CHECK_PARAM(PARAM_PWMx(PWMx));
    498 	CHECK_PARAM(PARAM_PWM_MATCH_UPDATE(UpdateType));
    499 
    500 	//Update match value
    501 	for(i=0;i<7;i++)
    502 	{
    503 		if(MatchStruct[i].Status == SET)
    504 		{
    505 			if(i<4)
    506 				*((volatile unsigned int *)(&(PWMx->MR0) + i)) = MatchStruct[i].Matchvalue;
    507 			else
    508 			{
    509 				*((volatile unsigned int *)(&(PWMx->MR4) + (i-4))) = MatchStruct[i].Matchvalue;
    510 			}
    511 			LatchValue |=(1<<i);
    512 		}
    513 	}
    514 	//set update for multi-channel at the same time
    515 	PWMx->LER = LatchValue;
    516 
    517 	// In case of update now
    518 	if (UpdateType == PWM_MATCH_UPDATE_NOW)
    519 	{
    520 		PWMx->TCR |= PWM_TCR_COUNTER_RESET;
    521 		PWMx->TCR &= (~PWM_TCR_COUNTER_RESET) & PWM_TCR_BITMASK;
    522 	}
    523 }
    524 /********************************************************************//**
    525  * @brief 		Configure Edge mode for each PWM channel
    526  * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
    527  * @param[in]	PWMChannel PWM channel, should be in range from 2 to 6
    528  * @param[in]	ModeOption PWM mode option, should be:
    529  * 				- PWM_CHANNEL_SINGLE_EDGE: Single Edge mode
    530  * 				- PWM_CHANNEL_DUAL_EDGE: Dual Edge mode
    531  * @return 		None
    532  * Note: PWM Channel 1 can not be selected for mode option
    533  *********************************************************************/
    534 void PWM_ChannelConfig(LPC_PWM_TypeDef *PWMx, uint8_t PWMChannel, uint8_t ModeOption)
    535 {
    536 	CHECK_PARAM(PARAM_PWMx(PWMx));
    537 	CHECK_PARAM(PARAM_PWM1_EDGE_MODE_CHANNEL(PWMChannel));
    538 	CHECK_PARAM(PARAM_PWM_CHANNEL_EDGE(ModeOption));
    539 
    540 	// Single edge mode
    541 	if (ModeOption == PWM_CHANNEL_SINGLE_EDGE)
    542 	{
    543 		PWMx->PCR &= (~PWM_PCR_PWMSELn(PWMChannel)) & PWM_PCR_BITMASK;
    544 	}
    545 	// Double edge mode
    546 	else if (PWM_CHANNEL_DUAL_EDGE)
    547 	{
    548 		PWMx->PCR |= PWM_PCR_PWMSELn(PWMChannel);
    549 	}
    550 }
    551 
    552 
    553 
    554 /********************************************************************//**
    555  * @brief 		Enable/Disable PWM channel output
    556  * @param[in]	PWMx	PWM peripheral selected, should be LPC_PWM1
    557  * @param[in]	PWMChannel PWM channel, should be in range from 1 to 6
    558  * @param[in]	NewState New State of this function, should be:
    559  * 				- ENABLE: Enable this PWM channel output
    560  * 				- DISABLE: Disable this PWM channel output
    561  * @return		None
    562  *********************************************************************/
    563 void PWM_ChannelCmd(LPC_PWM_TypeDef *PWMx, uint8_t PWMChannel, FunctionalState NewState)
    564 {
    565 	CHECK_PARAM(PARAM_PWMx(PWMx));
    566 	CHECK_PARAM(PARAM_PWM1_CHANNEL(PWMChannel));
    567 
    568 	if (NewState == ENABLE)
    569 	{
    570 		PWMx->PCR |= PWM_PCR_PWMENAn(PWMChannel);
    571 	}
    572 	else
    573 	{
    574 		PWMx->PCR &= (~PWM_PCR_PWMENAn(PWMChannel)) & PWM_PCR_BITMASK;
    575 	}
    576 }
    577 
    578 /**
    579  * @}
    580  */
    581 
    582 #endif /* _PWM */
    583 
    584 /**
    585  * @}
    586  */
    587 
    588 /* --------------------------------- End Of File ------------------------------ */