Hello,
I am trying to use both timer1 and the microcontroller's external memory on this board. The code I'm currently testing with is below. The problem is that when the external memory is enabled in the makefile, it seems to either disable or interfere with timer1.
With extmem disabled, the PWM output (connected to a motor in this case) works correctly and turns on and off as set by timer1. However enabling extmem in the makefile causes the motor to remain on constantly, seemingly ignoring timer1.
Does the extmem disable or interfere with timer1? Is there another problem or some settings missing?
#include <lpc24xx.h> int main(void) { unsigned int motor_status = 0; T1TCR = 0x02; //Timer Reset T1IR |= 1; //Clear Interrupt Register T1MR0 = 1200000; //Match Value 1 sec T1MCR |= 3; //Reset Counter and Set Interrupt on Match T1TCR = 0x01; //Start timer PINSEL2 |= (3<<6); //Set (P1.3) PWM Pin Configuration PWM0PCR |= (1<<10); //PWM Set To PWM0[2] PWM0MR0 = 120000; //PWM Frequency PWM0MCR |= (1<<1); //Reset Count On Match PWM0MR2 = 120000; //PWM Pulse Width PWM0TCR = 0x00000009; //PWM Start while(1) { if ((T1IR & 1) == 1) { if(motor == 0) { PWM0MR2 = 120000; //Set new speed PWM0LER = (1<<2); //Change to new speed motor = 1; //Motor On } else { PWM0MR2 = 0; //Set new speed PWM0LER = (1<<2); //Change to new speed motor = 0; //Motor Off } T1IR |= 1; //Clear timer0 interrupt flag } } }
Thanks, Joe
Sorry I should have explained better that this is an assignment I've been given. I'm compiling using Notepad++ and have been provided with a makefile. Within the makefile I've been instructed to only change the filename (for compiling the hexfile) and to select whether to use the external memory or not. Oddly many others have been manage to do this without issue but for some reason timer1/counter1 keeps giving me issues when combined with the external memory. I originally thought the issue was with the display, see here: http://www.keil.com/forum/60599/. The interfaces don't share any commong pins.
It's my understanding that timer1 is used in the initialization of the display. The reason we've been given the option of enabling the extmem or not is because the expansion board attached to the LPC2478 has LEDs that can only be used when the display/extmem is disabled.
Depending on whether extmem is selected or not, 1 buildfile and 3 startup files are chosen (different files depending on extmem = 1). I've not been told to modify these and as others have managed to get this to work I'm expected to think that this can't be the issue, but as I've tried everything else I can, I can only think it could be.
Sorry to correct myself. I can see now that in the initialization of the external memory, Timer1 is used:
void mdelay(unsigned long ms) { /* * setup timer #1 for delay */ T1TCR = 0x02; //stop and reset timer T1PR = 0x00; //set prescaler to zero T1MR0 = ms * (Fpclk / 1000); T1IR = 0xff; //reset all interrrupt flags T1MCR = 0x04; //stop timer on match T1TCR = 0x01; //start timer //wait until delay time has elapsed while(T1TCR & 0x01) ; }