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