Forums

ADC & PWM

Started by Ravi April 6, 2008
Hi all

CPU=LPC2148
crystal = 12 Mhz
PLL = 4
Following pgm I wrote to get PWM freq 1.2 Khz, but it is generating
1.5 Khz, with correct duty cycle of 50%.
I want ADC should start conversion after start of each PWM cycle
(after matching MR0)
but when I measure freq across LED I get 750 Hz with duty cycle 50%
Can anyone help me
Thanx in advance
int main (void)
{
VPBDIV = 0x00000004; //Set the Pclk to 12 Mhz (crystal*4)/4
PINSEL0= 0x00020002; //Enable pin port0.0 as PWM1 & PWM4
IODIR0 = 0x000E0000;//set as output for LED(three connected)

PWMPR = 0x000003E8; // Load prescaler Pclk/1000 = 12 Khz
PWMPCR = 0x00001200; //Enable single edge controlled PWM1,4
PWMMCR = 0x00000003; //Reset Timer on MR0 match
PWMMR0 = 0x0000000A; // set cycle rate to 1.2 Khz
PWMMR4 = 0x00000005; //duty cyce 50%
PWMTCR = 0x00000002;
PWMTCR = 0x00000009;

AD1CR = 0x00200C20;//AD1.5, Burst=0, 10 bit software controlled
VICVectCntl1 = 0x00000035; //Connect AD1 to slot 1
VICVectAddr1 = (unsigned)ADCIRQ;

VICVectCntl0 = 0x00000028;
VICVectAddr0 = (unsigned)PWMIRQ;
VICIntEnable = 0x00200100; // Enable PWM & AD1 interrupt
AD1CR |= 0x01000000;//Start ADC
while(1);

return 0;
}

void PWMIRQ(void)
{
PWMIR = 0x00000001; //Reset interrupt
AD1CR |= 0x01000000;//Start ADC
VICVectAddr = 0x00000000;
}

void ADCIRQ(void)
{
if(flag == 0)
{
IOSET0 = 0x000E0000;//LED ON
flag = 1;
}
else
{
IOCLR0 = 0x000E0000;//LED OFF
flag = 0;
}
AD1CR &= 0xF8FFFFFF;//Stop ADC
VICVectAddr = 0x00000000;
}


An Engineer's Guide to the LPC2100 Series