在M4核的PTA2上输出PWM波控制摄像头补光灯

cancel
Showing results for 
Search instead for 
Did you mean: 

在M4核的PTA2上输出PWM波控制摄像头补光灯

Jump to solution
334 Views
404740370
Contributor I

参照SDK中实例simple_pwm,具体代码如下:

404740370_0-1599810128899.png

404740370_1-1599810151413.png

/*******************************************************************************
===========================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;
}

404740370_2-1599810223203.png

 

int main(void)
{
。。。。
PTA2_PWM0_Init();
Ctrl_PTA2_PWM0_Proc(8);
。。。
}

 

我反复设置这个Ctrl_PTA2_PWM0_Proc(10);从0设置到10都没啥变化

用示波器看PTA2(威富模块的11脚),一直输出高电平

0 Kudos
1 Solution
332 Views
terry_lv
NXP Employee
NXP Employee

Hi,

  Please check:

  1. #define TPM_SOURCE_CLOCK CLOCK_GetIpFreq(kCLOCK_Tpm2)
  2. CLOCK_SetIpSrc(kCLOCK_Tpm2, kCLOCK_IpSrcSysOscAsync);

  Tpm0 should be used to initialize clock.

  Thanks!

Regards

Terry

View solution in original post

3 Replies
315 Views
nxf58904
NXP TechSupport
NXP TechSupport

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.
-------------------------------------------------------------------------------

0 Kudos
328 Views
404740370
Contributor I

OK了,THKs

0 Kudos
333 Views
terry_lv
NXP Employee
NXP Employee

Hi,

  Please check:

  1. #define TPM_SOURCE_CLOCK CLOCK_GetIpFreq(kCLOCK_Tpm2)
  2. CLOCK_SetIpSrc(kCLOCK_Tpm2, kCLOCK_IpSrcSysOscAsync);

  Tpm0 should be used to initialize clock.

  Thanks!

Regards

Terry

View solution in original post