Exemplo n.º 1
0
void Motor_Duty_Change(MotorPosition motorPos, int32 tagetDuty)
{

    /* Set motor threshold */
    if (tagetDuty > 9000)
    {
        tagetDuty = 9000;
    }
    else if (tagetDuty < -9000)
    {
        tagetDuty = -9000;
    }

	switch (motorPos)
	{
		case MOTOR_LEFT :
			LPLD_FTM_PWM_ChangeDuty(FTM0, FTM_Ch1, tagetDuty > 0 ? 0 : (uint32)(-tagetDuty));
			LPLD_FTM_PWM_ChangeDuty(FTM0, FTM_Ch2, tagetDuty > 0 ? (uint32)tagetDuty : 0);
			break;
		case MOTOR_RIGHT :
			LPLD_FTM_PWM_ChangeDuty(FTM0, FTM_Ch3, tagetDuty > 0 ? 0 : (uint32)(-tagetDuty));
			LPLD_FTM_PWM_ChangeDuty(FTM0, FTM_Ch4, tagetDuty > 0 ? (uint32)tagetDuty : 0);
            break;
	}
}
Exemplo n.º 2
0
void main (void)
{

  //初始化PWM
  pwm_init();
  
  delay(1000);
  //初始化延时后改变角度为45度
#if defined(CPU_MK60DZ10) || defined(CPU_MK60D10)
  LPLD_FTM_PWM_ChangeDuty(FTM0, FTM_Ch0, angle_to_period(45));
#elif defined(CPU_MK60F12) || defined(CPU_MK60F15)
  LPLD_FTM_PWM_ChangeDuty(FTM2, FTM_Ch0, angle_to_period(45));
#endif 
  while(1)
  {
  } 
}
Exemplo n.º 3
0
void pit0_isr(void)
{
	PIT_InitTypeDef pit0_init_struct;
	pit0_init_struct.PIT_Pitx = PIT0;
	
	LPLD_FTM_PWM_ChangeDuty(FTM0, FTM_Ch0, angle_to_period(90));
	
	LPLD_PIT_Deinit(pit0_init_struct);
}