各位大师,我又来了。昨天听过大神的建议后,我学习了一下KE06开发板的数据手册和一些demo。其中有一个demo是我所想要了解一下的,就是FTM_EPWM_demo。看过代码,也自己把程序烧写到板子上后了,我就有几个问题了。
首先,就是这些函数,虽然上面都有注释说明其含义,但是我之前从来没有见过这些函数,现在看见这些函数完全不知道该怎么用,所以想问问有没有像我这个板子的一些函数的使用说明和函数库?
第二个问题,就是EPWM周期问题,使用手册上面说EPWM 周期取决于(MOD − CNTIN + 0x0001),然后EPWM模式只有在CNTIN=0x0000的时候才能使用。下面代码有 FTM_SetModValue(FTM2,9999);应该是把MOD的值设为9999吧?那这个样子的话应该怎么算?9999是十进制还是什么?感觉灯闪的周期没那么大啊。如果我想把周期设为200ms的话应该怎么改?
下面是FTM_EPWM_demo.c
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2013 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
***************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
***************************************************************************//*!
*
* @file FTM_EPWM_demo.c
*
* @author Freescale
*
* @version 0.0.1
*
* @date Oct. 25, 2013
*
* @brief Demonstrate EPWM, output pwm from FTM2 Ch5,
LED BLUE on FRDM-KE06 board will blink as pwm pulse width changing.
*
*******************************************************************************/
#include "common.h"
#include "ics.h"
#include "ftm.h"
#include "uart.h"
#include "sysinit.h"
/******************************************************************************
* Global variables
******************************************************************************/
/******************************************************************************
* Constants and macros
******************************************************************************/
/******************************************************************************
* Local types
******************************************************************************/
/******************************************************************************
* Local function prototypes
******************************************************************************/
/******************************************************************************
* Local variables
******************************************************************************/
/******************************************************************************
* Local functions
******************************************************************************/;
void FTM2_Task(void);
/******************************************************************************
* Global functions
******************************************************************************/
/********************************************************************/
int main (void)
{
/* Perform processor initialization */
sysinit();
//Select FTM2Ch5 on PTG7
SIM_RemapFTM2CH4ToPTG6();
/* FTM2 is set as edge aligned pwm mode, high true pulse */
FTM_PWMInit(FTM2, FTM_PWMMODE_EDGEALLIGNED, FTM_PWM_HIGHTRUEPULSE);
/* FTMEN enable */
FTM_SetFTMEnhanced(FTM2);
/* update MOD value */
FTM_SetModValue(FTM2,9999);
/* set clock source, start counter */
FTM_ClockSet(FTM2, FTM_CLOCK_SYSTEMCLOCK, FTM_CLOCK_PS_DIV1);
/* enable FTM2 interrupt in NVIC */
NVIC_EnableIRQ(FTM2_IRQn);
/* setup call back function for interrupt */
FTM_SetCallback(FTM2, FTM2_Task);
/* enable FTM2 overflow interrupt */
FTM_EnableOverflowInt(FTM2);
while(1)
{}
}
/*****************************************************************************//*!
*
* @brief callback routine of FTM2 driver. FTM2 CH5 will change the duty cycle
* periodically.
*
* @param none.
*
* @return none.
*
* @ Pass/ Fail criteria: none.
*
*****************************************************************************/
uint16_t u16ChV_old, u16ChV_new;
void FTM2_Task(void)
{
static uint16_t u16count;
static uint8_t u8DirMark;
/* clear the flag */
FTM_ClrOverFlowFlag(FTM2);
if(100 == u16count)
{
u16count = 0;
u16ChV_old = FTM2->CONTROLS[4].CnV;
if(!u8DirMark)
{
u16ChV_new = u16ChV_old + 200;
if(u16ChV_new >= FTM2->MOD)
{
u16ChV_new = FTM2->MOD - 200;
u8DirMark = 1;
}
else
{
}
}
else
{
u16ChV_new = u16ChV_old - 200;
if(u16ChV_new < 200)
{
u16ChV_new = 200;
u8DirMark = 0;
}
else
{
}
}
/* update the channel value */
FTM_SetChannelValue(FTM2, FTM_CHANNEL_CHANNEL4, u16ChV_new);
}
else
{
u16count++;
}
}
/********************************************************************/
如果可能的话,也说一下那个FTM2_TASK函数是干嘛的,谢谢了。 |