These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!
pwm_single_edge.c
00001 /***********************************************************************//** 00002 * @file pwm_single_edge.c 00003 * @purpose This program illustrates the PWM signal on 6 Channels 00004 * in single edge mode 00005 * @version 2.0 00006 * @date 21. May. 2010 00007 * @author NXP MCU SW Application Team 00008 *--------------------------------------------------------------------- 00009 * Software that is described herein is for illustrative purposes only 00010 * which provides customers with programming information regarding the 00011 * products. This software is supplied "AS IS" without any warranties. 00012 * NXP Semiconductors assumes no responsibility or liability for the 00013 * use of the software, conveys no license or title under any patent, 00014 * copyright, or mask work right to the product. NXP Semiconductors 00015 * reserves the right to make changes in the software without 00016 * notification. NXP Semiconductors also make no representation or 00017 * warranty that such application will be suitable for the specified 00018 * use without further testing or modification. 00019 **********************************************************************/ 00020 #include "lpc17xx_pwm.h" 00021 #include "lpc17xx_libcfg.h" 00022 #include "lpc17xx_pinsel.h" 00023 00024 /* Example group ----------------------------------------------------------- */ 00025 /** @defgroup PWM_Single_Edge Single_Edge 00026 * @ingroup PWM_Examples 00027 * @{ 00028 */ 00029 00030 /*-------------------------MAIN FUNCTION------------------------------*/ 00031 /*********************************************************************//** 00032 * @brief c_entry: Main PWM program body 00033 * @param[in] None 00034 * @return int 00035 **********************************************************************/ 00036 int c_entry(void) 00037 { 00038 uint8_t temp, temp2; 00039 PWM_TIMERCFG_Type PWMCfgDat; 00040 PWM_MATCHCFG_Type PWMMatchCfgDat; 00041 PINSEL_CFG_Type PinCfg; 00042 00043 /* PWM block section -------------------------------------------- */ 00044 /* Initialize PWM peripheral, timer mode 00045 * PWM prescale value = 1 (absolute value - tick value) */ 00046 PWMCfgDat.PrescaleOption = PWM_TIMER_PRESCALE_TICKVAL; 00047 PWMCfgDat.PrescaleValue = 1; 00048 PWM_Init(LPC_PWM1, PWM_MODE_TIMER, (void *) &PWMCfgDat); 00049 00050 /* 00051 * Initialize PWM pin connect 00052 */ 00053 PinCfg.Funcnum = 1; 00054 PinCfg.OpenDrain = 0; 00055 PinCfg.Pinmode = 0; 00056 PinCfg.Portnum = 2; 00057 for (temp = 0; temp <= 6; temp++){ 00058 PinCfg.Pinnum = temp; 00059 PINSEL_ConfigPin(&PinCfg); 00060 } 00061 00062 00063 /* Set match value for PWM match channel 0 = 256, update immediately */ 00064 PWM_MatchUpdate(LPC_PWM1, 0, 256, PWM_MATCH_UPDATE_NOW); 00065 /* PWM Timer/Counter will be reset when channel 0 matching 00066 * no interrupt when match 00067 * no stop when match */ 00068 PWMMatchCfgDat.IntOnMatch = DISABLE; 00069 PWMMatchCfgDat.MatchChannel = 0; 00070 PWMMatchCfgDat.ResetOnMatch = ENABLE; 00071 PWMMatchCfgDat.StopOnMatch = DISABLE; 00072 PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat); 00073 00074 /* Configure each PWM channel: --------------------------------------------- */ 00075 /* - Single edge 00076 * - PWM Duty on each PWM channel determined by 00077 * the match on channel 0 to the match of that match channel. 00078 * Example: PWM Duty on PWM channel 1 determined by 00079 * the match on channel 0 to the match of match channel 1. 00080 */ 00081 00082 /* Configure PWM channel edge option 00083 * Note: PWM Channel 1 is in single mode as default state and 00084 * can not be changed to double edge mode */ 00085 for (temp = 2; temp < 7; temp++) 00086 { 00087 PWM_ChannelConfig(LPC_PWM1, temp, PWM_CHANNEL_SINGLE_EDGE); 00088 } 00089 00090 00091 /* Configure match value for each match channel */ 00092 temp2 = 10; 00093 for (temp = 1; temp < 7; temp++) 00094 { 00095 /* Set up match value */ 00096 PWM_MatchUpdate(LPC_PWM1, temp, temp2, PWM_MATCH_UPDATE_NOW); 00097 /* Configure match option */ 00098 PWMMatchCfgDat.IntOnMatch = DISABLE; 00099 PWMMatchCfgDat.MatchChannel = temp; 00100 PWMMatchCfgDat.ResetOnMatch = DISABLE; 00101 PWMMatchCfgDat.StopOnMatch = DISABLE; 00102 PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat); 00103 /* Enable PWM Channel Output */ 00104 PWM_ChannelCmd(LPC_PWM1, temp, ENABLE); 00105 /* Increase match value by 10 */ 00106 temp2 += 10; 00107 } 00108 00109 /* Reset and Start counter */ 00110 PWM_ResetCounter(LPC_PWM1); 00111 PWM_CounterCmd(LPC_PWM1, ENABLE); 00112 00113 /* Start PWM now */ 00114 PWM_Cmd(LPC_PWM1, ENABLE); 00115 00116 /* Loop forever */ 00117 while(1); 00118 return 1; 00119 } 00120 00121 /* With ARM and GHS toolsets, the entry point is main() - this will 00122 allow the linker to generate wrapper code to setup stacks, allocate 00123 heap area, and initialize and copy code and data segments. For GNU 00124 toolsets, the entry point is through __start() in the crt0_gnu.asm 00125 file, and that startup code will setup stacks and data */ 00126 int main(void) 00127 { 00128 return c_entry(); 00129 } 00130 00131 00132 #ifdef DEBUG 00133 /******************************************************************************* 00134 * @brief Reports the name of the source file and the source line number 00135 * where the CHECK_PARAM error has occurred. 00136 * @param[in] file Pointer to the source file name 00137 * @param[in] line assert_param error line source number 00138 * @return None 00139 *******************************************************************************/ 00140 void check_failed(uint8_t *file, uint32_t line) 00141 { 00142 /* User can add his own implementation to report the file name and line number, 00143 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00144 00145 /* Infinite loop */ 00146 while(1); 00147 } 00148 #endif 00149 00150 /* 00151 * @} 00152 */
Generated on Tue Jul 12 2022 17:28:09 by 1.7.2