PWM function debugging notes

// *** Xia Board Tests ***

// ***********************************************************************
// 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 testXiaBoardPwmBlinky02()
{
  // 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 

  // Enable System AHB clock for CT16B0 timer (Table 21 bit 7 CT16B0)
  LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7); // CT16B0 = 1 enables CT16B0
                
  // Set PWM mode for CT16B0_MAT0 (Table 293 bit 0 PWMEN0, bit3 PWMEN3)
  LPC_TMR16B0->PWMC |= 0x9; // PWMENO, PWMEN3 = 1 enables MR0, MR3

  // Resets timer counter on a match (Table 286 bit 10 MR3R)
  LPC_TMR16B0->MCR |= (1 << 10); // 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, 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)
testXiaBoardPwmBlinky02();   // Blink Somy Board PIO0_8 LED (Not working!!!)
}

// ***********************************************************************
// Main Function
// ***********************************************************************

int main()
{  
testXiaBoardPwmBlinky();
}

// ***********************************************************************
// End of Program
// ***********************************************************************

// .END 

No comments:

Post a Comment