Dear all, I am using Realview (evaluation) and have the following program for LPC2148:
#include <LPC214x.h> #define LED 0x01000000 main() { IO1DIR |= LED; //use P1.24 for(;;){ IO1CLR |= LED ; IO1SET |= LED; } }
the crystal is 12M and multiple factor is 5, no VPB setup (i also tried VPBDIV=1). It means the system should run with CPU clock=60Mhz The problem is the LED blinks only with 1 MHz. I tried simulation but the time shown there still indicate that the LED blinks with frequency around 30Mhz. This happen not only with the LED but with any code i put. It seems that my system runs with 2Mhz CPU clock. Does any one have the same problem, please help me. Thanks a lot.
I'm too tired right now to start thinking about if your clock/pll initialization is correct, and if you have activated caching of the flash etc, but one thing my tired brain notices is that you seem to have forgotten the runtime requirements of the for loop.
Even if you think that the two set/clear operations should be a single clock cycle each, that is not the only thing your processor has to do. Unroll the loop a bit by using multiple sets of (IO1CLR |= LED; IO1SET |= LED;) inside the loop and check how much time the loop takes.
Besides, are the physical port direct-mapped into the ARM core, so the pins may be toggled without access delay?
Thank you. But I think the pin and peripheral are not the problem. The LED is just one example. Actually I tried to put more code such as:
while(1) { IO1CLR=LED; CodeTakes5msWith60MHZClock(): IO1SET=LED; CodeTakes5msWith60MHZClock(): }
I expect to have LED blink with the cycle of 10ms but in fact it blinks with much slower cycle, around 200ms-300ms (20 times slower). I also use UART0 and timer 0 and they work with correct timing. I dont use IAP for Flash.
You haven't mentioned if you have enabled the MAM.
I had NOT enabled MAM before. I enabled it and the system works correctly now. Thank you for your useful advices.