MiniMax (25.01.2007 00:21, просмотров: 1) ответил Nikolas на Подскажите, кто пользовал PWM у LPC2xxx.
Это мой рабочий пример для LPC2138 и GNU ARM GCC void InitPWM()
{
/* Initialize PWM2/4/6*/
PINSEL0 &= (~(1UL<<14));
PINSEL0 |= (1UL<<15); // Enable PWM2
PINSEL0 &= (~(1UL<<16));
PINSEL0 |= (1UL<<17); // Enable PWM4
PINSEL0 &= (~(1UL<<18));
PINSEL0 |= (1UL<<19); // Enable PWM6
PWMPR = 0x1; //Load prescaler
PWMPCR = 0x5400; //PWM channels 2,4,6, single edge control, output enabled
PWMMCR = 1; //On match with timer reset the counter
PWMMR0 = 0x0FFF; //set cycle rate
PWMMR2 = 0; //set init value
PWMMR4 = 0; //set init value
PWMMR6 = 0; //set init value
PWMLER = 0x55; //enable shadow latch for match 2,4,6
PWMTCR = 0x02; //Reset counter and prescaler
PWMTCR = 0x09; //Enable counter and PWM, release counter from reset
}
//
...
PWMMR2 = value;
PWMLER = (1<<2); //set latch to update PWM register next cycle
...
PWMMR4 = value;
PWMLER = (1<<4); //set latch to update PWM register next cycle
...
PWMMR6 = value;
PWMLER = (1<<6); //set latch to update PWM register next cycle