LPC55S69 ctimer pwm

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

LPC55S69 ctimer pwm

866 Views
wangyibin
Contributor II

在SDK的 alpcxpresso55s69_ctimer_pwm_example中提定时器的一个pwm通道进行配置,我想再配置另一个定时器的pwm输出,同时输出两路的pwm。添加了kCTIMER_Match_2通道和volatile uint32_t g_pwmPeriod_1 = 0U;volatile uint32_t g_pulsePeriod_1 = 0U;的宏定义并为此
单独配置了CTIMER_GetPwmPeriodValue1函数如下图所示。但在我单独的运行第2张图的上面两行程序时,现象是:绿灯闪烁,蓝灯常亮。单独的运行第2张图下面的两行程序时,现象是:蓝灯闪烁,绿灯常亮。这四行程序一起运行,现象是蓝绿混色在我规定的频率上亮是符合预期的。

wangyibin_1-1646016458055.png

wangyibin_0-1646016372786.png

请问他们单独运行的时候为什么会相互干扰并且他们灯亮的颜色和程序并不是一致的呢?是不是我配置的有问题,CTIMER_SetupPwmPeriod(CTIMER, CTIMER_MAT_PWM_PERIOD_CHANNEL_1, CTIMER_MAT_OUT_2, g_pwmPeriod_1, g_pulsePeriod_1, false);
中的第二个参数也是定时器的通道可以两路pwm输出公用吗?

在这个函数中的第二个参数说是Specify the channel to control the PWM period?我想用ctimer2同时输出3路pwm,3路输出都用同一个通道可以吗?

 

 

Labels (1)
0 Kudos
3 Replies

856 Views
wangyibin
Contributor II

srcClock_Hz = CTIMER_CLK_FREQ;

PRINTF("CTimer 示例以生成 PWM 信号\r\n");

CTIMER_GetDefaultConfig(&config);
timerClock = srcClock_Hz / (config.prescale + 1);

CTIMER_Init(CTIMER, &config);

这一段代码应该是pwm的两个通道可以公用的;

CTIMER_GetPwmPeriodValue(2, 20, timerClock);
CTIMER_SetupPwmPeriod(CTIMER, CTIMER_MAT_PWM_PERIOD_CHANNEL, CTIMER_MAT_OUT, g_pwmPeriod, g_pulsePeriod, false);
CTIMER_GetPwmPeriodValue1(2, 20, timerClock);
CTIMER_SetupPwmPeriod(CTIMER, CTIMER_MAT_PWM_PERIOD_CHANNEL, CTIMER_MAT_OUT_2, g_pwmPeriod_1, g_pulsePeriod_1, false);

为另一个通道配置了CTIMER_GetPwmPeriodValue1函数的2个宏定义,但输出的波形占空比和我的程序设定的不一样。

按道理同一个定时器的两个通道能够同时输出不同的波形?

0 Kudos

852 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

For one CTimer module, all PWM channels(CT2_MAT0, CT2_MAT1,CT2_MAT2) must  have the same PWM cycle time, only the duty cycle can be different.

Hope it can help you

BR

XiangJun Rong

0 Kudos

860 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I think you can consider the following code.

P0_10 FC6_SCK CT_INP10 CT2MAT0 FC1_TXD_SCL_
MISO

The following code set up so that the PWM signal can output to CT2MT0 pin(P0_10)

In the pin_mux.c, pls add the code in the void BOARD_InitPins(void)

void BOARD_InitPins(void)

{

.........................

CLOCK_EnableClock(kCLOCK_Iocon);
//P0_10 func3=CT2_MAT0

const uint32_t port0_pin10_config = (/* Pin is configured as CTIMER2_MAT1 */
IOCON_PIO_FUNC3 |
/* No addition pin function */
IOCON_PIO_MODE_INACT |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW_STANDARD |
/* Input function is not inverted */
IOCON_PIO_INV_DI |
/* Enables digital function */
IOCON_PIO_DIGITAL_EN |
/* Open drain is disabled */
IOCON_PIO_OPENDRAIN_DI);
/* PORT1 PIN4 (coords: 1) is configured as CTIMER2_MAT1 */
IOCON_PinMuxSet(IOCON, 0U, 10U, port0_pin10_config);

}

For example, you want to add the CT2_MAT0 pin to output PWM signal.

srcClock_Hz = CTIMER_CLK_FREQ;

PRINTF("CTimer example to generate a PWM signal\r\n");

CTIMER_GetDefaultConfig(&config);
timerClock = srcClock_Hz / (config.prescale + 1);

CTIMER_Init(CTIMER, &config);

/* Get the PWM period match value and pulse width match value of 20Khz PWM signal with 20% dutycycle */
CTIMER_GetPwmPeriodValue(20000, 20, timerClock);
CTIMER_SetupPwmPeriod(CTIMER, CTIMER_MAT_OUT, g_pwmPeriod, g_pulsePeriod, false);

 


//Can not use kCTIMER_Match_3, which is used to control PWM period

//output PWM signal from the P0_10
CTIMER_SetupPwmPeriod(CTIMER, kCTIMER_Match_0, g_pwmPeriod, g_pulsePeriod, false);

CTIMER_StartTimer(CTIMER);

while (1)
{
}
}

I do not have a test, pls test yourself.

Hope it can help you

BR

XiangJun Rong

 

0 Kudos