Hi could anyone help me with the PWM for the ARM LPC2148, below is my complete code that am trying to implement. At the moment the only part of the of the code that is being run is the initialization of the PWM and then it is enabled in the main function. The PWM is just suppose to run without stopping or interrupting. The code works as desired in the debugger but once I program the chip and check P0.0 pin I get nothing the pin just sits at zero.
Is there something that I'm missing please help.
#include <LPC21XX.H> // LPC21XX Peripheral Registers __irq void PWMISR (void); //Set up prototypes void PWMInit (void); void delay (void);
//End of Declarations********************** /*****************************************/ /*****************************************/ //Main Function**************************** int main (void) {
PWMInit (); //Jump to PWM initialize
PWMTCR = 0x9; // Enable (sart) PWM Note Match registers must be set prior to enable. Turn on Timer counter and Prescaler
while(1) //Infinite loop { } }
/*****************************************/ /*****************************************/ //Start of Timer initialization************ void PWMInit (void) //Timer initialize function { PINSEL0 = 0x2; //Select P0.0 as PWM1
PWMTC = 0x0; //Set the Timer Counter to start counting from zero PWMPR = 0x1; //Maximum value of the Prescaler PWMPC = 0x0; //Sets the prescaler division of the PCLK. Start counting at zero
/* Prescale Counter is incremented on every PCLK. When it reaches the value stored in the PWM Prescale Register, the PWM Timer Counter is incremented and the PWM Prescale Counter is reset on the next PCLK. This causes the PWM TC to increment on every PCLK when PWMPR = 0, every 2 PCLKs when PWMPR = 1, etc. */
PWMMR0 = 0x0FF; //Set the match register PWMMR1 = 0x088; //Set the match register PWMMCR = 0x2; //Reset timer counter on match
PWMPCR = 0x200; //Enable PWM1 output
PWMTCR = 0x02; //Reset Timer Counter PWMIR = 0xFFFF; //Reset all Interrupts flags
VICVectAddr0 = (unsigned long)PWMISR; //Associate the address of timer0 with IRQ0 VICVectCntl0 = 0x20 | 8; //Enable slot 0 and associate it with Timer 0 VICIntEnable = 0x00100; //Enable PWM0 Interrupt } //End of Timer initialization**************
/*****************************************/ /*****************************************/ //Start of Delay*************************** void delay (void) //Delay function { long i = 0; for(i=0;i<1000000;i++); //For loop, does nothing for 100000 cycles } //End of Delay***************************** __irq void PWMISR (void) { // PWMMR0 = 0x03; // PWMLER = 0x01;
VICVectAddr = 0; //Acknoledge the interrupt PWMIR = 0xFFFF; //Reset the interrupts }