Generating variable frequency in LPC11xx

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

Generating variable frequency in LPC11xx

611 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by angiey on Mon Aug 17 00:03:15 MST 2015
Hi all!!

How to generate variable frequency in lpc11xx controller, currently  i'm getting fixed frequency on
pin 27[CT16B0_MAT0] of 96.2hz, but I need to generate a from frequency from 6hz to 20hz.
Below is the part of the code which I have compared:

void init_timer16(uint8_t timer_num, uint32_t TimerInterval) 
{
  if ( timer_num == 0 )
  {
  
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);
    LPC_IOCON->PIO0_2           &= ~0x07;/*  Timer0_16 I/O config */
    LPC_IOCON->PIO0_2           |= 0x02;/* Timer0_16 CAP0 */
    LPC_IOCON->PIO0_8           &= ~0x07;
    LPC_IOCON->PIO0_8           |= 0x02;/* Timer0_16 MAT0 */
    LPC_IOCON->PIO0_9           &= ~0x07;
    LPC_IOCON->PIO0_9           |= 0x02;/* Timer0_16 MAT1 */
#ifdef __JTAG_DISABLED
    LPC_IOCON->JTAG_TCK_PIO0_10 &= ~0x07;
    LPC_IOCON->JTAG_TCK_PIO0_10 |= 0x03;/* Timer0_16 MAT2 */
#endif

    timer16_0_counter = 0;
    LPC_TMR16B0->MR0 = TimerInterval;

    LPC_TMR16B0->MCR = 3;/* Interrupt and Reset on MR0 */

    /* Enable the TIMER0 Interrupt */
    NVIC_EnableIRQ(TIMER_16_0_IRQn);
  }
  else if ( timer_num == 1 )
  {
 
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8);
    LPC_IOCON->PIO1_8           &= ~0x07;/*  Timer1_16 I/O config */
    LPC_IOCON->PIO1_8           |= 0x01;/* Timer1_16 CAP0 */
    LPC_IOCON->PIO1_9           &= ~0x07;
    LPC_IOCON->PIO1_9           |= 0x01;/* Timer1_16 MAT0 */
    LPC_IOCON->PIO1_10          &= ~0x07;
    LPC_IOCON->PIO1_10          |= 0x02;/* Timer1_16 MAT1 */

    timer16_1_counter = 0;
    LPC_TMR16B1->MR0 = TimerInterval;
    LPC_TMR16B1->MCR = 3;/* Interrupt and Reset on MR1 */

    /* Enable the TIMER1 Interrupt */
    NVIC_EnableIRQ(TIMER_16_1_IRQn);
  }
  return;
}

Kindly suggest how to process further.

Thank you.
Labels (1)
0 Kudos
Reply
1 Reply

585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Badman on Wed Aug 19 10:47:57 MST 2015
For change frequency, you must change  LPC_TMR16B0->MR0. No need to change the state of the pin 27 in the interruption. You can use the block PWM register LPC_TMR32B1-> PWMC
0 Kudos
Reply