⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hal_ftm_pwm.c

📁 最新版IAR FOR ARM(EWARM)5.11中的代码例子
💻 C
字号:
/************************************************************************/
/*                                                                      */
/*    Copyright (C) 2006 Oki Electric Industry Co., LTD.                */
/*                                                                      */
/*    System Name    :  ML675050 series                                 */
/*    Module Name    :  ML675050 FTM_PWM HAL program                    */
/*    File   Name    :  hal_ftm_pwm.c                                   */
/*    Date           :  2005/01/12 initial version                      */
/*                                                                      */
/************************************************************************/
#include "common.h"
#include "hal_ftm_pwm.h"

#if defined(__arm)
#include "ml675050.h"
#elif defined(_WIN32)
#include "ml675050sim.h"
#else
#error COMPILER ERROR
#endif

#include "hal_state.h"
#include "hal_common.h"
#include "hal_interrupt.h"
/******************************/
/*     Private defines        */
/******************************/
/*--------- function ---------*/
static void _pwm1_handler(void);

/******************************/
/*     Public defines         */
/******************************/
FP pwm1_handler = _pwm1_handler;
/************************************************************************/
/*                                                                      */
/*  Function Name   : HALPwm_FtmPwmInit                                 */
/*  Input           : uint16_t pwm_mode                                 */
/*  Output          : void                                              */
/*  Note            : Initialize ftm_pwm.                               */
/*                                                                      */
/************************************************************************/
void HALPwm_FtmPwmInit(void)
{
    OkiCLib_write16(FTM1CON, FTM1CON_PWM | FTMCON_FTMCLK16);        /* Ftm1 mode set. */
    OkiCLib_set16bit(FTM1IER, FTM1IER_OVFIE);                      /* Ftm1 interrupt enable .*/
    OkiCLib_write16(FTM1IOLV, 0x0) ;
}
/************************************************************************/
/*                                                                      */
/*  Function Name   : HALPwm_FtmPwmSet                                  */
/*  Input           : struct ML675050_FtmPwm                            */
/*  Output          : void                                              */
/*  Note            :  ftm_pwm set.                                     */
/*                                                                      */
/************************************************************************/
void HALPwm_FtmPwmSet(struct ML675050_FtmPwm *pwm)
{
    OkiCLib_write16(FTM1R, pwm->cycle);                     /* Pwm1 interrupt cycle.*/
    OkiCLib_write16(FTM1GR, pwm->value);                    /* Pwm1 value set.*/
}
/************************************************************************/
/*                                                                      */
/*  Function Name   : HALPwm_FtmPwmStart                                */
/*  Input           : start 1: start  0: stop.                          */
/*  Output          : void                                              */
/*  Note            :   ftm_pwm start or stop.                          */
/*                                                                      */
/************************************************************************/
void HALPwm_FtmPwmStart(uint16_t start)
{
    if (start == 1) {
        OkiCLib_set16bit(FTMEN, FTMEN_FTMEN1);      /* FTM1 timer start. */
    }
    else {
        OkiCLib_set16bit(FTMDIS, FTMDIS_FTMDIS1);   /* FTM1 timer stop. */
    }
}
/************************************************************************/
/*                                                                      */
/*  Function Name   : _pwm_handler                                      */
/*  Input           : void                                              */
/*  Output          : void                                              */
/*                                                                      */
/*  Note : PWM handler.                                                 */
/*                                                                      */
/************************************************************************/
static void _pwm1_handler(void)
{
    OkiCLib_set16bit(FTM1ST,FTM1ST_OVF);  
    CALL_BACK_TABLE[INT_FTM1](CALLBACK_STATE_PWM); 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -