Hi all
I am working on single edge PWM generation on LPC 2129 .The summary o my work is as below
1)I am able to see PWM output on Pin 33(PWM 4).it is as per my clock settings.No problem still here.
2)In the PWM ISR,I am setting 2 flags and in the main loop of the code ,and based on these flag values I am dynamically changing PWM4 rate by changing PWMMR0 ;PWMMR4 PWMLER registers.
3)These above mentioned changes are not reflected in the scope output.I dont see my modified rate settings on the scope.
Please help me.
Regards
Anand
nt main(void)
{
systemInit(); // PLL, MAM etc.
gpioInit();
enableIRQ();
init_PWM();
while (1) { /* Loop forever */
if (count10flag == 1) // count10flag Updated in ISR
{
count10flag = 0;
PWMMR4 = 500;
PWMLER = 0x0;
PWMLER = 0x7f;
//PWMTCR = 0x09; // Counter Enable, PWM Mode Enabled(bit0, bit3)
}
else if (count20flag == 1) // count20flag Updated in ISR
{
count20flag = 0;
PWMMR4 = 1500;
PWMLER = 0x0;
PWMLER = 0x7f;
}
;
}
return 0; /* never reached */
}
pwm.c
unsigned char ISRflag=0;
//void PWM0_isr (void) attribute ((interrupt(“IRQ”)));
//void uart2_isr (void) attribute ((interrupt(“IRQ”)));
void PWM0_isr (void) attribute ((naked));
static int count = 0;
int count10flag = 0;
int count20flag = 0;
void PWM0_isr (void)
{
ISR_ENTRY();
PWMIR |= 0x00000001; /* Clear match0 interrupt */
VICVectAddr = 0x00000000;
count++;
if (count == 10) //LED Blinks at every 4 * 10 = 40 seconds
{
IOSET1 = LED3BITY; // enable LED3
count10flag = 1;
}
else if (count == 20)//LED Blinks off at every 4 * 10 = 40 seconds
{
IOCLR1 = LED3BITY; // disable LED3
count = 0;
count20flag = 1;
}
ISR_EXIT();
}
void init_PWM (void) {
VICIntSelect = 0x00000000;
VICIntEnable = 0x00000100; /* Enable the interrupt */
VICVectCntl8 = 0x00000028; /* Set channel */
VICVectAddr8 = (unsigned)(void )PWM0_isr; / Set the PWM ISR vector address */
PINSEL0 |= 0x00020000; // Change GPIO P0.8 to PWM4
PWMPR = 23999;// Set Pre Scale to 23999 -Here formula is given by Delay = (Y/(X*10^6)) .Here if Pclk = 24 Mhz then X = 24 And here we want a delay of 1 ms
// therefore Y = 24000 (1ms *24 Mhz) = 23999+1;Therefore Pr = 23999 which gives 24000 / 24 Mhz = 1ms;
PWMPCR = 0x00001000; // Enable PWM4 Output (bit12)
// 1 tick = 1ms;
PWMMR0 = 4000;// Max Value of Pulse Width for 4000 ticks — total pulse width at PWM4 pin no 33 = 4 seconds (4000 * 1ms))
PWMMR4 = 2500;// PWM4 Match Value for 2500 ticks pulse width at PWM4 pin no 33 = 2.5 seconds (2500 * 1ms).
PWMMCR = 0x00000003; // Reset PWMTC and interrupt PWMMTC when Matched with PWMMR0
PWMLER = 0x7F; // Latch in all PWMMMR’s
PWMTCR = 0x02; // Reset PWMMTC, (bit1)
PWMTCR = 0x09; // Counter Enable, PWM Mode Enabled(bit0, bit3)
}