Example LPC1114 in LPC 11U14

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Example LPC1114 in LPC 11U14

482 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bruno on Thu Apr 26 11:51:51 MST 2012
******************************************************************************
** Function name:init_timer
**
** Descriptions:Initialize timer, set timer interval, reset timer,
**install timer interrupt handler
**
** parameters:timer number and timer interval
** Returned value:None
** 
******************************************************************************/
void init_timer32(uint8_t timer_num, uint32_t TimerInterval) 
{
  if ( timer_num == 0 )
  {
    /* Some of the I/O pins need to be carefully planned if
    you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9);
    LPC_IOCON->PIO1_28 &= ~0x07;/*  Timer0_32 I/O config */
    LPC_IOCON->PIO1_28 |= 0x02;/* Timer0_32 CAP0 */
    LPC_IOCON->PIO1_24 &= ~0x07;
    LPC_IOCON->PIO1_24 |= 0x02;/* Timer0_32 MAT0 */
    LPC_IOCON->PIO1_25 &= ~0x07;
    LPC_IOCON->PIO1_25 |= 0x02;/* Timer0_32 MAT1 */
    LPC_IOCON->PIO1_26 &= ~0x07;
    LPC_IOCON->PIO1_26|= 0x02;/* Timer0_32 MAT2 */
#ifdef __JTAG_DISABLED
    LPC_IOCON->PIO1_27 &= ~0x07;
    LPC_IOCON->PIO1_27 |= 0x03;/* Timer0_32 MAT3 */
#endif
#if CONFIG_TIMER32_DEFAULT_TIMER32_0_IRQHANDLER==1
    timer32_0_counter = 0;
    timer32_0_capture = 0;
#endif //TIMER32_0_DEFAULT_HANDLER
    LPC_CT32B0->MR0 = TimerInterval;
#if TIMER_MATCH
    LPC_CT32B0->EMR &= ~(0xFF<<4);
    LPC_CT32B0->EMR |= ((0x3<<4)|(0x3<<6)|(0x3<<8)|(0x3<<10));/* MR0/1/2/3 Toggle */
#else
/* Capture 0 on rising edge, interrupt enable. */
LPC_CT32B0->CCR = (0x1<<0)|(0x1<<2);
#endif
LPC_CT32B0->MCR = 3;/* Interrupt and Reset on MR0 */

#if CONFIG_TIMER32_DEFAULT_TIMER32_0_IRQHANDLER==1
    /* Enable the TIMER0 Interrupt */
    NVIC_EnableIRQ(TIMER_32_0_IRQn);
#endif
  }
  else if ( timer_num == 1 )
  {
    /* Some of the I/O pins need to be clearfully planned if
    you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<10);
#ifdef __JTAG_DISABLED
    LPC_IOCON->TMS_PIO0_12  &= ~0x07;/*  Timer1_32 I/O config */
    LPC_IOCON->TMS_PIO0_12  |= 0x03;/* Timer1_32 CAP0 */
    LPC_IOCON->TDO_PIO0_13  &= ~0x07;
    LPC_IOCON->TDO_PIO0_13  |= 0x03;/* Timer1_32 MAT0 */
    LPC_IOCON->TRST_PIO0_14 &= ~0x07;
    LPC_IOCON->TRST_PIO0_14 |= 0x03;/* Timer1_32 MAT1 */
    LPC_IOCON->SWDIO_PIO0_15  &= ~0x07;
    LPC_IOCON->SWDIO_PIO0_15  |= 0x03;/* Timer1_32 MAT2 */
#endif
    LPC_IOCON->PIO1_27 &= ~0x07;
    LPC_IOCON->PIO1_27 |= 0x02;/* Timer0_32 MAT3 */

#if CONFIG_TIMER32_DEFAULT_TIMER32_1_IRQHANDLER==1
    timer32_1_counter = 0;
    timer32_1_capture = 0;
#endif //TIMER32_1_DEFAULT_HANDLER

    LPC_CT32B1->MR0 = TimerInterval;
#if TIMER_MATCH
    LPC_CT32B1->EMR &= ~(0xFF<<4);
    LPC_CT32B1->EMR |= ((0x3<<4)|(0x3<<6)|(0x3<<8)|(0x3<<10));/* MR0/1/2 Toggle */
#else
/* Capture 0 on rising edge, interrupt enable. */
    LPC_CT32B1->CCR = (0x1<<0)|(0x1<<2);
#endif
    LPC_CT32B1->MCR = 3;/* Interrupt and Reset on MR0 */

#if CONFIG_TIMER32_DEFAULT_TIMER32_1_IRQHANDLER==1
    /* Enable the TIMER1 Interrupt */
    NVIC_EnableIRQ(TIMER_32_1_IRQn);
#endif
  }
  return;
}
/******************************************************************************
** Function name:init_timer32PWM
**
** Descriptions:Initialize timer as PWM
**
** parameters:timer number, period and match enable:
**match_enable[0] = PWM for MAT0 
**match_enable[1] = PWM for MAT1
**match_enable[2] = PWM for MAT2
**
** Returned value:None
** 
******************************************************************************/
void init_timer32PWM(uint8_t timer_num, uint32_t period, uint8_t match_enable)
{

disable_timer32(timer_num);
if (timer_num == 1)
{
    /* Some of the I/O pins need to be clearfully planned if
    you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<10);

/* Setup the external match register */
    LPC_CT32B1->EMR = (1<<EMC3)|(1<<EMC2)|(2<<EMC1)|(1<<EMC0)|(1<<3)|(match_enable);

/* Setup the outputs */
/* If match0 is enabled, set the output */
if (match_enable & 0x01)
{
  LPC_IOCON->TDO_PIO0_13  &= ~0x07;
  LPC_IOCON->TDO_PIO0_13  |= 0x03;/* Timer1_32 MAT0 */
}
/* If match1 is enabled, set the output */
if (match_enable & 0x02)
{
  LPC_IOCON->TRST_PIO0_14 &= ~0x07;
  LPC_IOCON->TRST_PIO0_14 |= 0x03;/* Timer1_32 MAT1 */
}
/* If match2 is enabled, set the output */
if (match_enable & 0x04)
{
  LPC_IOCON->SWDIO_PIO0_15   &= ~0x07;
  LPC_IOCON->SWDIO_PIO0_15   |= 0x03;/* Timer1_32 MAT2 */
}
/* If match3 is enabled, set the output */
if (match_enable & 0x08)
{
  LPC_IOCON->PIO0_16         &= ~0x07;
  LPC_IOCON->PIO0_16           |= 0x02;/* Timer1_32 MAT3 */
}

#ifdef __JTAG_DISABLED
  PIO1_0_JTAG_TMS  &= ~0x07;/*  Timer1_32 I/O config */
  PIO1_0_JTAG_TMS  |= 0x03;/* Timer1_32 CAP0 */
#endif

/* Enable the selected PWMs and enable Match3 */
LPC_CT32B1->PWMC = (1<<3)|(match_enable);
 
/* Setup the match registers */
/* set the period value to a global variable */
timer32_1_period = period;
LPC_CT32B1->MR3 = timer32_1_period;
LPC_CT32B1->MR0= timer32_1_period/2;
LPC_CT32B1->MR1= timer32_1_period/2;
LPC_CT32B1->MR2= timer32_1_period/2;

/* */
LPC_CT32B1->MCR = 1<<10;/* Reset on MR3 */
}
else
{
    /* Some of the I/O pins need to be clearfully planned if
    you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9);

/* Setup the external match register */
    LPC_CT32B0->EMR = (1<<EMC3)|(2<<EMC2)|(1<<EMC1)|(1<<EMC0)|(1<<3)|(match_enable);
 
/* Setup the outputs */
/* If match0 is enabled, set the output */
if (match_enable & 0x01)
{
 LPC_IOCON->PIO1_24           &= ~0x07;
  LPC_IOCON->PIO1_24           |= 0x02;/* Timer0_32 MAT0 */
}
/* If match1 is enabled, set the output */
if (match_enable & 0x02)
{
LPC_IOCON-> PIO1_25           &= ~0x07;
  LPC_IOCON-> PIO1_25           |= 0x02;/* Timer0_32 MAT1 */
}
/* If match2 is enabled, set the output */
if (match_enable & 0x04)
{
  LPC_IOCON->PIO1_26           &= ~0x07;
  LPC_IOCON->PIO1_26           |= 0x02;/* Timer0_32 MAT2 */
}
/* If match3 is enabled, set the output */
if (match_enable & 0x08)
{
  LPC_IOCON->PIO1_27 &= ~0x07;
  LPC_IOCON->PIO1_27 |= 0x03;/* Timer0_32 MAT3 */
}

/* Enable the selected PWMs and enable Match3 */
LPC_CT32B0->PWMC = (1<<3)|(match_enable);

/* Setup the match registers */
/* set the period value to a global variable */
timer32_0_period = period;
LPC_CT32B0->MR3 = timer32_0_period;
LPC_CT32B0->MR0= timer32_0_period;///2;
LPC_CT32B0->MR1= timer32_0_period/2;
LPC_CT32B0->MR2= timer32_0_period/2;

LPC_CT32B0->MCR = 1<<10;/* Reset on MR3 */
}


}

I modified the file for LPC 11U14, but it  not works.
What could be wrong?
0 Kudos
2 Replies

360 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Fri Apr 27 13:01:40 MST 2012
The LPC11U actually has a number of differences from the original LPC11 family. Thus you might  do better looking at some example code specifically for this family, rather than starting from LPC11 examples.

The current LPC11U examples shipped with LPCXpresso are fairly limited. However NXP do have a sample code bundle for LPC11Uxx peripherals available from:

http://www.lpcware.com/gfiles/all?tid_1[]=128&tid_2[]=8

Porting this code into LPCXpresso IDE should be fairly straightforward. Some notes that may be useful in doing this can be found here:

http://support.code-red-tech.com/CodeRedWiki/PortingCodeOtherToolchains

Regards,
CodeRedSupport
0 Kudos

360 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Thu Apr 26 23:30:41 MST 2012
@Bruno........Hi..!!!

Are you using the exact right code for your Emulator...!!! Just Recheck.
And what exact error are you getting..!!
Can you share the .TXT document for this project if it is a sample code, so that I can look in to this application.
Or, Share the whole main.c file's code so that I can track on it.


Thanks & Regards.....:)
0 Kudos