Loading to flash works now.
[LPC2xxx_and_RobotSpejbl.git] / app / contrib / test_pwm / test_pwm.c
blob13b43db6cd04cce72305cb4ce75d5165f6135751
1 /******************************************************************************/
2 /* This file is part of the uVision/ARM development tools */
3 /* Copyright KEIL ELEKTRONIK GmbH 2002-2004 */
4 /******************************************************************************/
5 /* */
6 /* PWM.C: LED Flasher */
7 /* */
8 /******************************************************************************/
12 #include <types.h>
13 #include <LPC210x.h>
14 #include "config.h"
15 #include "pwm.h"
19 /**
20 * * Function Name: lowInit()
22 * Description:
23 * This function starts up the PLL then sets up the GPIO pins before
24 * waiting for the PLL to lock. It finally engages the PLL and
25 * returns
27 * Calling Sequence:
28 * void
30 * Returns:
31 * void
35 static void lowInit(void)
37 // set PLL multiplier & divisor.
38 // values computed from config.h
39 PLLCFG = PLLCFG_MSEL | PLLCFG_PSEL;
41 // enable PLL
42 PLLCON = PLLCON_PLLE;
43 PLLFEED = 0xAA; // Make it happen. These two updates
44 PLLFEED = 0x55; // MUST occur in sequence.
46 // setup the parallel port pin
47 IOCLR = PIO_ZERO_BITS; // clear the ZEROs output
48 IOSET = PIO_ONE_BITS; // set the ONEs output
49 IODIR = PIO_OUTPUT_BITS; // set the output bit direction
51 // wait for PLL lock
52 while (!(PLLSTAT & PLLSTAT_LOCK))
53 continue;
55 // enable & connect PLL
56 PLLCON = PLLCON_PLLE | PLLCON_PLLC;
57 PLLFEED = 0xAA; // Make it happen. These two updates
58 PLLFEED = 0x55; // MUST occur in sequence.
60 // setup & enable the MAM
61 MAMTIM = MAMTIM_CYCLES;
62 MAMCR = MAMCR_FULL;
64 // set the peripheral bus speed
65 // value computed from config.h
66 VPBDIV = VPBDIV_VALUE; // set the peripheral bus clock speed
70 /**
71 * Function Name: sysInit()
73 * Description:
74 * This function is responsible for initializing the program
75 * specific hardware
77 * Calling Sequence:
78 * void
80 * Returns:
81 * void
86 static void sysInit(void)
88 lowInit(); // setup clocks and processor port pins
90 // set the interrupt controller defaults
91 #define RAM_RUN
92 #if defined(RAM_RUN)
93 MEMMAP = MEMMAP_SRAM; // map interrupt vectors space into SRAM
94 #elif defined(ROM_RUN)
95 MEMMAP = MEMMAP_FLASH; // map interrupt vectors space into FLASH
96 #else
97 #error RUN_MODE not defined!
98 #endif
99 VICIntEnClear = 0xFFFFFFFF; // clear all interrupts
100 VICIntSelect = 0x00000000; // clear all FIQ selections
101 VICDefVectAddr = (uint32_t)reset; // point unvectored IRQs to reset()
107 * Creates a delay
108 * @param d duration (unit not defined yet)
110 void
111 delay(int d)
113 volatile int x;
114 int i;
115 for (i = 0; i < 10; i++)
116 for(x = d; x; --x)
123 * this function has been created to test PWM unit
124 * It has been tested with the DC motor of M.Sojka ;-)
125 * One accelerated phase with upward rotation then one constant speed phase with backward rotation
126 * DC motor pin 2 = PWM4
127 * DC motor pin 3 = PWM6
128 * DC motor pin 25 = GND
129 * @return
131 int main() {
133 int j;
136 sysInit();
138 Init_PWM(20000);
140 Run_PWM();
141 Set_PWM (6,0);
142 for (j = 0 ; j < 10 ; j++)
144 Set_PWM (4, j*0.1);
145 delay (500000);
150 while (1)
151 { /* Loop forever */
154 return 0;