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_match_int.c
frank26080115 0:bf7b9fba3924 3 * @purpose PWM match interrupt example
frank26080115 0:bf7b9fba3924 4 * @version 2.0
frank26080115 0:bf7b9fba3924 5 * @date 21. May. 2010
frank26080115 0:bf7b9fba3924 6 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 7 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 8 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 9 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 10 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 11 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 12 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 13 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 14 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 15 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 16 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 17 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 18 **********************************************************************/
frank26080115 0:bf7b9fba3924 19 #include "lpc17xx_pwm.h"
frank26080115 0:bf7b9fba3924 20 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 22
frank26080115 0:bf7b9fba3924 23 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 24 /** @defgroup PWM_Match_Interrupt Match_Interrupt
frank26080115 0:bf7b9fba3924 25 * @ingroup PWM_Examples
frank26080115 0:bf7b9fba3924 26 * @{
frank26080115 0:bf7b9fba3924 27 */
frank26080115 0:bf7b9fba3924 28
frank26080115 0:bf7b9fba3924 29 /************************** PRIVATE DEFINITIONS *************************/
frank26080115 0:bf7b9fba3924 30 // Time out definition - used in blocking mode in read/write function
frank26080115 0:bf7b9fba3924 31 #define TIME_OUT 10000
frank26080115 0:bf7b9fba3924 32
frank26080115 0:bf7b9fba3924 33
frank26080115 0:bf7b9fba3924 34 /************************** PRIVATE VARIABLES *************************/
frank26080115 0:bf7b9fba3924 35 __IO uint32_t match_cnt = 0;
frank26080115 0:bf7b9fba3924 36 __IO uint32_t long_duty = 0;
frank26080115 0:bf7b9fba3924 37
frank26080115 0:bf7b9fba3924 38 /************************** PRIVATE FUNCTIONS *************************/
frank26080115 0:bf7b9fba3924 39 /* Interrupt service routine */
frank26080115 0:bf7b9fba3924 40 void PWM1_IRQHandler(void);
frank26080115 0:bf7b9fba3924 41
frank26080115 0:bf7b9fba3924 42 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
frank26080115 0:bf7b9fba3924 43 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 44 * @brief GPDMA interrupt handler sub-routine
frank26080115 0:bf7b9fba3924 45 * @param[in] None
frank26080115 0:bf7b9fba3924 46 * @return None
frank26080115 0:bf7b9fba3924 47 **********************************************************************/
frank26080115 0:bf7b9fba3924 48 void PWM1_IRQHandler(void)
frank26080115 0:bf7b9fba3924 49 {
frank26080115 0:bf7b9fba3924 50 /* Check whether if match flag for channel 0 is set or not */
frank26080115 0:bf7b9fba3924 51 if (PWM_GetIntStatus(LPC_PWM1, PWM_INTSTAT_MR0))
frank26080115 0:bf7b9fba3924 52 {
frank26080115 0:bf7b9fba3924 53 match_cnt++;
frank26080115 0:bf7b9fba3924 54 /* Clear the interrupt flag */
frank26080115 0:bf7b9fba3924 55 PWM_ClearIntPending(LPC_PWM1, PWM_INTSTAT_MR0);
frank26080115 0:bf7b9fba3924 56 }
frank26080115 0:bf7b9fba3924 57 }
frank26080115 0:bf7b9fba3924 58
frank26080115 0:bf7b9fba3924 59
frank26080115 0:bf7b9fba3924 60 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 61 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 62 * @brief c_entry: Main PWM program body
frank26080115 0:bf7b9fba3924 63 * @param[in] None
frank26080115 0:bf7b9fba3924 64 * @return int
frank26080115 0:bf7b9fba3924 65 **********************************************************************/
frank26080115 0:bf7b9fba3924 66 int c_entry(void)
frank26080115 0:bf7b9fba3924 67 {
frank26080115 0:bf7b9fba3924 68 uint8_t temp, temp2;
frank26080115 0:bf7b9fba3924 69 PWM_TIMERCFG_Type PWMCfgDat;
frank26080115 0:bf7b9fba3924 70 PWM_MATCHCFG_Type PWMMatchCfgDat;
frank26080115 0:bf7b9fba3924 71 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 72
frank26080115 0:bf7b9fba3924 73 /* PWM block section -------------------------------------------- */
frank26080115 0:bf7b9fba3924 74 /* Initialize PWM peripheral, timer mode
frank26080115 0:bf7b9fba3924 75 * PWM prescale value = 1 (absolute value - tick value) */
frank26080115 0:bf7b9fba3924 76 PWMCfgDat.PrescaleOption = PWM_TIMER_PRESCALE_TICKVAL;
frank26080115 0:bf7b9fba3924 77 PWMCfgDat.PrescaleValue = 1;
frank26080115 0:bf7b9fba3924 78 PWM_Init(LPC_PWM1, PWM_MODE_TIMER, (void *) &PWMCfgDat);
frank26080115 0:bf7b9fba3924 79
frank26080115 0:bf7b9fba3924 80 /*
frank26080115 0:bf7b9fba3924 81 * Initialize PWM pin connect
frank26080115 0:bf7b9fba3924 82 */
frank26080115 0:bf7b9fba3924 83 PinCfg.Funcnum = 1;
frank26080115 0:bf7b9fba3924 84 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 85 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 86 PinCfg.Portnum = 2;
frank26080115 0:bf7b9fba3924 87 for (temp = 0; temp <= 6; temp++){
frank26080115 0:bf7b9fba3924 88 PinCfg.Pinnum = temp;
frank26080115 0:bf7b9fba3924 89 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 90 }
frank26080115 0:bf7b9fba3924 91
frank26080115 0:bf7b9fba3924 92
frank26080115 0:bf7b9fba3924 93 /* Set match value for PWM match channel 0 = 256, update immediately */
frank26080115 0:bf7b9fba3924 94 PWM_MatchUpdate(LPC_PWM1, 0, 256, PWM_MATCH_UPDATE_NOW);
frank26080115 0:bf7b9fba3924 95 /* PWM Timer/Counter will be reset when channel 0 matching
frank26080115 0:bf7b9fba3924 96 * Enable interrupt when match
frank26080115 0:bf7b9fba3924 97 * no stop when match */
frank26080115 0:bf7b9fba3924 98 PWMMatchCfgDat.IntOnMatch = ENABLE;
frank26080115 0:bf7b9fba3924 99 PWMMatchCfgDat.MatchChannel = 0;
frank26080115 0:bf7b9fba3924 100 PWMMatchCfgDat.ResetOnMatch = ENABLE;
frank26080115 0:bf7b9fba3924 101 PWMMatchCfgDat.StopOnMatch = DISABLE;
frank26080115 0:bf7b9fba3924 102 PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat);
frank26080115 0:bf7b9fba3924 103
frank26080115 0:bf7b9fba3924 104 /* Configure each PWM channel: --------------------------------------------- */
frank26080115 0:bf7b9fba3924 105 /* - Single edge
frank26080115 0:bf7b9fba3924 106 * - PWM Duty on each PWM channel determined by
frank26080115 0:bf7b9fba3924 107 * the match on channel 0 to the match of that match channel.
frank26080115 0:bf7b9fba3924 108 * Example: PWM Duty on PWM channel 1 determined by
frank26080115 0:bf7b9fba3924 109 * the match on channel 0 to the match of match channel 1.
frank26080115 0:bf7b9fba3924 110 */
frank26080115 0:bf7b9fba3924 111
frank26080115 0:bf7b9fba3924 112 /* Configure PWM channel edge option
frank26080115 0:bf7b9fba3924 113 * Note: PWM Channel 1 is in single mode as default state and
frank26080115 0:bf7b9fba3924 114 * can not be changed to double edge mode */
frank26080115 0:bf7b9fba3924 115 for (temp = 2; temp < 7; temp++)
frank26080115 0:bf7b9fba3924 116 {
frank26080115 0:bf7b9fba3924 117 PWM_ChannelConfig(LPC_PWM1, temp, PWM_CHANNEL_SINGLE_EDGE);
frank26080115 0:bf7b9fba3924 118 }
frank26080115 0:bf7b9fba3924 119
frank26080115 0:bf7b9fba3924 120 /* Setting interrupt for PWM ---------------------------------------------- */
frank26080115 0:bf7b9fba3924 121 /* Disable PWM interrupt */
frank26080115 0:bf7b9fba3924 122 NVIC_DisableIRQ(PWM1_IRQn);
frank26080115 0:bf7b9fba3924 123 /* preemption = 1, sub-priority = 1 */
frank26080115 0:bf7b9fba3924 124 NVIC_SetPriority(PWM1_IRQn, ((0x01<<3)|0x01));
frank26080115 0:bf7b9fba3924 125
frank26080115 0:bf7b9fba3924 126 /* Configure match value for each match channel */
frank26080115 0:bf7b9fba3924 127 temp2 = 10;
frank26080115 0:bf7b9fba3924 128 for (temp = 1; temp < 7; temp++)
frank26080115 0:bf7b9fba3924 129 {
frank26080115 0:bf7b9fba3924 130 /* Set up match value */
frank26080115 0:bf7b9fba3924 131 PWM_MatchUpdate(LPC_PWM1, temp, temp2, PWM_MATCH_UPDATE_NOW);
frank26080115 0:bf7b9fba3924 132 /* Configure match option */
frank26080115 0:bf7b9fba3924 133 PWMMatchCfgDat.IntOnMatch = DISABLE;
frank26080115 0:bf7b9fba3924 134 PWMMatchCfgDat.MatchChannel = temp;
frank26080115 0:bf7b9fba3924 135 PWMMatchCfgDat.ResetOnMatch = DISABLE;
frank26080115 0:bf7b9fba3924 136 PWMMatchCfgDat.StopOnMatch = DISABLE;
frank26080115 0:bf7b9fba3924 137 PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat);
frank26080115 0:bf7b9fba3924 138 /* Enable PWM Channel Output */
frank26080115 0:bf7b9fba3924 139 PWM_ChannelCmd(LPC_PWM1, temp, ENABLE);
frank26080115 0:bf7b9fba3924 140 /* Increase match value by 10 */
frank26080115 0:bf7b9fba3924 141 temp2 += 10;
frank26080115 0:bf7b9fba3924 142 }
frank26080115 0:bf7b9fba3924 143
frank26080115 0:bf7b9fba3924 144 /* Enable PWM interrupt */
frank26080115 0:bf7b9fba3924 145 NVIC_EnableIRQ(PWM1_IRQn);
frank26080115 0:bf7b9fba3924 146
frank26080115 0:bf7b9fba3924 147 /* Reset and Start counter */
frank26080115 0:bf7b9fba3924 148 PWM_ResetCounter(LPC_PWM1);
frank26080115 0:bf7b9fba3924 149 PWM_CounterCmd(LPC_PWM1, ENABLE);
frank26080115 0:bf7b9fba3924 150
frank26080115 0:bf7b9fba3924 151 /* Start PWM now */
frank26080115 0:bf7b9fba3924 152 PWM_Cmd(LPC_PWM1, ENABLE);
frank26080115 0:bf7b9fba3924 153
frank26080115 0:bf7b9fba3924 154 // Update PWM1.1 every 0x1000 match interrupt
frank26080115 0:bf7b9fba3924 155 while (1)
frank26080115 0:bf7b9fba3924 156 {
frank26080115 0:bf7b9fba3924 157 if (match_cnt >= 0x1000) {
frank26080115 0:bf7b9fba3924 158 match_cnt = 0;
frank26080115 0:bf7b9fba3924 159 long_duty++;
frank26080115 0:bf7b9fba3924 160 if (long_duty >= 256) {
frank26080115 0:bf7b9fba3924 161 // Reset duty
frank26080115 0:bf7b9fba3924 162 long_duty = 0;
frank26080115 0:bf7b9fba3924 163 // Print info
frank26080115 0:bf7b9fba3924 164 //UART_Puts_(uartdev, "PWM1.1 is reset!");
frank26080115 0:bf7b9fba3924 165 }
frank26080115 0:bf7b9fba3924 166
frank26080115 0:bf7b9fba3924 167 // Update PWM1.1 duty
frank26080115 0:bf7b9fba3924 168 PWM_MatchUpdate(LPC_PWM1, 1, long_duty, PWM_MATCH_UPDATE_NOW);
frank26080115 0:bf7b9fba3924 169 }
frank26080115 0:bf7b9fba3924 170 }
frank26080115 0:bf7b9fba3924 171 return 1;
frank26080115 0:bf7b9fba3924 172 }
frank26080115 0:bf7b9fba3924 173
frank26080115 0:bf7b9fba3924 174 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 175 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 176 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 177 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 178 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 179 int main(void)
frank26080115 0:bf7b9fba3924 180 {
frank26080115 0:bf7b9fba3924 181 return c_entry();
frank26080115 0:bf7b9fba3924 182 }
frank26080115 0:bf7b9fba3924 183
frank26080115 0:bf7b9fba3924 184
frank26080115 0:bf7b9fba3924 185 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 186 /*******************************************************************************
frank26080115 0:bf7b9fba3924 187 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 188 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 189 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 190 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 191 * @return None
frank26080115 0:bf7b9fba3924 192 *******************************************************************************/
frank26080115 0:bf7b9fba3924 193 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 194 {
frank26080115 0:bf7b9fba3924 195 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 196 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 197
frank26080115 0:bf7b9fba3924 198 /* Infinite loop */
frank26080115 0:bf7b9fba3924 199 while(1);
frank26080115 0:bf7b9fba3924 200 }
frank26080115 0:bf7b9fba3924 201 #endif
frank26080115 0:bf7b9fba3924 202
frank26080115 0:bf7b9fba3924 203 /*
frank26080115 0:bf7b9fba3924 204 * @}
frank26080115 0:bf7b9fba3924 205 */