We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
here is my code..is it correct.if wrong plz help me to generate pulse of 10khz .
#include <LPC21xx.H>
void T0isr(void)__irq;
void delay(void) { VPBDIV = 0x00000002; //Set pclk to 30 Mhz PINSEL0 = 0x00000020; //Enable pin 0.2 as capture channel0 T0PR = 0x0000001E; //Load prescaler for 1 Msec tick T0TCR = 0x00000002; //Reset counter and prescaler T0CCR = 0x00000005; //Capture on rising edge of channel0 T0TCR = 0x00000001; //enable timer
VICVectAddr4 = (unsigned)T0isr; //Set the timer ISR vector address VICVectCntl4 = 0x00000024; //Set channel VICIntEnable = 0x00000010; //Enable the interrupt } int main(void) { IODIR0=0X000000001;
while(1) { IOSET0=0X00000001; delay(); IOCLR0=0X00000001; delay();
} }
void T0isr (void)__irq { //static int value; //value = T0CR0; // read the capture value T0IR |= 0x00000001; //Clear match 0 interrupt VICVectAddr = 0x00000000; //Dummy write to signal end of interrupt
}
T0PR = 0x0000001E; //Load prescaler for 1 Msec tick
Why did you hardcode the value? 0x1E = 30, and you had 30MHz input frequency. Didn't you think 30MHz/1MHz would be more readable?
And next thing - did you read the text in the datasheet about the T0PR register? Did you then follow up by looking at the example timing diagrams? You sure you should divide by 30?
Next thing - when you have prescaled down 30MHz to 1MHz you still wanted 10kHz pulse. How? And how do you think two calls to delay() helps you? You seen any code somewhere that makes the processor actually stop and wait into delay() until the required time have passed?
Finally - do consider following the posting instructions for source code. There are probably lots of errors in the code that no one will spot because no one will care to read garbled code.