// ***********************************************************************
// Program - PWM Blinky
// Description - Blink Somy Board LED PIO0_8 using PWM
// Build - 2013.08.08.02
// Date - 2013aug09hkt1259
// Author - TL Fong (fongmcu.blogspot.hk, tlfong01hongkong@google.com)
// Hardware - NXP ARM Cortex M0 LPC1114FBD48/302
// IDE - MDK-Lite/uVision 4.71, CoLinkEx 1.1, Flash Magic v7.51
// References -
// 1. UM10398 LPC111x/LPC11Cxx User manual R12 2012sep24
// 2. LPC11xx.h CMSIS Cortex-M0 Core Peripheral Access Layer Header File
// for NXP LPC11xx/LPC11Cxx V1.10 2010nov24
// Notes -
// 1. PWM pin configuration
// PIO0_8/MISO0/CT16B0_MAT0 = Somy LPC1114 Eval Board P4 Pin 3
// ***********************************************************************
void testXiaBoardPwmBlinky03()
{
// Enable System AHB clock for CT16B0 timer (Table 21 bit 7 CT16B0)
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7); // CT16B0 = 1 enables CT16B0
// Set function of PIO0_8 pin (UM10398 Table 79 bits 2:0 FUNC)
LPC_IOCON->PIO0_8 &= ~0x7; // FUNC = 0x2 selects function
LPC_IOCON->PIO0_8 |= 0x2; // CT16B0_MAT0
// Set PWM mode for CT16B0_MAT0 (Table 293 bit 0 PWMEN0, bit3 PWMEN3)
LPC_TMR16B0->PWMC |= 0x9; // PWMENO, PWMEN3 = 1 enables MR0, MR3
// Set External Match Register (Tables 290, 291)
LPC_TMR16B0->EMR = (0x3 | 0x1); // bits 4, 5 = 11 toggle, bit 0 = 1 ?
// Resets timer counter on a match (Table 286 bit 10 MR3R)
LPC_TMR16B0->MCR |= 0x400; // MR3R = 1 resets counter on MR3 match
// Set prescale 12000 count of AHB clock = 240 uS (Table 279 TMR16B0PR)
LPC_TMR16B0->PR = 12000; // (1/(50,000,000/2) x 12000 = 240 uS
// Set cycle length (Table 279 TMR16B0MR3, Figure 68)
LPC_TMR16B0->MR3 = 4000; // 240uS x 4000 = 0.96 == 1 second
// Set duty cycle (Table 279 TMR16B0MR0, Figure 68)
LPC_TMR16B0->MR0 = 2000; // 240uS x 2000 == 0.5 second (50% duty cycle)
// Start timer (Table 279 TMR16B0CTCR bit0 CEn)
LPC_TMR16B0->TCR |= 0x1; // CEn = 1 enables timer
while (1)
{
// loop forever
}
}
void testXiaBoardPwmBlinky04()
{
/* Enable the clock for CT16B0 */
LPC_SYSCON->SYSAHBCLKCTRL |= 0x00000080;
/* Configure PIO0.8 as Timer1_16 MAT0 Output */
LPC_IOCON->PIO0_8 &= ~0x00000007;
LPC_IOCON->PIO0_8 |= 0x00000002;
// Set prescale 12000 count of AHB clock = 240 uS (Table 279 TMR16B0PR)
LPC_TMR16B0->PR = 12000; // (1/(50,000,000/2) x 12000 = 240 uS
// Set cycle length (Table 279 TMR16B0MR3, Figure 68)
LPC_TMR16B0->MR3 = 4000; // 240uS x 4000 = 0.96 == 1 second
// Set duty cycle (Table 279 TMR16B0MR0, Figure 68)
LPC_TMR16B0->MR0 = 2000; // 240uS x 2000 == 0.5 second (50% duty cycle)
/* Configure match control register to reset on MR3 */
LPC_TMR16B0->MCR = 0x00000400;
/* External Match Register Settings for PWM */
LPC_TMR16B0->EMR = 0x00000030 | 0x00000001;
/* Enable PWM0 and PWM3 */
LPC_TMR16B0->PWMC = 0x00000001 | 0x00000008;
/* Enable Timer1 */
LPC_TMR16B0->TCR = 0x00000001;
while (1)
{
// loop forever
}
}
void testXiaBoardDelayBlinky02()
{
testXiaBoardBlinky01(Led1, TwoTimes);
testXiaBoardBlinky01(Led2, TwoTimes);
testXiaBoardBlinky01(Led3, TwoTimes);
testXiaBoardBlinky01(Led4, TwoTimes);
testXiaBoardBlinky01(Led5, TwoTimes);
}
void testXiaBoardPwmBlinky()
{
initializeXiaBoard01();
testXiaBoardDelayBlinky02(); // Blink Somy Board's 4 LEDs + PIO0_8 LED (OK)
// testXiaBoardPwmBlinky03(); // Blink Somy Board PIO0_8 LED (Not working!!!)
testXiaBoardPwmBlinky04(); // Blink Somy Board PIO0_8 LED (Not working!!!)
}
// ***********************************************************************
// Main Function
// ***********************************************************************
int main()
{
testXiaBoardPwmBlinky();
}
// ***********************************************************************
// End of Program
// ***********************************************************************
// .END
No comments:
Post a Comment