These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /***********************************************************************//**
frank26080115 0:bf7b9fba3924 2 * @file pwm_single_edge.c
frank26080115 0:bf7b9fba3924 3 * @purpose This program illustrates the PWM signal on 6 Channels
frank26080115 0:bf7b9fba3924 4 * in single edge mode
frank26080115 0:bf7b9fba3924 5 * @version 2.0
frank26080115 0:bf7b9fba3924 6 * @date 21. May. 2010
frank26080115 0:bf7b9fba3924 7 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 8 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 9 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 10 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 11 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 12 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 13 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 14 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 15 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 16 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 17 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 18 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 19 **********************************************************************/
frank26080115 0:bf7b9fba3924 20 #include "lpc17xx_pwm.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 22 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 23
frank26080115 0:bf7b9fba3924 24 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 25 /** @defgroup PWM_Single_Edge Single_Edge
frank26080115 0:bf7b9fba3924 26 * @ingroup PWM_Examples
frank26080115 0:bf7b9fba3924 27 * @{
frank26080115 0:bf7b9fba3924 28 */
frank26080115 0:bf7b9fba3924 29
frank26080115 0:bf7b9fba3924 30 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 31 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 32 * @brief c_entry: Main PWM program body
frank26080115 0:bf7b9fba3924 33 * @param[in] None
frank26080115 0:bf7b9fba3924 34 * @return int
frank26080115 0:bf7b9fba3924 35 **********************************************************************/
frank26080115 0:bf7b9fba3924 36 int c_entry(void)
frank26080115 0:bf7b9fba3924 37 {
frank26080115 0:bf7b9fba3924 38 uint8_t temp, temp2;
frank26080115 0:bf7b9fba3924 39 PWM_TIMERCFG_Type PWMCfgDat;
frank26080115 0:bf7b9fba3924 40 PWM_MATCHCFG_Type PWMMatchCfgDat;
frank26080115 0:bf7b9fba3924 41 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 42
frank26080115 0:bf7b9fba3924 43 /* PWM block section -------------------------------------------- */
frank26080115 0:bf7b9fba3924 44 /* Initialize PWM peripheral, timer mode
frank26080115 0:bf7b9fba3924 45 * PWM prescale value = 1 (absolute value - tick value) */
frank26080115 0:bf7b9fba3924 46 PWMCfgDat.PrescaleOption = PWM_TIMER_PRESCALE_TICKVAL;
frank26080115 0:bf7b9fba3924 47 PWMCfgDat.PrescaleValue = 1;
frank26080115 0:bf7b9fba3924 48 PWM_Init(LPC_PWM1, PWM_MODE_TIMER, (void *) &PWMCfgDat);
frank26080115 0:bf7b9fba3924 49
frank26080115 0:bf7b9fba3924 50 /*
frank26080115 0:bf7b9fba3924 51 * Initialize PWM pin connect
frank26080115 0:bf7b9fba3924 52 */
frank26080115 0:bf7b9fba3924 53 PinCfg.Funcnum = 1;
frank26080115 0:bf7b9fba3924 54 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 55 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 56 PinCfg.Portnum = 2;
frank26080115 0:bf7b9fba3924 57 for (temp = 0; temp <= 6; temp++){
frank26080115 0:bf7b9fba3924 58 PinCfg.Pinnum = temp;
frank26080115 0:bf7b9fba3924 59 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 60 }
frank26080115 0:bf7b9fba3924 61
frank26080115 0:bf7b9fba3924 62
frank26080115 0:bf7b9fba3924 63 /* Set match value for PWM match channel 0 = 256, update immediately */
frank26080115 0:bf7b9fba3924 64 PWM_MatchUpdate(LPC_PWM1, 0, 256, PWM_MATCH_UPDATE_NOW);
frank26080115 0:bf7b9fba3924 65 /* PWM Timer/Counter will be reset when channel 0 matching
frank26080115 0:bf7b9fba3924 66 * no interrupt when match
frank26080115 0:bf7b9fba3924 67 * no stop when match */
frank26080115 0:bf7b9fba3924 68 PWMMatchCfgDat.IntOnMatch = DISABLE;
frank26080115 0:bf7b9fba3924 69 PWMMatchCfgDat.MatchChannel = 0;
frank26080115 0:bf7b9fba3924 70 PWMMatchCfgDat.ResetOnMatch = ENABLE;
frank26080115 0:bf7b9fba3924 71 PWMMatchCfgDat.StopOnMatch = DISABLE;
frank26080115 0:bf7b9fba3924 72 PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat);
frank26080115 0:bf7b9fba3924 73
frank26080115 0:bf7b9fba3924 74 /* Configure each PWM channel: --------------------------------------------- */
frank26080115 0:bf7b9fba3924 75 /* - Single edge
frank26080115 0:bf7b9fba3924 76 * - PWM Duty on each PWM channel determined by
frank26080115 0:bf7b9fba3924 77 * the match on channel 0 to the match of that match channel.
frank26080115 0:bf7b9fba3924 78 * Example: PWM Duty on PWM channel 1 determined by
frank26080115 0:bf7b9fba3924 79 * the match on channel 0 to the match of match channel 1.
frank26080115 0:bf7b9fba3924 80 */
frank26080115 0:bf7b9fba3924 81
frank26080115 0:bf7b9fba3924 82 /* Configure PWM channel edge option
frank26080115 0:bf7b9fba3924 83 * Note: PWM Channel 1 is in single mode as default state and
frank26080115 0:bf7b9fba3924 84 * can not be changed to double edge mode */
frank26080115 0:bf7b9fba3924 85 for (temp = 2; temp < 7; temp++)
frank26080115 0:bf7b9fba3924 86 {
frank26080115 0:bf7b9fba3924 87 PWM_ChannelConfig(LPC_PWM1, temp, PWM_CHANNEL_SINGLE_EDGE);
frank26080115 0:bf7b9fba3924 88 }
frank26080115 0:bf7b9fba3924 89
frank26080115 0:bf7b9fba3924 90
frank26080115 0:bf7b9fba3924 91 /* Configure match value for each match channel */
frank26080115 0:bf7b9fba3924 92 temp2 = 10;
frank26080115 0:bf7b9fba3924 93 for (temp = 1; temp < 7; temp++)
frank26080115 0:bf7b9fba3924 94 {
frank26080115 0:bf7b9fba3924 95 /* Set up match value */
frank26080115 0:bf7b9fba3924 96 PWM_MatchUpdate(LPC_PWM1, temp, temp2, PWM_MATCH_UPDATE_NOW);
frank26080115 0:bf7b9fba3924 97 /* Configure match option */
frank26080115 0:bf7b9fba3924 98 PWMMatchCfgDat.IntOnMatch = DISABLE;
frank26080115 0:bf7b9fba3924 99 PWMMatchCfgDat.MatchChannel = temp;
frank26080115 0:bf7b9fba3924 100 PWMMatchCfgDat.ResetOnMatch = DISABLE;
frank26080115 0:bf7b9fba3924 101 PWMMatchCfgDat.StopOnMatch = DISABLE;
frank26080115 0:bf7b9fba3924 102 PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat);
frank26080115 0:bf7b9fba3924 103 /* Enable PWM Channel Output */
frank26080115 0:bf7b9fba3924 104 PWM_ChannelCmd(LPC_PWM1, temp, ENABLE);
frank26080115 0:bf7b9fba3924 105 /* Increase match value by 10 */
frank26080115 0:bf7b9fba3924 106 temp2 += 10;
frank26080115 0:bf7b9fba3924 107 }
frank26080115 0:bf7b9fba3924 108
frank26080115 0:bf7b9fba3924 109 /* Reset and Start counter */
frank26080115 0:bf7b9fba3924 110 PWM_ResetCounter(LPC_PWM1);
frank26080115 0:bf7b9fba3924 111 PWM_CounterCmd(LPC_PWM1, ENABLE);
frank26080115 0:bf7b9fba3924 112
frank26080115 0:bf7b9fba3924 113 /* Start PWM now */
frank26080115 0:bf7b9fba3924 114 PWM_Cmd(LPC_PWM1, ENABLE);
frank26080115 0:bf7b9fba3924 115
frank26080115 0:bf7b9fba3924 116 /* Loop forever */
frank26080115 0:bf7b9fba3924 117 while(1);
frank26080115 0:bf7b9fba3924 118 return 1;
frank26080115 0:bf7b9fba3924 119 }
frank26080115 0:bf7b9fba3924 120
frank26080115 0:bf7b9fba3924 121 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 122 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 123 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 124 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 125 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 126 int main(void)
frank26080115 0:bf7b9fba3924 127 {
frank26080115 0:bf7b9fba3924 128 return c_entry();
frank26080115 0:bf7b9fba3924 129 }
frank26080115 0:bf7b9fba3924 130
frank26080115 0:bf7b9fba3924 131
frank26080115 0:bf7b9fba3924 132 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 133 /*******************************************************************************
frank26080115 0:bf7b9fba3924 134 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 135 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 136 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 137 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 138 * @return None
frank26080115 0:bf7b9fba3924 139 *******************************************************************************/
frank26080115 0:bf7b9fba3924 140 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 141 {
frank26080115 0:bf7b9fba3924 142 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 143 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 144
frank26080115 0:bf7b9fba3924 145 /* Infinite loop */
frank26080115 0:bf7b9fba3924 146 while(1);
frank26080115 0:bf7b9fba3924 147 }
frank26080115 0:bf7b9fba3924 148 #endif
frank26080115 0:bf7b9fba3924 149
frank26080115 0:bf7b9fba3924 150 /*
frank26080115 0:bf7b9fba3924 151 * @}
frank26080115 0:bf7b9fba3924 152 */