参照SDK中实例simple_pwm,具体代码如下:
/*******************************************************************************
===========================PTA2_PWM0_CH0======================
******************************************************************************/
volatile uint8_t updatedDutycycle = 10U;
void PTA2_PWM0_Init()
{
tpm_config_t tpmInfo;
tpm_chnl_pwm_signal_param_t tpmParam;
#ifndef TPM_LED_ON_LEVEL
#define TPM_LED_ON_LEVEL kTPM_LowTrue
#endif
/* Configure tpm params with frequency 24kHZ */
tpmParam.chnlNumber = (tpm_chnl_t)BOARD_TPM_CHANNEL;
tpmParam.level = TPM_LED_ON_LEVEL;
tpmParam.dutyCyclePercent = updatedDutycycle;
/* Print a note to terminal */
PRINTF("\r\nTPM example to output center-aligned PWM signal\r\n");
PRINTF("\r\nIf an LED is connected to the TPM pin, you will see a change in LED brightness if you enter different values");
PRINTF("\r\nIf no LED is connected to the TPM pin, then probe the signal using an oscilloscope");
TPM_GetDefaultConfig(&tpmInfo);
/* Initialize TPM module */
TPM_Init(BOARD_TPM_BASEADDR, &tpmInfo);
TPM_SetupPwm(BOARD_TPM_BASEADDR, &tpmParam, 1U, kTPM_CenterAlignedPwm, 24000U, TPM_SOURCE_CLOCK);
TPM_StartTimer(BOARD_TPM_BASEADDR, kTPM_SystemClock);
}
int Ctrl_PTA2_PWM0_Proc(unsigned char setValue)
{
if(setValue > 9U)
{
DBG_PRINTF("Note: The range of value is 0 to 9.\r\n");
DBG_PRINTF("For example: If enter '5', the duty cycle will be set to 50 percent.\r\n");
return -1;
}
updatedDutycycle = setValue * 10U;
/* Disable channel output before updating the dutycycle */
TPM_UpdateChnlEdgeLevelSelect(BOARD_TPM_BASEADDR, (tpm_chnl_t)BOARD_TPM_CHANNEL, 0U);
/* Update PWM duty cycle */
TPM_UpdatePwmDutycycle(BOARD_TPM_BASEADDR, (tpm_chnl_t)BOARD_TPM_CHANNEL, kTPM_CenterAlignedPwm,
updatedDutycycle);
/* Start channel output with updated dutycycle */
TPM_UpdateChnlEdgeLevelSelect(BOARD_TPM_BASEADDR, (tpm_chnl_t)BOARD_TPM_CHANNEL, TPM_LED_ON_LEVEL);
DBG_PRINTF("The duty cycle was successfully updated!\r\n");
return 0;
}
int main(void)
{
。。。。
PTA2_PWM0_Init();
Ctrl_PTA2_PWM0_Proc(8);
。。。
}
我反复设置这个Ctrl_PTA2_PWM0_Proc(10);从0设置到10都没啥变化
用示波器看PTA2(威富模块的11脚),一直输出高电平
Solved! Go to Solution.
Hi,
Please check:
Tpm0 should be used to initialize clock.
Thanks!
Regards
Terry
Hi,
Has the problem been solved ?
I will support you if you still have issues.
Jianyu:
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
OK了,THKs
Hi,
Please check:
Tpm0 should be used to initialize clock.
Thanks!
Regards
Terry