LPC2103 PWM ไม่ออกอ่ะครับ

  • 0 Replies
  • 1670 Views
LPC2103 PWM ไม่ออกอ่ะครับ
« on: March 03, 2013, 08:03:12 pm »
คือว่า ผมใช้ LPC2103 code pwm ที่ ett ให้มามี PWM ให้มา 3 ขา(ett เขา timer 1 ) แต่ผมต้องการใช้อีกเพิ่ม อีก 2 ขา โดยใช้ timer 2 แต่ผมปรับไปใช้ timer 2 แล้ว PWM ผมลองปรับค่าแล้ว แต่มันไม่ได้อ่ะครับ

นี้คือ code ที่ผมเปลี่ยน เองครับ ขา ของ pwm ก็มี่ ขา 7 8 9  กรุณาช่วยดูให้ทีครับผิดตรงไหน

/*****************************************************/
/* Examples Program For "ET-ARM7 BASE LPC2103" Board */
/* Target MCU  : Philips ARM7-LPC2103                */
/*             : X-TAL : 19.6608 MHz                 */
/*             : Run Speed 58.9824MHz (With PLL)     */
/* Keil Editor : uVision3 V3.03a                     */
/* Compiler    : Keil CARM V2.50a                   */
/* Create By   : Eakachai Makarn (WWW.ETT.CO.TH)     */
/* Last Update : 17/April/2006                       */
/* Function    : Example Use Timer1 = PWM Mode       */
/*****************************************************/
// GPIO0.12 -> MAT1.0 = PWM0 = 1.0mS/20mS
// GPIO0.13 -> MAT1.1 = PWM1 = 1.5mS/20mS
// GPIO0.19 -> MAT1.2 = PWM2 = 2.0mS/20mS
// GPIO0.20 -> MAT1.3 = Not Connect = PWM Period Count (20mS)

#include <LPC2103.H>                                       // LPC2103 MPU Register

