Hi guys...I'm a newbie in ARM7 programming.I have a readymade hardware board of LPC2148.I'm doing a simple blinking action on it.I'm supplying the processor with 12MHz frequency as its processor clock.And i hve read in net somewhere tht each for loop [for(x=0;x<1;x++)] takes 12-13 cycles to execute.So by rough calculation the value of the delay counter should be 1000000 for 1sec delay.But my delay turns out to be 4-5sec. I have deactivated the MAM block and also PLL0 i.e., I'm using the external supplied oscillator as the clock source for the processor. I havn't used the timer module to get the desired delay till now..as i need to brush up the theories behind it first.But whether it is absolutely necessary to use the timer block to produce the 1sec delay?? plz answer my post some one..thanks in advance.My code is given below --
#include "LPC214x.H" /* Fosc = external supplied crystal frequency Fcclk = Processor clock or o/p of PLL0 Pclk = The VPB clock frquency.The o/p of the VPB driver Fcco = the frequency of the PLL current controlled oscillator */ void init_clock() { /* PLL0CON = 0x03; // PLL0 is enabled & connected as the clock source of the microcontroller PLL0CFG = 0x24; // The i/p crystal oscillator frequency is multiplied in the PLL0 block by a fator of 5(=4+1) PLL0FEED == 0xAA; // 0xAA and 0x55 should be feed into this register for the PLL0FEED == 0x55; // changes in PLL0CON and PLL0CFG to take place actively VPBDIV = 0x01; // The Pclk frequency = Fcclk frequecy..not necessary. // by default the GPIO are selacted as legacy ports */ PLL0CON=0x0; // these 4 lins are as given by blink.c.Though the result is nt coming as expected.the above commented out result are my first try to supply the processor with 60MHz clock supply // the PLL is nt connected as the clock source for the processor PLL0FEED=0xAA; PLL0FEED=0x55; VPBDIV=0x00; MAMCR = 0x00; // Any MAM function is disabled..i.e } void delay() { unsigned long int i; for(i=0;i<250000;i++); } // with 12MHZ clock supply the time delay is cmng as 1sec if the delay value is 250000 but it should be 1000000 according to my calculation // in this void main(void) { unsigned long dword=0x00000000; unsigned char min_hand=0; init_clock(); PINSEL1 &= 0x00000000; // all the pins of port1 are selected as GPIO IODIR1 = 0x00FF0000; // the pin 16 to 23 are configuered as the o/p pins. IOCLR1 = 0xFFFFFFFF; while(1) { min_hand++; dword = dword>>16; dword++; dword = dword <<16; IOSET1 |= dword; // IOPIN1 = IOSET1; delay(); if(min_hand /60 == 0) { min_hand=0; delay(); } IOCLR1 = 0xFFFFFFFF; delay(); } }
The below code has been tested on my LPC2368. And the LED blinks regularly with a 1 second interval.
#include "LPC23xx.h" void delay(void) { /* My PCLK of Timer0 is 18Mhz */ T0PR = 9999; // Prescale Register = 9999 T0MR0 = 900; // Match Register = 900 T0MCR = 0x00000004; // Stop on MR0: the TC and PC will be stopped // and TCR[0] will be set to 0 if MR0 matches the TC. T0TCR = 0x02; // Counter Reset T0TCR = 0x01; // Counter Enable while(T0TC != T0MR0); } int main(void) { FIO3DIR |= (1<<26); // 1 for Output while(1) { FIO3CLR = (1<<26); delay(); FIO3SET = (1<<26); delay(); } }
Thanks for ur help...As my Pclk is 12MHz i have used 1200 as the matched value in T0MR0 register.Else i have put ur code fully in mine,but the result is same as i previously explained here i.e, in short its not working.I have checked the result both in the simulator and in the hardware.
One more question if u have put 9999 in ur PR that means the TC will increase after every 10000 clk cycles..in that case if ur Pclk is 18MHz the value at which the TC register should match with the MR0 register, for 1sec delay, should be 1800...not 900.So how are you getting a 1sec delay..plz clarify this point.
Turn on the LED for 0.5 sec. Turn off the LED for 0.5 sec. Totally 1.0 sec.
Ok I understand,So why doesnt ur code run on my code.whats the problem with it????
Sorry John Linq-----
I'm really sorrry to you John Linq.I was blindly following the simulator...so i didnt actually burned the codes in the hardware.Moreover the last time i burnt there was a problem in my burning software so that didnt worked.
Today i reinstalled the software and burn the code..it worked perfectly.Even my timer delay code that i have given earlier that also worked...i.e., it was my simulator problem which couldnt project the right output.I will remember this in the coming days.So thank you all really thank you...and once again Sorry John Linq..plz dont mind.