This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PROBLEM IN PWM PULSES IN ARM LPC2148

HI EVRYBODY,,, i am new to arm.i m getting pwm 3 pulses at the respected pin no on cro. Now i want to use pwm 1 to pwm 6 at the same time. But not getting how to generate all the pwm pulses. Can antbody suggest how to do it? or modification in following code. the below code is work only for pwm3.

plz help

#include <LPC214X.H> // LPC21XX Peripheral Registers

void __irq PWMISR(void);
void PWMInit (void);
void delay (void);

//End of Declarations**********************
/*****************************************/
/*****************************************/
//Main Function****************************
int main (void)
{

PINSEL0 = 0x8; //Select P0.1 as PWM3 IO1DIR = (1<<19) | (1<<18) | (1<<17) | (1<<16); PINSEL2 = 0x00000000;

PWMInit (); //Jump to PWM initialize

while(1) //Infinite loop {

}
}

/*****************************************/
/*****************************************/
//Start of Timer initialization************

void PWMInit (void) //Timer initialize function
{

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. */

//PWMMCR = 0x00000003;//On match with timer reset the counter PWMMCR = 0x00000600;//On match with timer reset the counter

//PWMMR0 = 0x0ff; //Set the match register PWMMR1 = 0x088; //Set the match register PWMMCR = 0x2; //Reset timer counter on match

PWMMR3 = 0x000f;//0x0ff; //Set the match register PWMMR1 = 0x088; //Set the match register PWMMCR = 0x2; //Reset timer counter on match

//PWMPCR = 0x001; //Enable PWM1 output //PWMPCR = 0x008; //Enable PWM3 output //PWMPR = 0x00000001; //Load prescaler //PWMPR = 0x00000001; //Load prescaler PWMPR = 0x00000008;//0x00000008; //Load prescaler

PWMTCR = 0x00000002;//Reset counter and prescaler //PWMTCR = 0x00000009;//enable counter and PWM, // release counter from reset PWMTCR = 0x00000009;//enable counter and PWM, //release counter from reset

//PWMLER = 0x08; //PWMPCR = 0X0100; PWMPCR = 0X0800;

PWMTCR = 0x9; // Enable (sart) PWM Note Match registers must be set prior to enable. Turn on Timer counter and Prescaler

PWMLER = 0x08;

VICIntSelect = 0x00000000; // Setting all interrupts as IRQ(Vectored) VICVectCntl0 = 0x20 | 8;//9; // Assigning Highest Priority Slot to I2C0 and enabling this slot

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

VICIntEnable = (1<<8);

}

//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)
void __irq PWMISR(void)
{ PWMTCR = 0x00000002;//Reset counter and prescaler

PWMTCR = 0x9; // Enable (sart) PWM Note Match registers must be set prior to enable. Turn on Timer counter and Prescaler

test++; PWMIR = 0x08; VICVectAddr = 0; //Acknoledge the interrupt PWMIR = 0xFFFF; //Reset the interrupts
}

Parents
  • thnaks for ur rply...

    So what issues do you see getting more outputs working? Have you read the description and register specifications for the PWM in the processor user manual?

    yeah i have read the mannual but still not getting for multiple pwm pulses at a time...

    i have enbale all the respected registers list for all pwm pulses. So i have to get the pulses at respected line if the code is working for single pwm pulse. but after including registers for all pwm pulses i m not able to get a single pulse at the respected pin.

    if i m nt understanding where i m going wrng? what precaution i have to take for geneartingg all pwm pulses at the same time? or any registers affects on the generation of pwm pulses?

    plz let me know....

Reply
  • thnaks for ur rply...

    So what issues do you see getting more outputs working? Have you read the description and register specifications for the PWM in the processor user manual?

    yeah i have read the mannual but still not getting for multiple pwm pulses at a time...

    i have enbale all the respected registers list for all pwm pulses. So i have to get the pulses at respected line if the code is working for single pwm pulse. but after including registers for all pwm pulses i m not able to get a single pulse at the respected pin.

    if i m nt understanding where i m going wrng? what precaution i have to take for geneartingg all pwm pulses at the same time? or any registers affects on the generation of pwm pulses?

    plz let me know....

Children
  • nobody is there who will guide me?

  • In order to output PWM signals you have to select the PWM function for all the pins involved

    /*
        P0.0:  PWM1 (Pulse Width Modulator output 1)
        P0.1:  PWM3 (Pulse Width Modulator output 3)
        P0.7:  PWM2 (Pulse Width Modulator output 2)
        P0.8:  PWM4 (Pulse Width Modulator output 4)
        P0.9:  PWM6 (Pulse Width Modulator output 6)
        P0.21:  PWM5 (Pulse Width Modulator output 5)
    */
    
    
        PINSEL0 = 0x000A800A;     /* binary: 00000000_00001010_10000000_00001010 */
        PINSEL1 = 0x00000400;     /* binary: 00000000_00000000_00000100_00000000 */
    
    

    Alex