Ejemplo n.º 1
0
int main(void)
{
    DelayInit();
    UART_QuickInit(UART0_RX_PD06_TX_PD07, 115200);
    GPIO_QuickInit(HW_GPIOE, 6, kGPIO_Mode_OPP); /* LED */

    printf("calc the PWM duty, pwm will be generated on PA08 and input pin: PC01 and PC02\r\n");
    
    FTM_PWM_QuickInit(FTM1_CH0_PA08, kPWM_EdgeAligned, 200);
	FTM_PWM_ChangeDuty(HW_FTM1, HW_FTM_CH0, 2500);/* 25% */
    
    /* 配置IC 功能 设置中断 */
    FTM_IC_QuickInit(FTM0_CH0_PC01, kFTM_ClockDiv128);
    FTM_IC_SetTriggerMode(HW_FTM0, HW_FTM_CH0, kFTM_IC_RisingEdge);
    FTM_CallbackInstall(HW_FTM0, FTM0_ISR);
    FTM_ITDMAConfig(HW_FTM0, kFTM_IT_CH0, true);
	
	FTM_IC_QuickInit(FTM0_CH1_PC02, kFTM_ClockDiv128);
    FTM_IC_SetTriggerMode(HW_FTM0, HW_FTM_CH1, kFTM_IC_FallingEdge);
    /* FTM_CallbackInstall(HW_FTM1, FTM1_ISR); */
    FTM_ITDMAConfig(HW_FTM0, kFTM_IT_CH1, true);
    
	while(1)
    {
        /*
		printf("Frequency:%6dHz", InputCaptureValue);
		printf(" Frequency1:%6dHz\r\n", InputCaptureValue1);
		*/
		printf("Duty = %3f%% \n",((double)InputCaptureValue)/((double)InputCaptureValue1)*100.0);
        GPIO_ToggleBit(HW_GPIOE, 6); //控制小灯闪烁
        DelayMs(500);
    }
}
Ejemplo n.º 2
0
static rt_err_t rt_beep_open(rt_device_t dev, rt_uint16_t oflag)
{
    if (dev->rx_indicate != RT_NULL)
    {
        /* Open Interrupt */
    }
    ftm_instance = FTM_PWM_QuickInit(FTM0_CH3_PA06, kPWM_EdgeAligned, 10000);
    FTM_PWM_ChangeDuty(ftm_instance, HW_FTM_CH3, 0);
    return RT_EOK;
}
Ejemplo n.º 3
0
int main(void)
{
    DelayInit();
    
    GPIO_QuickInit(HW_GPIOE, 6, kGPIO_Mode_OPP); /* LED */
    
    UART_QuickInit(UART0_RX_PD06_TX_PD07, 115200);
    
    printf("kPWM_Complementary test, pwm will be generated on PC01 and PC02\r\n");
    
    /* 初始化互补PWM 必须调用2次FTM_PWM_Init 硬件会自动连接相邻的2个通道*/
    FTM_PWM_QuickInit(FTM0_CH0_PC01, kPWM_Complementary, 3000);
    FTM_PWM_QuickInit(FTM0_CH1_PC02, kPWM_Complementary, 3000);
    
    /* 设置FTM 的占空比 */
    FTM_PWM_ChangeDuty(HW_FTM0, HW_FTM_CH0, 8000); // 50%占空比 0-10000 对应 0-100% 设置任意一个通道则会一起改变
    
    while(1)
    {
        GPIO_ToggleBit(HW_GPIOE, 6);
        DelayMs(500);
    }
}
Ejemplo n.º 4
0
static rt_err_t rt_beep_control(rt_device_t dev, rt_uint8_t cmd, void *args)
{
    RT_ASSERT(dev != RT_NULL);
    static int freq = 10000;
    switch (cmd)
    {
        case RT_DEVICE_CTRL_BEEP_START:
            FTM_PWM_ChangeDuty(ftm_instance, HW_FTM_CH3, 3000);
            break;
        case RT_DEVICE_CTRL_BEEP_STOP:
            FTM_PWM_ChangeDuty(ftm_instance, HW_FTM_CH3, 0);
            break;
        case RT_DEVICE_CTRL_SET_BEEP_FRQ:
            freq = *(int*)args;
            FTM_PWM_QuickInit(FTM0_CH3_PA06, kPWM_EdgeAligned, freq);
            break;
    }
    return RT_EOK;
}
Ejemplo n.º 5
0
int main(void)
{
    DelayInit();
    UART_QuickInit(UART0_RX_PD06_TX_PD07, 115200);
    GPIO_QuickInit(HW_GPIOE, 6, kGPIO_Mode_OPP); /* LED */

    printf("ftm intput capture test, pwm will be generated on PA06 and input pin: PA08\r\n");
    
    FTM_PWM_QuickInit(FTM0_CH3_PA06, kPWM_EdgeAligned, 200);
    
    /* 配置IC 功能 设置中断 */
    FTM_IC_QuickInit(FTM1_CH0_PA08, kFTM_ClockDiv128);
    FTM_IC_SetTriggerMode(HW_FTM1, HW_FTM_CH0, kFTM_IC_FallingEdge);
    FTM_CallbackInstall(HW_FTM1, FTM1_ISR);
    FTM_ITDMAConfig(HW_FTM1, kFTM_IT_CH0, true);
    
    while(1)
    {
        printf("Frequency:%6dHz\r", InputCaptureValue);
        GPIO_ToggleBit(HW_GPIOE, 6); //控制小灯闪烁
        DelayMs(500);
    }
}