// Main Program Start Here //
int main(void)

  // Initial Timer1 Pin Connect   
  PINSEL0 &= 0xFFFF3FFF;       // 1111 1111 1111 1111 0011 1111 1111 1111 = Reset P0.7 Function
  PINSEL0 |= 0x00008000;      // 0000 0010 0000 0000 0000 0000 1000 0000
  PINSEL0 &= 0xFFFCFFFF;       // 1111 0011 1111 1111 1111 1111 1111 1111 = Reset P0.8 Function
  PINSEL0 |= 0x00020000;       // 0000 1000 0000 0000 0000 0000 0000 0000 =
 
  PINSEL0 &= 0xFFF3FFFF;      // 1111 1111 1111 1111 1111 1111 1111 1100 = Reset P0.9 Function 

 
  // Initial Timer Operate
  T2TCR   &= 0xFFFFFFFC;      // Timer1 = Timer Mode Count By Rising PCLK Edge   
  T2TC     = 0x00000000;        // Timer Start = 0
  T2PR     = 0x00000000;        // Prescale = 0
  T2PC     = 0x00000000;         // Prescale Count = 0
 
  // Initial Timer1 Match Operate
  T2MCR     &= 0xFFFE;         // Disable Interrupt on Match-0 (1111 1111 1111 111x)
  T2MCR   &= 0xFFFD;         // Disable Reset TC on Match-0   (1111 1111 1111 11x1)
  T2MCR   &= 0xFFFB;         // Disable Stop TC on Match-0   (1111 1111 1111 1x11)
  T2MCR     &= 0xFFF7;         // Disable Interrupt on Match-1   (1111 1111 1111 x111)
  T2MCR   &= 0xFFEF;         // Disable Reset TC on Match-1   (1111 1111 111x 1111)
  T2MCR   &= 0xFFDF;         // Disable Stop TC on Match-1   (1111 1111 11x1 1111)
  T2MCR     &= 0xFFBF;         // Disable Interrupt on Match-2   (1111 1111 1x11 1111)
  T2MCR   &= 0xFF7F;         // Disable Reset TC on Match-2   (1111 1111 x111 1111)
  T2MCR   &= 0xFEFF;         // Disable Stop TC on Match-2    (1111 111x 1111 1111)
  T2MCR     &= 0xFDFF;         // Disable Interrupt on Match-3   (1111 11x1 1111 1111)
  T2MCR   |= 0x0400;         // Enable Reset TC on Match-3   (0000 0x00 0000 0000)
  T2MCR   &= 0xF7FF;         // Disable Stop TC on Match-3    (1111 x111 1111 1111)
   
  // Initial PWM Function
  // Set   Output By Timer Match
  // Reset Output By TC Reset
  T2PWMCON |= 0x00000001;      // Enable MAT1.0 = PWM
  T2PWMCON |= 0x00000002;      // Enable MAT1.1 = PWM
  T2PWMCON |= 0x00000004;      // Enable MAT1.2 = PWM

  // Initial Timer1 Interrupt
  T2IR &= 0xFE;              // Disable MAT0 Interrupt (1111111x)
  T2IR &= 0xFD;              // Disable MAT1 Interrupt (111111x1)
  T2IR &= 0xFB;              // Disable MAT2 Interrupt (11111x11)
  T2IR &= 0xF7;              // Disable MAT3 Interrupt (1111x111)
  T2IR &= 0xEF;              // Disable CAP0 Interrupt (111x1111)
  T2IR &= 0xDF;              // Disable CAP1 Interrupt (11x11111)
  T2IR &= 0xBF;              // Disable CAP2 Interrupt (1x111111)
  T2IR &= 0x7F;              // Disable CAP3 Interrupt (x1111111)

  // Initial PWM Timing
  // Timer Count PCLK (29.4912MHz) 
  // 1 Cycle Timer  = 33.90842 nS
  // -> 20 mS = 589824 Cycle (90000H)
  // -> 1.0mS = 29491.2 Cycle (7333H)
  // -> 1.5mS = 44236.8 Cycle (ACCDH)
  // -> 2.0mS = 58982.4 Cycle (E666H)
  // -> Used MAT1.0 = Count Low Pulse MAT1.0(Set Output on MAT1.0)
  // -> Used MAT1.1 = Count Low Pulse MAT1.1(Set Output on MAT1.1)
  // -> Used MAT1.2 = Count Low Pulse MAT1.2(Set Output on MAT1.2)
  // -> Used MAT1.3 = Count Period of PWM(Reset TC on MATx.3)
  // Reset All Output on TC Start (TC=0)
  // Set Output on MATx.y (TC=MATx.y)
  // Reset TC on MATx.3

  // MAT1.0 Count Low Pulse of PWM0
  // MAT1.1 Count Low Pulse of PWM1
  // MAT1.2 Count Low Pulse of PWM2
  // MAT1.3 Count Period of All PWM
  T2MR0 = 100000;             // MAT1.0 = 0..560332.8 (19.0 mS) = Set Output (PWM 1.0 mS)
  T2MR1 = 589824;            // MAT1.1 = 0..545587.2 (18.5 mS) = Set Output (PWM 1.5 mS)
  T2MR2 = 530842;            // MAT1.2 = 0..530841.6 (18.0 mS) = Set Output (PWM 2.0 mS)
  T2MR3 = 589824;            // MAT1.3 = 0..589824   (20.0 mS) = Reset Output (PWM Period)

  // Initial Timer-1 Control
  T2TCR |= 0x01;            // Timer-1 Enable        (0000000x)
  T2TCR |= 0x02;              // Timer-1 Press Reset    (000000x0)
  T2TCR &= 0xFD;              // Timer-1 Release Reset (111111x1)
   
  // Now GPIO0.12 Generate PWM = 1.0mS
  //     GPIO0.13 Generate PWM = 1.5mS
  //     GPIO0.19 Generate PWM = 2.0mS
  while(1);                  // Loop Continue 

}