PWMout with CT32Bx external match register isn't working.

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

PWMout with CT32Bx external match register isn't working.

613 Views
daisukefukuda_n
Contributor III

Hi evevyone!

I try to make a pwmout by CT32B0 with external match register in LPC11U68 xpresso. I make sure the counter is working but I still observe pio1_26 keeps HIGH. I want to realize pio1_26 is working as a 50% duty pwm.

The code I modified is the following. Are there anything wrong?

board_sysinit.c

 /* PIO1_24-CT32B0_MAT0  -                           - GPIO input, with pullup */
 {1, 24, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, // fukuda modified

timer.c

int main(void)
{
 uint32_t timerFreq;

 SystemCoreClockUpdate();
 Board_Init();

 /* Initialize 32-bit timer 0 clock */
 Chip_TIMER_Init(LPC_TIMER32_0);

 /* Initialize 16-bit timer 0 clock */
 Chip_TIMER_Init(LPC_TIMER16_0);

 /* Timer rate is system clock rate */
 timerFreq = Chip_Clock_GetSystemClockRate();

 /* Timer setup for match and interrupt at TICKRATE_HZ */
 Chip_TIMER_Reset(LPC_TIMER32_0);
 Chip_TIMER_Reset(LPC_TIMER16_0);

 /* Enable both timers to generate interrupts when time matches */
 Chip_TIMER_MatchEnableInt(LPC_TIMER32_0, 1);
 Chip_TIMER_MatchEnableInt(LPC_TIMER16_0, 1);

 /* Setup prescale value on 16-bit timer to extend range */
 Chip_TIMER_PrescaleSet(LPC_TIMER16_0, PRESCALE_HZ2);

 /* Setup 32-bit timer's duration (32-bit match time) */
 Chip_TIMER_SetMatch(LPC_TIMER32_0, 1, (timerFreq / TICKRATE_HZ1));

 Chip_TIMER_SetMatch(LPC_TIMER32_0, 0, (timerFreq / TICKRATE_HZ1) / 2); // MAT0 = 1/2 of MAT1. by Fukuda


 /* Setup 16-bit timer's duration (16-bit match time) */
 Chip_TIMER_SetMatch(LPC_TIMER16_0, 1, (timerFreq / TICKRATE_HZ2) >> 16);

 /* Setup both timers to restart when match occurs */
 Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_0, 1);
 Chip_TIMER_ResetOnMatchEnable(LPC_TIMER16_0, 1);

 Chip_TIMER_ExtMatchControlSet(LPC_TIMER32_0, 0, TIMER_EXTMATCH_SET, 0); // At first, CT32B0_MAT0 (PIO1_24) sets LOW. If the counter reaches MAT0 then CT32B0_MAT0 (PIO1_24) goes to HIGH. by Fukuda

 /* Start both timers */
 Chip_TIMER_Enable(LPC_TIMER32_0);
 Chip_TIMER_Enable(LPC_TIMER16_0);

 /* Clear both timers of any pending interrupts */
 NVIC_ClearPendingIRQ(TIMER_32_0_IRQn);
 NVIC_ClearPendingIRQ(TIMER_16_0_IRQn);

 /* Enable both timer interrupts */

 NVIC_EnableIRQ(TIMER_32_0_IRQn);
 NVIC_EnableIRQ(TIMER_16_0_IRQn);

 /* Wait for timers to generate interrupts (LEDs toggle in interrupt handlers) */
 while (1) {
  __WFI();
 }

 return 0;
}

Best regards,

Fukuda

Labels (1)
0 Kudos
2 Replies

475 Views
daisukefukuda_n
Contributor III

Hi everyone!

This is Daisuke. I was able to resolve this issue by myself. The root cause is that the io port settings is not executed because I believed  Board_SystemInit() I ported was called in main(), but it didn't call it. That was my mistake, sorry.

Please let me share my solution with you.

board_sysinit.c

 /* PIO1_24-CT32B0_MAT0  -                           - GPIO input, with pullup */
 {1, 24, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, // fukuda modified

 

test.c

void Init_myBuzzer(void)
{
// uint32_t timerFreq;

 /* Initialize 32-bit timer 0 clock */
 Chip_TIMER_Init(LPC_TIMER32_0);

 /* Timer rate is system clock rate */
// timerFreq = Chip_Clock_GetSystemClockRate();

 /* Timer setup for match and interrupt at TICKRATE_HZ */
 Chip_TIMER_Reset(LPC_TIMER32_0);

 Chip_TIMER_EnablePWMControl(LPC_TIMER32_0, 0); // Enable PWM mode

 /* Clear both timers of any pending interrupts */
// NVIC_ClearPendingIRQ(TIMER_32_0_IRQn); // for debug
}

void Start_myBuzzer(int cycle)
{
 uint32_t timerFreq;

 /* Timer rate is system clock rate */
 timerFreq = Chip_Clock_GetSystemClockRate();

// printf("timerFreq:%d, cycle:%d, MAT3:%d, MAT0:%d\n", timerFreq, cycle, (timerFreq / cycle), ((timerFreq / cycle) / 2)); // debug

 /* Setup a 32-bit timer to restart when match occurs */
 Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_0, 3);

 /* Setup 32-bit timer's duration (32-bit match time) */
 Chip_TIMER_SetMatch(LPC_TIMER32_0, 3, (timerFreq / cycle)); // If MR3 reaches timerFreq then MR3 goes to 0.

 Chip_TIMER_SetMatch(LPC_TIMER32_0, 0, ((timerFreq / cycle) / 2));

// Chip_TIMER_MatchEnableInt(LPC_TIMER32_0, 3);

 /* Start a timer */
 Chip_TIMER_Enable(LPC_TIMER32_0);

 /* Enable a timer interrupt */
// NVIC_EnableIRQ(TIMER_32_0_IRQn); // debug
}

timer_11u6x.h

STATIC INLINE void Chip_TIMER_EnablePWMControl(LPC_TIMER_T *pTMR, int8_t pwmnum)
{
 pTMR->PWMC |= (uint32_t) (1 << pwmnum);
}

STATIC INLINE void Chip_TIMER_DisablePWMControl(LPC_TIMER_T *pTMR, int8_t pwmnum)
{
 pTMR->PWMC &= ~((uint32_t) (1 << pwmnum));
}

0 Kudos

475 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Daisuke Fukuda,

Thank you for your interest in NXP Semiconductor products and 
for the opportunity to serve you.

I'm glad to hear that.

If you have any further questions about it, please feel free to contact with me.
 Have a great day,

TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos