Hello everyone,
A little background on what I am doing. I am trying to use an LPC2292 microprocessor to create a simple stopwatch. It needs to read in two inputs: Start/Stop and Reset. The Start/Stop is one push button on the demo board I am using to toggle the stopwatch on and off and Reset is another push button that will reset the stopwatch back to 00:00.00 if it is in a stopped state.
Anyway, the problem I am having is that I am using the two timers (Timer0 and Timer1) to generate interrupts. Timer0 is set to generate an interrupt every 0.01s and Timer1 is set to generate an interrupt every 0.001s.
Timer0's ISR simply increments several variables I am using to store minutes, seconds, hundredths, etc.
I was going to use Timer1's ISR to poll the input pins to see if my Start/Stop, Reset pins had changed. However, I, apparently, have not been able to set up the VIC registers correctly.
I have been reading the datasheet...
www.eng.auburn.edu/.../elec5260_6260/user.manual.lpc2119.lpc2129.lpc2194.lpc2292.lpc2294.pdf
..but to me setting things such as the VICVectCntl Registers, etc are quite ambiguous.
I have also been perusing these forums in the attempt to find a simple and easy to understand example. However, all I have found are extremely complicated (to my eyes) UART programs that set up the VIC registers.
Here is how I have set up my timers:
// Set pclk to 30 MHz VPBDIV = 0x00000002; // Load prescaler for 1 u_sec tick for timer 0 T0PR = 0x1E; // Load prescaler for 1 u_sec tick for timer 1 T1PR = 0x1E; // Enable match register 0 to reset on match for timer 0 T0MCR = 0x03; // Enable match register 0 to reset on match for timer 1 T1MCR = 0x03; // Initialize match register 0 value for timer 0 // 0x2710 - 0.01 s T0MR0 = 0x2710; // Initialize match register 0 value for timer 1 // 0x3E8 - 1.0 milisecond T1MR0 = 0x3E8; // enable timer 1 T1TCR = 0x01;
And here is what I tried for my VIC registers:
VICIntSelect = 0x00000000; // set vectored interrupt controller for timer0 VICVectAddr0 = (unsigned long) timer_handler; VICVectCntl0 = 0x24; // set vectored interrupt controller for timer1 VICVectAddr1 = (unsigned long) ssr_handler; VICVectCntl1 = 0x25; VICIntEnable = 0x30;
And here are my two irqs:
//timer 0 interrupt void timer_handler (void) __irq { // increment hundredths hundredths++; if( hundredths == 100 ) { // increment seconds seconds++; // reset hundredths hundredths = 0; } if( seconds == 60 ) { // increment minutes minutes++; // reset seconds seconds = 0; } if( minutes == 100 ) { // reset minutes minutes = 0; } VICVectAddr=0; // Acknowledge Interrupt } //timer 1 interrupt void ssr_handler (void) __irq { // locals int ssr_test = 0; int ss = 0; int rst = 0; ssr_test = IOPIN2 & 0x00030000; ssr_test = ssr_test >> 16; // determine switch settings ss = ssr_test & 0x01; rst = ssr_test & 0x02; rst = rst >> 1; if( ss == 1 ) { // toggle start_stop_flag if( start_stop_flag == 0 ) { // start enabled start_stop_flag = 1; } else if( start_stop_flag == 1 ) { // stop enabled start_stop_flag = 0; } } if( rst == 1 ) { if( start_stop_flag == 0 ) { // reset if timer is stopped minutes = 0; seconds = 0; hundredths = 0; } } VICVectAddr=0; // Acknowledge Interrupt }
Am I not loading the correct values into the registers? Am I using the right registers? If someone could please help me out, I would be most greatful.
Thank you for all of your time and patience,
Brooks
p.s. In no way am I trying to get someone else to do my project for me. All I want is to know how to set up interrupts in my C programs no matter which device (ADC, PWM, Timers, etc.) I happen to be using. Thanks again for all of your help :-)
Note This message was edited to reduce width.