看了官方的主要函数是:
#define Simple_CKO_MainCounter 120
#define Simple_CKO_Prescaler 100
#define Simple_CKO_Source 1
/**
*******************************************************************************
* @brief Toggle TM10_CKO pin when TM10 counter overflow
* @Details 1.initial & modify TimeBase parameter
* \n 2.clear TOF flag
* \n 3.Clock Out config (initial state='1' & enable clock out)
* \n 4.Start TM10
* @NOTE if user wants to 1ms period and CK_TM10_PR is 12MHz.
* The Total clocks is 12M*1ms = 12000.
* User can set "clock prescaler"=100 and "pulse width"=120 .
*******************************************************************************
*/
void Sample_TM10_ClockOut(void)
{
TM_TimeBaseInitTypeDef TM_TimeBase_InitStruct;
// 1.TimeBase structure initial
TM_TimeBaseStruct_Init(&TM_TimeBase_InitStruct); ///////¶¨Ê±Ê±»ù³õʼ»¯
// modify parameter
TM_TimeBase_InitStruct.TM_Period = Simple_CKO_MainCounter - 1; ///ÖÜÆÚ³õʼ»¯
TM_TimeBase_InitStruct.TM_Prescaler = Simple_CKO_Prescaler - 1; ///·ÖƵÆ÷
TM_TimeBase_InitStruct.TM_CounterMode = Cascade; /////¼ÆÊýģʽ
TM_TimeBase_Init(TM10, &TM_TimeBase_InitStruct); ///ʱ»ù³õʼ»¯
TM_ClearFlag(TM10, TMx_TOF); ///Çå³ýÖжÏ
// 3.Clock Out config (initial state='1' & enable clock out)
TM_ClockOutSource_Select(TM10, (TM_CKOSrcDef) Simple_CKO_Source); ///Êä³öµ½TM10
TM_CKOOutputState_Init(TM10, SET); /////Êä³ö״̬ΪSET
TM_ClockOut_Cmd(TM10, ENABLE); //////Êä³öʹÄÜ
// ----------------------------------------------------
// 4.Start TM10
TM_Timer_Cmd(TM10, ENABLE); ////´ò¿ª¶¨Ê±Æ÷
return;
}
再看手册的 对应输出口
再贴上整个程序 编译后烧录 示波器没有测试没有波形输出。
//***************************************************
//*********ʵÑéÄ¿µÄ£ºTM10Êä³öPWM²¨ÐÎ************
#include "MG32x02z__Common_DRV.H"
#include "MG32x02z_DRV.H"
#include "MG32x02z_TM_DRV.h"
void ChipInit(void);
#define Simple_CKO_MainCounter 120
#define Simple_CKO_Prescaler 100
#define Simple_CKO_Source 1
/**
*******************************************************************************
* @brief Toggle TM10_CKO pin when TM10 counter overflow
* @details 1.initial & modify TimeBase parameter
* \n 2.clear TOF flag
* \n 3.Clock Out config (initial state='1' & enable clock out)
* \n 4.Start TM10
* @note if user wants to 1ms period and CK_TM10_PR is 12MHz.
* The Total clocks is 12M*1ms = 12000.
* User can set "clock prescaler"=100 and "pulse width"=120 .
*******************************************************************************
*/
void Sample_TM10_ClockOut(void)
{
TM_TimeBaseInitTypeDef TM_TimeBase_InitStruct;
// 1.TimeBase structure initial
TM_TimeBaseStruct_Init(&TM_TimeBase_InitStruct); ///////¶¨Ê±Ê±»ù³õʼ»¯
// modify parameter
TM_TimeBase_InitStruct.TM_Period = Simple_CKO_MainCounter - 1; ///ÖÜÆÚ³õʼ»¯
TM_TimeBase_InitStruct.TM_Prescaler = Simple_CKO_Prescaler - 1; ///·ÖƵÆ÷
TM_TimeBase_InitStruct.TM_CounterMode = Cascade; /////¼ÆÊýģʽ
TM_TimeBase_Init(TM10, &TM_TimeBase_InitStruct); ///ʱ»ù³õʼ»¯
TM_ClearFlag(TM10, TMx_TOF); ///Çå³ýÖжÏ
// 3.Clock Out config (initial state='1' & enable clock out)
TM_ClockOutSource_Select(TM10, (TM_CKOSrcDef) Simple_CKO_Source); ///Êä³öµ½TM10
TM_CKOOutputState_Init(TM10, SET); /////Êä³ö״̬ΪSET
TM_ClockOut_Cmd(TM10, ENABLE); //////Êä³öʹÄÜ
// ----------------------------------------------------
// 4.Start TM10
TM_Timer_Cmd(TM10, ENABLE); ////´ò¿ª¶¨Ê±Æ÷
return;
}
int main()
{
ChipInit();
Sample_TM10_ClockOut();
while(1)
{
}
}
|