// Program - PWM Blinky
// Description - Blink Somy Board LED PIO0_8 using PWM
// Build - 2013.08.10.05
// Date - 2013aug10hkt1532
// Author - TL Fong
// Reference - MIT 6.01SC Intro EE&CS1, <http://ocw.mit.edu/6-01SCS11>
// License - Creative Commons BY-NC-SA <http://ocw.mit.edu/terms/>
// Hardware - NXP ARM Cortex M0 LPC1114FBD48/302 (Somy Eval Board)
// IDE - MDK-Lite/uVision 4.71, CoLinkEx 1.1, Flash Magic v7.51
// Manuals -
// 1. UM10398 LPC111x/LPC11Cxx User manual R12 2012sep24 Chapter 18
// 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 testXiaBoardPwmBlinky05()
{
// Enable System AHB clock for CT16B0 timer (Table 21 bit 7 CT16B0)
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7); // CT16B0 = 1 enables CT16B0
// Enable System AHB clock for IOCON block (Table 21 bit 16 IOCON)
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 16); // IOCON = 1 enable clk for IOCON
// Set function of PIO0_8 pin (UM10398 Table 79 bits 2:0 FUNC)
LPC_IOCON->PIO0_8 &= ~0x7; // FUNC = 0x2 selects function of
LPC_IOCON->PIO0_8 |= 0x2; // CT16B0_MAT0
// Set PWM mode for CT16B0_MAT0,3 (Table 293 bit 0 PWMEN0, bit3 PWMEN3)
LPC_TMR16B0->PWMC |= 0x9; // PWMENO & PWMEN3 = 1 enable MR0, MR3
// Set External Match Register (Tables 290, 291) // not sure about this
LPC_TMR16B0->EMR = (0x3 | 0x1); // bits 4, 5 = 11 toggle, bit 0 = 1
// Resets timer counter on MR3 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 testXiaBoardDelayBlinky02()
{
testXiaBoardBlinky01(Led1, OneTime); // Port 1, Pin 8
testXiaBoardBlinky01(Led2, OneTime); // Port 2, Pin 7
testXiaBoardBlinky01(Led3, OneTime); // Port 2, Pin 8
testXiaBoardBlinky01(Led4, OneTime); // Port 2, Pin 5
testXiaBoardBlinky01(Led5, OneTime); // Port 0, Pin 8
}
void testXiaBoardPwmBlinky04()
{
initializeXiaBoard01();
testXiaBoardDelayBlinky02(); // delay blink
testXiaBoardPwmBlinky05(); // pwm blink
}
// ***********************************************************************
// Main Function
// ***********************************************************************
int main()
{
testXiaBoardPwmBlinky04(); // blinks Led 1 to 5 once, then 5 non stop
}
// ***********************************************************************
// End of Program
// ***********************************************************************
// .END
No comments:
Post a Comment