有没有,CH32X035F8U6的PWM示例

请问,有没有,CH32X035F8U6的PWM示例,用官方给的示例调试板子上没有反应

#include "debug.h"


/* PWM Output Mode Definition */

#define PWM_MODE1   0

#define PWM_MODE2   1


/* PWM Output Mode Selection */

#define PWM_MODE PWM_MODE1

//#define PWM_MODE PWM_MODE2


/* PWM Supersede Mode Enable Definition*/

#define PWM_SPE_MODE_DISABLE   0

#define PWM_SPE_MODE_ENABLE    1


/* PWM Supersede Mode Enable Selection */

#define PWM_SPE_MODE   PWM_SPE_MODE_DISABLE

//#define PWM_SPE_MODE   PWM_SPE_MODE_ENABLE




/*********************************************************************

 * @fn      TIM1_OutCompare_Init

 *

 * @brief   Initializes TIM1 output compare.

 *

 * @param   arr - the period value.

 *          psc - the prescaler value.

 *          ccp - the pulse value.

 *

 * @return  none

 */

void TIM1_PWMOut_Init(u16 arr, u16 psc, u16 ccp)

{

GPIO_InitTypeDef GPIO_InitStructure={0};

TIM_OCInitTypeDef TIM_OCInitStructure={0};

TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure={0};


RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_TIM1, ENABLE );


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init( GPIOA, &GPIO_InitStructure );


TIM_TimeBaseInitStructure.TIM_Period = arr;

TIM_TimeBaseInitStructure.TIM_Prescaler = psc;

TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit( TIM1, &TIM_TimeBaseInitStructure);


#if (PWM_MODE == PWM_MODE1)

  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;


#elif (PWM_MODE == PWM_MODE2)

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;


#endif


TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse = ccp;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OC1Init( TIM1, &TIM_OCInitStructure );


#if (PWM_SPE_MODE == PWM_SPE_MODE_ENABLE)

TIM_OC12_SupersedeModeCmd( TIM1, TIM_Supersede_Mode_OC1_H, TIM_Supersede_Mode_OC2_H, ENABLE);

#endif


TIM_CtrlPWMOutputs(TIM1, ENABLE );

TIM_OC1PreloadConfig( TIM1, TIM_OCPreload_Disable );

TIM_ARRPreloadConfig( TIM1, ENABLE );

TIM_Cmd( TIM1, ENABLE );

}

/*********************************************************************

 * @fn      main

 *

 * @brief   Main program.

 *

 * @return  none

 */

int main(void)

{

SystemCoreClockUpdate();

USART_Printf_Init(115200);

printf("SystemClk:%d\r\n",SystemCoreClock);

printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );


TIM1_PWMOut_Init( 100, 48000-1, 50 );


while(1);

}



您好,PA0对应的是TIM2的通道1,你程序中还配置TIM1,有问题,附件为参考例程,可以看一下

icon_rar.gifCH32X035 PA0_PWM.zip



只有登录才能回复,可以选择微信账号登录