Hello Friends,
This program i downloaded from keil website.
Its working in KEIL SOFTWARE.
But its not working for PWM4,PWM5 & PWM6.
WHAT'S WRONG IN THIS PROGRAM.
I CHANGED ONLY THE REG SETTINGS AS MENTIONED IN THE USER MANUAL
KINDLY HELP ME TO SOLVE THE PROBLEM
/*********************************************************************
*********/
/* This file is part of the uVision/ARM development
tools */
/* Copyright KEIL ELEKTRONIK GmbH 2002-
2004 */
/*********************************************************************
*********/
/*
*/
/* PWM.C: LED
Flasher */
/*
*/
/*********************************************************************
*********/
#include <LPC21xx.H> /* LPC21xx definitions */
void PWM0_isr(void) __irq
{
PWMIR |= 0x00000001; /* Clear match0 interrupt
*/
VICVectAddr = 0x00000000;
}
void poll_ADC (void) { /* Get ADC Value and set
PWM */
unsigned int cnt;
unsigned int val = 0;
static unsigned int oldval = 0;
// ADCR |= 0x01000000; /* Start A/D Conversion
*/
do {
val = val++;
/* Read A/D Data Register */
} while (val == 50000); /* Wait for end of A/D Conversion */
//ADCR &= ~0x01000000; /* Stop A/D Conversion */
val = (val >> 6) & 0x03FF; /* Extract AIN0 Value */
if ((val != oldval)) {
PWMMR2 = val;
PWMLER = 0x4; /* Enable Shadow latch */
oldval = val;
}
}
void init_PWM (void) {
VICVectAddr8 = (unsigned)PWM0_isr; /* Set the PWM ISR vector
address */
VICVectCntl8 = 0x00000028; /* Set channel */
VICIntEnable = 0x00000100; /* Enable the interrupt */
PINSEL0 |= 0x0002A00A; /* Enable P0.7 and P0.1
as PWM output */
PWMPR = 0x00000000; /* Load prescaler */
PWMPCR = 0x00000C0C; /* PWM channel 2 & 3
double edge control, output enabled */
PWMMCR = 0x00000003; /* On match with timer
reset the counter */
PWMMR0 = 0x400; /* set cycle rate to
sixteen ticks */
PWMMR1 = 0; /* set rising edge of
PWM2 to 100 ticks */
PWMMR2 = 0x200; /* set falling edge of
PWM2 to 200 ticks */
PWMMR3 = 0x400; /* set rising edge of
PWM3 to 100 ticks */
PWMLER = 0xF; /* enable shadow latch
for match 1 - 3 */
PWMEMR = 0x00210A8E; /* Match 1 and Match 2
outputs set high */
PWMTCR = 0x00000002; /* Reset counter and
prescaler */
PWMTCR = 0x00000009; /* enable counter and
PWM, release counter from reset */
}
int main (void) {
unsigned int n;
int rx_char;
// IODIR1 = 0x00FF0000; /* P1.16..23 defined as
Outputs */
// ADCR = 0x01200401; /* Setup A/D: 10-bit
AIN0 @ 3MHz */
init_PWM();
while (1) { /* Loop forever */
poll_ADC();
}
}Message
REG: PWM PROBLEM
2005-03-07 by rockraj_2003
Attachments
- No local attachments were found for this message.