Exemple #1
0
void MemManage_Handler(void)//??????
{
	FTM_PWM_ChangeDuty(FTM0_CH3_PA6,0);
	FTM_PWM_ChangeDuty(FTM0_CH4_PA7,0);
//	FTM_PWM_ChangeDuty(FTM1_CH0_PA8,0);
//	FTM_PWM_ChangeDuty(FTM1_CH1_PA9,0);
	#if(CHIP_DEBUG==ON)	
	wait();
	#endif
}
Exemple #2
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);
    }
}
Exemple #3
0
void HardFault_Handler(void)//?????????
{
	OLED_Clear();
	FTM_PWM_ChangeDuty(FTM0_CH3_PA6,0);
	FTM_PWM_ChangeDuty(FTM0_CH4_PA7,0);
//	FTM_PWM_ChangeDuty(FTM1_CH0_PA8,0);
//	FTM_PWM_ChangeDuty(FTM1_CH1_PA9,0);
	OLED_Write_String(0,0,(uint8_t *)"The memory");
	
	OLED_Write_String(0,2,(uint8_t *)"or Stacks");	
	
	OLED_Write_String(0,4,(uint8_t *)"overflows");
	
	#if(CHIP_DEBUG==ON)
	wait();
	#endif
	while(1);
}
Exemple #4
0
void NMI_Handler(void)//??????
{
	OLED_Clear();
	FTM_PWM_ChangeDuty(FTM0_CH3_PA6,0);
	FTM_PWM_ChangeDuty(FTM0_CH4_PA7,0);
//	FTM_PWM_ChangeDuty(FTM1_CH0_PA8,0);
//	FTM_PWM_ChangeDuty(FTM1_CH1_PA9,0);

	OLED_Write_String(0,0,(uint8_t *)"The Chip");
	
	OLED_Write_String(0,2,(uint8_t *)"have big");	
	
	OLED_Write_String(0,4,(uint8_t *)"error");
	#if(CHIP_DEBUG==ON)	
	wait();
	#endif
	while(1);
}
Exemple #5
0
/*****************************
*
*  函数名称CCD_HeiXian
*  功能说明:采集黑线位置进行黑线点数计算
*  参数说明:
*  函数返回:无
*  修改时间:
*  备    注:
*************************************************************************/
void CCD_HeiXian(void)
{
	uint8_t i;
	for(i = Center;i < 128;i++)
	{
		if(Pixel[i] == 0) 
		{
			Right = i;
			break;
		}
	}
	for(i = Center;i > 0;i--)
	{
		if(Pixel[i] == 0)
		{
			Left = i;
			break;
		}
	}
	
	Center = (Left + Right) / 2;
	if(Center <= 63)
	{
		if(63 - Center <= 7)											FTMDuty = 4700 + (63 - Center) * a1;
		if(63 - Center <= 15 && 63 - Center > 7)  FTMDuty = 4700 + (63 - Center) * a2;
		if(63 - Center <= 25 && 63 - Center > 15) FTMDuty = 4700 + (63 - Center) * a3;
		if(63 - Center <= 40 && 63 - Center > 25) FTMDuty = 4700 + (63 - Center) * a4;
		if(63 - Center >40)												FTMDuty = 4700 + (63 - Center) * a5;
		
		FTM_PWM_ChangeDuty(FTM0_CH4_PA7,FTMDuty);
		if(FTMDuty >= 5900) FTMDuty = 5900;
	}
	if(Center >= 64)
	{
		if (Center - 64 <= 7)											 FTMDuty = 4700 - (Center - 64) * a1;
		if (Center - 64 <= 15 && Center - 64 > 7)  FTMDuty = 4700 - (Center - 64) * a2;
		if (Center - 64 <= 25 && Center - 64 > 15) FTMDuty = 4700 - (Center - 64) * a3;
		if (Center - 64 <= 40 && Center - 64 > 25) FTMDuty = 4700 - (Center - 64) * a4;
		if (Center - 64 >40)											 FTMDuty = 4700 - (Center - 64) * a5;

		FTM_PWM_ChangeDuty(FTM0_CH4_PA7,FTMDuty);
		if(FTMDuty <= 3700) FTMDuty = 3700;
	}
}
Exemple #6
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;
}
Exemple #7
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;
}
Exemple #8
0
void FTM_Configuration (void)
{
	FTM_InitTypeDef FTM_InitStruct;
	FTM_PWM_MapTypeDef* pFTM_Map = (FTM_PWM_MapTypeDef*) FTM1;
	FTM_InitStruct.Frequency = (uint32_t)(4096*5);  //
	FTM_InitStruct.FTMxMAP = FTM1_CH1_PB1;          //
	FTM_InitStruct.FTM_Mode = FTM_Mode_EdgeAligned; //
	FTM_InitStruct.InitalDuty = FTM_DUTY;           //0~10000
	FTM_Init(&FTM_InitStruct);
	AD7687_CNV_PORT->PCR[AD7687_CNV_Pin]|= PORT_PCR_ODE_MASK;
	FTM_PWM_ChangeDuty(FTM1_CH1_PB1,0);
}
Exemple #9
0
//退出
void Menu_Quit(void)
{
	if(Key_2  ==  0)
	{
		DelayMs(100);
		if(Key_2  ==  0)
		{
			OLED_Clear();
			CCD_Flag = 0;
			PIT_Stop(PIT1);
			FTM_PWM_ChangeDuty(FTM0_CH3_PA6,0);
		}
	}
}
Exemple #10
0
void SCU_TASK(void *p_arg)
{
	uint32_t* speed;
	uint8_t err;
	int PWM_Duty = 0;
	int B;
  (void)p_arg;  
	LCD_Print(1,2,"speed = 1.0m/s");
	while(1)
	{
		PID_Init();
		speed = OSMboxPend(Str_Box_1,0,&err);   //请求消息;获得当前速度
	  // printf("process_point = %d\n",*speed);
		 
		 PWM_Duty += PID_Calc(0, *speed, 0);
     B = PWM_Duty;
		 printf("PWM = %d\n",B);
		 if(PWM_Duty >= 1000)
		 {
		   FTM_PWM_ChangeDuty(HW_FTM0,HW_FTM_CH0,1000);  /* 0-10000 对应 0-100%占空比 */
		 //	LCD_Print(1,5,"FULL_SPEED");
		 	printf("PWM_Duty = 100 \n");
		 }
		  if(PWM_Duty > 0 && PWM_Duty < 1000)
		 {
		   FTM_PWM_ChangeDuty(HW_FTM0,HW_FTM_CH0,PWM_Duty);  /* 0-10000 对应 0-100%占空比 */
		 //	LCD_Print(1,7,"Part_SPEED");
		 	printf("PWM_Duty = %d\n",PWM_Duty/100);
		 }
		 if (PWM_Duty <= 0)
		 {
		   FTM_PWM_ChangeDuty(HW_FTM0,HW_FTM_CH0,0);  /* 0-10000 对应 0-100%占空比 */
		 	 printf("PWM_Duty = 0\n");
		 }
    OSTimeDlyHMSM(0,0,0,50);	
	}
}
Exemple #11
0
void DIR_TASK(void *p_arg)
{
	uint8_t err;
	double servo_corner,Location_corner,B,D;
	float Servo_pwm_duty,A;
	uint8_t* Track_Midline_value;
	(void)p_arg;
		while(1)
		{
			Track_Midline_value = OSMboxPend(Str_Box_2,0,&err);
			B = *Track_Midline_value;
			printf("Track_value = %f\n",B);
			Location_corner = PID_Calc(1, 0, *Track_Midline_value);
			D = servo_corner;
			printf("servo_corner = %f\n",D);
			Servo_pwm_duty = Servo_pwm(Location_corner);
			A = Servo_pwm_duty;
			printf("Servo_pwm_duty = %f\n",A);
			FTM_PWM_ChangeDuty(HW_FTM1,HW_FTM_CH0,Servo_pwm_duty);	
			OSTimeDlyHMSM(0,0,0,50);
		}
}
Exemple #12
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);
    }
}
Exemple #13
0
int main(void)
{

	SystemClockSetup(ClockSource_EX50M,CoreClock_100M);
	DelayInit();
	OLED_Init();
	Sd_Init();
	chuinit_Init();
	DataInit();
	Data_Uart_Init();
	
	while(1)
	{
		Menu_Init();
		//ccd
		while(Flag == 1)
		{
			if(TIME1flag_20ms == 1)
			{
				TIME1flag_20ms = 0;
				ImageCapture(Pixel);
//				Sd_X();
//				Sd_D();
//				UART_Send_Con();
				erzhi();
				LB();
				oled_collect();
				oled_show();
			}
			CCD_HeiXian();
			OLED_ZhongXian();
			OLED_Write_Num3(4,0,Center);
			OLED_Write_Num3(0,0,Left);
			OLED_Write_Num3(9,0,Right);
			if(Key_1 == 0) //??
			{
				DelayMs(100);
				if(Key_1 == 0)
				{
					OLED_Clear();
					Flag = 2;
					SD_X = 0;
					PIT_Start(PIT1);
				}
			}
			if(Key_down == 0) //发车
			{
				DelayMs(100);
				if(Key_down == 0)
				{
					OLED_Clear();
					Flag = 0;
					PIT_Stop(PIT1);
					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
				}
			}
			if(Key_right == 0) //上位机
			{
				DelayMs(100);
				if(Key_right == 0)
				{
					while(1)
					{
						OLED_Clear();
						Sd_D();
						UART_Send_Con();
						FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
					}
				}
			}
		}
		
	//发车
		while(Flag == 2)
		{
			if(TIME1flag_20ms==1)
			{
				TIME1flag_20ms=0;
				ImageCapture(Pixel);
				erzhi();
				LB();
				Sd_X();
			}
			CCD_HeiXian();
			if(leixin == 0) 
			{
				if(jiasuflag <= a4) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,5000);
				if(jiasuflag >  a4) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,FTMDuty_1);
			}
			if(leixin == 1) 
			{
				if(jiansuflag <= a3) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
				if(jiansuflag >  a3) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,FTMDuty_2);
			}
			if(Key_down == 0)//菜单
			{
				DelayMs(100);
				if(Key_down == 0)
				{
					OLED_Clear();
					Flag = 0;
					PIT_Stop(PIT1);
					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
				}
			}
		}
	}
}
Exemple #14
0
/*****************************
*
*  函数名称CCD_HeiXian
*  功能说明:采集黑线位置进行黑线点数计算
*  参数说明:
*  函数返回:无
*  修改时间:
*  备    注:
*************************************************************************/
void CCD_HeiXian(void)
{
	uint8_t i,value_max,value_min,maxvalue;
	
	value_max = Pixel[0];
	for (i = 2;i < 126;i++) 
  {
    if (value_max <= Pixel[i]) value_max = Pixel[i];
  }
	value_min = Pixel[0];
	for (i = 2;i < 126;i++) 
  {
    if (value_min >= Pixel[i]) value_min = Pixel[i];
  }
	AverageValue = (value_max + value_min) / 2 + 10;
	
//	for(i = 2;i <= 126;i++)
//  {
//    if(value_max <= Pixel[i])
//		{
//			value_max = Pixel[i];
//			maxvalue = i;
//		}
//    if(value_min >= Pixel[i])	value_min = Pixel[i];
//  }
//	value_max = (Pixel[maxvalue] + Pixel[maxvalue + 1] + Pixel[maxvalue + 2] + Pixel[maxvalue - 1] + Pixel[maxvalue - 2]) / 5;
//	
//	if(value_min < 40) value_min = 40;
//	
//	AverageValue = (0.3 * value_max + 0.7 * value_min);

	for (i = saoxian;i <= 122;i++)
	{
		Right = i;
		if (Pixel[i - 2] - Pixel[i] >= 8 && Pixel[i - 3] - Pixel[i - 1] >= 8 && Pixel[i] <= AverageValue) break;
	}
	for (i = saoxian;i >= 6;i--)
	{
		Left = i;
		if (Pixel[i + 2] - Pixel[i] >= 8 && Pixel[i + 3] - Pixel[i + 1] >= 8 && Pixel[i] <= AverageValue) break;
	}
	if (Left != 6 && Right != 122 && leixin == 0) Budao = (Right - Left) / 2;
	
/***********************buxianchuli*************************************/
	
	if (Left != 6 && Right == 122)
	{
		for (i = saoxian; i <= 122; i++)
		{
			Right = i;
			if (Pixel[i - 4] - Pixel[i] >= 8 && Pixel[i - 5] - Pixel[i - 1] >= 8 && Pixel[i] <= AverageValue) break;
		}
		if (Right != 122) Center = (Right + Left) / 2;
		else
		{
			Center = Left + Budao;
			if (Center > 128) Center = 128;
			if (Center < (Right + Left) / 2) Center = (Right + Left) / 2;
		}
	}

	if (Left == 6 && Right != 122)
	{
		for (i = saoxian; i >= 6; i--)
		{
			Left = i;
			if (Pixel[i + 4] - Pixel[i] >= 8 && Pixel[i + 5] - Pixel[i + 1] >= 8 && Pixel[i] <= AverageValue) break;
		}
		if (Left != 6) Center = (Right + Left ) / 2;
		else
		{
			if (Right >= Budao) Center = Right - Budao;
			else Center = 0;
			if (Center > (Right + Left) / 2) Center = (Right + Left) / 2;
		}
	}
	
	if (Left != 6 && Right != 122) Center = (Right + Left) / 2;
			
	if (Left == Right)
	{
		if (flag_black == 0) flag_miss = 1;
	}		
	if (flag_miss == 1)
	{
			for (i = saoxian;i <= 122;i++)
		{
			Right = i;
			if (Pixel[i - 8] - Pixel[i] >= 10 && Pixel[i - 9] - Pixel[i - 1] >= 10 && Pixel[i] <= AverageValue)
			{
				flag_miss = 0;
				break;
			}
		}
		for (i = saoxian;i >= 6;i--)
		{
			Left = i;
			if (Pixel[i + 8] - Pixel[i] >= 10 && Pixel[i + 9] - Pixel[i + 1] >= 10 && Pixel[i] <= AverageValue)
			{
				flag_miss = 0;
				break;
			}
		}
		if (Left != 6 && Right == 122)
		{
			Center = Left + Budao;
			if (Center > 128) Center = 128;
			if (Center < (Right + Left) / 2) Center = (Right + Left) / 2;
		}

		if (Left == 6 && Right != 122)  
		{
			if (Right >= Budao) Center = Right - Budao;
			else Center = 0;
			if (Center > (Right + Left) / 2) Center = (Right + Left) / 2;
		}
		if (Left != 6 && Right != 122) Center = (Right + Left) / 2;
		
		if (Left == Right)
		{
			flag_black = 1;
			flag_miss = 0;
			if (CenterLast[0] <= 63) FTMDuty = 4910 - (63 - CenterLast[0])*(63 - CenterLast[0]) * a1 / 10;
			if (CenterLast[0] >= 64) FTMDuty = 4910 + (CenterLast[0] - 64)*(CenterLast[0] - 64) * a2 / 10;
		}
	}
	
	if (Right == Left)
	{
		Left = LeftLast;
		Right = RightLast;
		Center = (Left + Right) / 2;
	}
	
	if (Center > 44 && Center <88 && CenterLast[0] > 44 && CenterLast[0] < 88 )
	{
		leixin = 0;//zhidao 
	}
	
	if ((Center <= 44 && Left <= 13) || (Center >=84 && Right >= 115))
	{
		leixin = 1;//wandao
	}
	
	/*********************************************************************/	

	LeftLast  = Left;
	RightLast = Right;

	CenterLast[1] = CenterLast[0];
	CenterLast[0] = Center;
	
	saoxian = Center;

	if (saoxian >= 122)  saoxian = 122;
	if (saoxian <= 6) 	 saoxian = 6;
	if (Center  >= 122)   Center = 122;
	if (Center  <= 6) 	  Center = 6;
	
	if (Center <= 63) FTMDuty = 4910 - (63 - Center)*(63 - Center) * a1 / 10;
	if (Center >= 64) FTMDuty = 4910 + (Center - 64)*(Center - 64) * a2 / 10;
	
	if (FTMDuty <= 4000) FTMDuty = 4000;
	if (FTMDuty >= 5800) FTMDuty = 5800;
	
	FTM_PWM_ChangeDuty(FTM0_CH4_PA7,FTMDuty);
}
Exemple #15
0
/*****************************
*
*  函数名称CCD_HeiXian
*  功能说明:采集黑线位置进行黑线点数计算
*  参数说明:
*  函数返回:无
*  修改时间:
*  备    注:
*************************************************************************/
void CCD_HeiXian(void)
{
	uint8_t i,value_max,value_min,x1,x2;
	
	value_max = Pixel[0];
	for (i = 2;i < 126;i++) 
  {
    if (value_max <= Pixel[i]) value_max = Pixel[i];
  }
	value_min = Pixel[0];
	for (i = 2;i < 126;i++) 
  {
    if (value_min >= Pixel[i]) value_min = Pixel[i];
  }
	AverageValue = (value_max + value_min * 2) / 3;

	for (i = saoxian;i <= 122;i++)
	{
		Right = i;
		if (Pixel[i - 2] - Pixel[i] >= 8 && Pixel[i - 3] - Pixel[i - 1] >= 8 && Pixel[i] <= AverageValue) break;
	}
	for (i = saoxian;i >= 6;i--)
	{
		Left = i;
		if (Pixel[i + 2] - Pixel[i] >= 8 && Pixel[i + 3] - Pixel[i + 1] >= 8 && Pixel[i] <= AverageValue) break;
	}
	if (Left != 6 && Right != 122 && leixin == 0) Budao = (Right - Left) / 2;
	
/***********************buxianchuli*************************************/
	
	if (Left != 6 && Right == 122)
	{
		for (i = saoxian; i <= 122; i++)
		{
			Right = i;
			if (Pixel[i - 4] - Pixel[i] >= 8 && Pixel[i - 5] - Pixel[i - 1] >= 8 && Pixel[i] <= AverageValue) break;
		}
		if (Right != 122) Center = (Right + Left) / 2;
		else
		{
			Center = Left + Budao;
			if (Center > 128) Center = 128;
			if (Center < (Right + Left) / 2) Center = (Right + Left) / 2;
		}
	}

	if (Left == 6 && Right != 122)
	{
		for (i = saoxian; i >= 6; i--)
		{
			Left = i;
			if (Pixel[i + 4] - Pixel[i] >= 8 && Pixel[i + 5] - Pixel[i + 1] >= 8 && Pixel[i] <= AverageValue) break;
		}
		if (Left != 6) Center = (Right + Left ) / 2;
		else
		{
			if (Right >= Budao) Center = Right - Budao;
			else Center = 0;
			if (Center > (Right + Left) / 2) Center = (Right + Left) / 2;
		}
	}
	
	if (Left != 6 && Right != 122) Center = (Right + Left) / 2;
	
	/*************************heixianchuli*****************************************/
	
	if (Left == 6 && Right == 122 && AverageValue <= 90)
	{
		if (CenterLast[0] <= 63) Center = 10;
		if (CenterLast[0] >  63) Center = 110;
		leixin = 1;
	}
	
	/***************************shizhichuli*********************************************/

	if (AverageValue >= a4 && Left <= 8 && Right >= 120 && Cross_flag_wan == 1 && AverageValue <= 200)
	{
		Cross_flag = 0;
	}
	if (AverageValue >= a4 && Left <= 8 && Right >= 120 && Cross_flag_wan == 0 && AverageValue <= 200)
	{
		Cross_flag = 1;
	}
	if (Cross_flag)
	{
		x1 = x2 = a3;
		if (leixin == 1) Cross_flag_wan = 1;
		if (leixin == 0 && leixin_last == 0) 
		{
			Cross_flag_wan = 0;
			Cross_flag 		 = 0;
		}
	}
	else
	{
		x1 = a1;
		x2 = a2;
		if (leixin == 0) Cross_flag_wan = 0;
	}
	
	/*******************************leixin************************************/	
	
	if (Center > 44 && Center < 88 && CenterLast[0] > 44 && CenterLast[0] < 88)
	{
		leixin = 0;//zhidao 
		jiansuflag = 0;
	}
	
	if ((Center <= 44 && Left <= 13) || (Center >=84 && Right >= 115))
	{
		leixin = 1;//wandao
		jiasuflag = 0;
	}
	
	/****************************************************************************/
	
	CenterLast[1] = CenterLast[0];
	CenterLast[0] = Center;

	leixin_last = leixin;
	
	if (Center  >= 122)   Center = 122;
	if (Center  <= 6) 	  Center = 6;
	
	saoxian = Center;
	
	if (Cross_flag)
	{
		if (Center <= 63) FTMDuty = 4896 - (63 - Center) * x1;
		if (Center >= 64) FTMDuty = 4896 + (Center - 64) * x2;
		
		if (FTMDuty <= 4000) FTMDuty = 4000;
		if (FTMDuty >= 5800) FTMDuty = 5800;
	}
	else
	{
		if (Center <= 63) FTMDuty = 4910 - (63 - Center)*(63 - Center) * x1 / 10;
		if (Center >= 64) FTMDuty = 4910 + (Center - 64)*(Center - 64) * x2 / 10;
		
		if (FTMDuty <= 4000) FTMDuty = 4000;
		if (FTMDuty >= 5800) FTMDuty = 5800;
	}
	FTM_PWM_ChangeDuty(FTM0_CH4_PA7,FTMDuty);
}
Exemple #16
0
/*****************************
*
*  函数名称CCD_HeiXian
*  功能说明:采集黑线位置进行黑线点数计算
*  参数说明:
*  函数返回:无
*  修改时间:
*  备    注:
*************************************************************************/
void CCD_HeiXian(void)
{
	uint8_t i,j;
	j = 0;
	for(i = 0;i < 128;i++)
	{
		if(Pixel[i] == 255)
		{
			if(j == 0)
			{
				Left = i;
				Right = i;
				j = 1;
			}
			else
			{
			  if(i < Left)  Left = i;
			  if(i > Right) Right = i;
		 }
		}
	}
	if(Left!=0||Right!=0)
	{
		Center = (Left + Right) / 2;
	if(Center <= 63)
	{
		if (63 - Center <= 5)											FTMDuty = 4700 + (63 - Center) * a1;
		if (63 - Center <= 10 && 63 - Center > 5) FTMDuty = 4700 + (63 - Center) * a2;
		if (63 - Center < 15 && 63 - Center > 10) FTMDuty = 4700 + (63 - Center) * a3;
		if (63 - Center >= 15)										FTMDuty = 4700 + (63 - Center) * a4;
		FTM_PWM_ChangeDuty(FTM0_CH4_PA7,FTMDuty);
		if(FTMDuty >= 5900) FTMDuty = 5900;
	}
	if(Center >= 64)
	{
		if (Center - 64 < 5)											 FTMDuty = 4700 - (Center - 64) * a1;
		if (Center - 64 <= 10 && Center - 64 >= 5) FTMDuty = 4700 - (Center - 64) * a2;
		if (Center - 64 < 15 && Center - 64 > 10)  FTMDuty = 4700 - (Center - 64) * a3;
		if (Center - 64 >= 15)										 FTMDuty = 4700 - (Center - 64) * a4;

		FTM_PWM_ChangeDuty(FTM0_CH4_PA7,FTMDuty);
		if(FTMDuty <= 3700) FTMDuty = 3700;
	}
	c=Center;
	}
//	for(i=63;i>0;i--)
//	{
//		if(Pixel[i] == 0)
//			Left = i;
//	}
//	for(i = 63;i < 127;i++)
//	{
//		if(Pixel[i] == 0)
//			Right = i;
//	}
//	Center = (Left + Right) / 2;
//	if(Center <= 63)
//	{
//		if (63 - Center < 5)
//		{
//			FTMDuty = 4350 - (63 - Center) * a1;
//		}
//		if (63 - Center <= 10 && 63 - Center >= 5)
//		{
//			FTMDuty = 4350 - (63 - Center) * a2;
//		}
//		if (63 - Center < 15 && 63 - Center > 10)
//		{
//			FTMDuty = 4350 - (63 - Center) * a3;
//		}
//		if (63 - Center >= 15)
//		{
//			FTMDuty = 4350 - (63 - Center) * a4;
//		}

//		FTM_PWM_ChangeDuty(FTM2_CH0_PA10,FTMDuty);
//		if(FTMDuty <= 3500) FTMDuty = 3500;
//	}
//	if(Center >= 64)
//	{
//		if (Center - 64 < 5)
//		{
//			FTMDuty = 4350 + (Center - 64) * a1;
//		}
//		if (Center - 64 <= 10 && Center - 64 >= 5)
//		{
//			FTMDuty = 4350 + (Center - 64) * a2;
//		}
//		if (Center - 64 < 15 && Center - 64 > 10)
//		{
//			FTMDuty = 4350 + (Center - 64) * a3;
//		}
//		if (Center - 64 >= 15)
//		{
//			FTMDuty = 4350 + (Center - 64) * a4;
//		}

//		FTM_PWM_ChangeDuty(FTM2_CH0_PA10,FTMDuty);
//		if(FTMDuty >= 5300) FTMDuty = 5300;
//	}
	
//	c=Center;
}
Exemple #17
0
/******************************主界面显示********************************/
void Menu_Init(void)
{
	OLED_Write_Char(0, yiwei(i,i), 43);
	OLED_Write_String(2,yiwei(0,i),"AI ");
	OLED_Write_String(2,yiwei(2,i),"BI ");
	OLED_Write_String(2,yiwei(4,i),"CI ");
	OLED_Write_String(2,yiwei(6,i),"DI ");
	OLED_Write_String(2,yiwei(8,i),"F1 ");
	OLED_Write_String(2,yiwei(10,i),"F2 ");
	OLED_Write_String(2,yiwei(12,i),"SD ");
	OLED_Write_Num2(7,yiwei(0,i),a1);
	OLED_Write_String(9,yiwei(0,i),"  ");
	OLED_Write_Num2(7,yiwei(2,i),a2);
	OLED_Write_String(9,yiwei(2,i),"  ");
	OLED_Write_Num2(7,yiwei(4,i),a3);
	OLED_Write_String(9,yiwei(4,i),"  ");
	OLED_Write_Num2(7,yiwei(6,i),a4);
	OLED_Write_String(9,yiwei(6,i),"  ");
	OLED_Write_Num4(7,yiwei(8,i),FTMDuty_1);
	OLED_Write_Num4(7,yiwei(10,i),FTMDuty_2);
	OLED_Write_String(7,yiwei(12,i),"    ");
	
	//上移
	if(Key_up == 0)
	{
		DelayMs(100);
		if(Key_up == 0)
		{
			OLED_Write_Char(0,yiwei(i,i), ' ');
			i = i - 2;
			if(i == -2) i = 12;
		}
	}
	
	//下移
	if(Key_down == 0)
	{
		DelayMs(100);
		if(Key_down == 0)
		{
			OLED_Write_Char(0,yiwei(i,i), ' ');
			i = i + 2;
			if(i == 14) i = 0;
		}
	}
	
	//a1
	if(yiwei(i,i) == yiwei(0,i))
	{
		//加
		if(Key_right == 0)
		{
			DelayMs(50);
			if(Key_right == 0)
			{
				a1++;
				if(a1 >= 50) a1 = 0;
			}
		}
		//减
		if(Key_left == 0)
		{
			DelayMs(50);
			if(Key_left == 0)
			{
				a1--;
				if(a1 <= 0) a1 = 50;
			}
		}
	}
	//a2
	if(yiwei(i,i) == yiwei(2,i))
	{
		//加
		if(Key_right == 0)
		{
			DelayMs(50);
			if(Key_right == 0)
			{
				a2++;
				if(a2 >= 50) a2 = 0;
			}
		}
		//减
		if(Key_left == 0)
		{
			DelayMs(50);
			if(Key_left == 0)
			{
				a2--;
				if(a2 <= 0) a2 = 50;
			}
		}
	}
	//a3
	if(yiwei(i,i) == yiwei(4,i))
	{
		//加
		if(Key_right == 0)
		{
			DelayMs(50);
			if(Key_right == 0)
			{
				a3++;
				if(a3 >= 50) a3 = 0;
			}
		}
		//减
		if(Key_left == 0)
		{
			DelayMs(50);
			if(Key_left == 0)
			{
				a3--;
				if(a3 <= 0) a3 = 50;
			}
		}
	}
	//a4
	if(yiwei(i,i) == yiwei(6,i))
	{
		//加
		if(Key_right == 0)
		{
			DelayMs(50);
			if(Key_right == 0)
			{
				a4++;
				if(a4 >= 50) a4 = 0;
			}
		}
		//减
		if(Key_left == 0)
		{
			DelayMs(50);
			if(Key_left == 0)
			{
				a4--;
				if(a4 <= 0) a4 = 50;
			}
		}
	}

	//FTMDuty_1
	if(yiwei(i,i) == yiwei(8,i))
	{
		//加
		if(Key_right == 0)
		{
			DelayMs(50);
			if(Key_right == 0)
			{
				FTMDuty_1 += 50;
				if(FTMDuty_1 >= 3000) FTMDuty_1 = 3000;
			}
		}
		//减
		if(Key_left == 0)
		{
			DelayMs(50);
			if(Key_left == 0)
			{
				FTMDuty_1 -= 50;
				if(FTMDuty_1 <= 0) FTMDuty_1 = 0;
			}
		}
	}
	
	//FTMDuty_2
	if(yiwei(i,i) == yiwei(10,i))
	{
		//加
		if(Key_right == 0)
		{
			DelayMs(50);
			if(Key_right == 0)
			{
				FTMDuty_2 += 50;
				if(FTMDuty_2 >= 3000) FTMDuty_2 = 3000;
			}
		}
		//减
		if(Key_left == 0)
		{
			DelayMs(50);
			if(Key_left == 0)
			{
				FTMDuty_2 -= 50;
				if(FTMDuty_2 <= 0) FTMDuty_2 = 0;
			}
		}
	}
	
	//SD
	if(yiwei(i,i) == yiwei(12,i))
	{
		if(Key_right == 0)
		{
			DelayMs(50);
			if(Key_right == 0)
			{
				OLED_Clear();
				SD_D = 0;
				flag_sd_d = 1;
			}
		}
	}
	//打开ccd测试
	if(Key_2 == 0)
	{
		DelayMs(100);
		if(Key_2 == 0)
		{
			OLED_Clear();
			flag_test = 1;
			SD_X = 0;
			PIT_Start(PIT1);
			FTM_PWM_ChangeDuty(FTM0_CH3_PA6,FTMDuty_1);
		}
	}
	//发车
	if(Key_1 == 0)
	{
		DelayMs(50);
		if(Key_1 == 0)
		{
			OLED_Clear();
			flag_run = 1;
			PIT_Start(PIT1);
			FTM_PWM_ChangeDuty(FTM0_CH3_PA6,FTMDuty_1);
		}
	}
	
}
Exemple #18
0
int main(void)
{

	SystemClockSetup(ClockSource_EX50M,CoreClock_100M);
	DelayInit();
	OLED_Init();
	Sd_Init();
	chuinit_Init();
	DataInit();
	Data_Uart_Init();
	
	while(1)
	{
		Menu_Init();
		//ccd测试
		while(Flag == 1)
		{
			if(TIME1flag_20ms == 1)
			{
				TIME1flag_20ms = 0;
				ImageCapture(P1);
//				Sd_X();
//				Sd_D();
//				UART_Send_Con();
				oled_collect();
				oled_show();
			}
			CCD_HeiXian();
			OLED_ZhongXian();
			OLED_Write_Num3(4,0,Center);
			OLED_Write_Num3(0,0,Left);
			OLED_Write_Num3(9,0,Right);
			OLED_Write_Num3(0,2,AverageValue);

			if(Key_1 == 0) //发车
			{
				DelayMs(100);
				if(Key_1 == 0)
				{
					OLED_Clear();
					Flag = 2;
					SD_X = 0;
					PIT_Start(PIT1);
				}
			}
			if(Key_down == 0) //菜单
			{
				DelayMs(100);
				if(Key_down == 0)
				{
					OLED_Clear();
					Flag = 0;
					PIT_Stop(PIT1);
					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
					FTM_PWM_ChangeDuty(FTM1_CH1_PB1,0);
				}
			}
			if(Key_up == 0) //SD 发车
			{
				DelayMs(100);
				if(Key_up == 0)
				{
					SD_Flag = !SD_Flag;
					if(SD_Flag) OLED_Write_String(2,2,"SD running");
					else 				OLED_Write_String(2,2,"SD stopping");
				}
			}
			if(Key_right == 0) //上位机
			{
				DelayMs(100);
				if(Key_right == 0)
				{
					while(1)
					{
						OLED_Clear();
						Sd_D();
						UART_Send_Con();
					}
				}
			}
		}
		
	//发车
		while(Flag == 2)
		{
			if(TIME1flag_20ms == 1)
			{
				TIME1flag_20ms = 0;
				ImageCapture(P1);
				Sd_X();
			}
			CCD_HeiXian();
			if(leixin == 0)
			{
				if (jiasuflag <= jiasu_Num) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,5000);
				else 								 				FTM_PWM_ChangeDuty(FTM1_CH0_PB0,FTMDuty_1);
			}
			if(leixin == 1) 
			{
				if (jiansuflag <= jiansu_Num)
				{
					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
					FTM_PWM_ChangeDuty(FTM1_CH1_PB1,100);
				}
//				else if(zhidaoflag_save < 200 && jiansuflag <= a6)
//				{
//					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
//				}
				else FTM_PWM_ChangeDuty(FTM1_CH0_PB0,FTMDuty_2);
			}
			if(Key_down == 0) //菜单
			{
				DelayMs(100);
				if(Key_down == 0)
				{
					OLED_Clear();
					Flag = 0;
					PIT_Stop(PIT1);
					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
					FTM_PWM_ChangeDuty(FTM1_CH1_PB1,0);
				}
			}
		}
	}
}
Exemple #19
0
/*****************************
*
*  函数名称CCD_HeiXian
*  功能说明:采集黑线位置进行黑线点数计算
*  参数说明:
*  函数返回:无
*  修改时间:
*  备    注:
*************************************************************************/
void CCD_HeiXian(void)
{
	uint8_t i;
	for(i = Saoxian;i <= 120;i++)
	{
		Right = i;
		if(Pixel[i] == 0) break;
	}
	for(i = Saoxian;i >= 12;i--)
	{
		Left = i;
		if(Pixel[i] == 0) break;
	}
	if (Left != 12 && Right != 120) Budao = (Right - Left) / 2;
	if (Left != 12 && Right == 120)
		{
				for (i = Saoxian; i <= 120; i++)
				{
						Right = i;
						if(Pixel[i] == 0) break;
				}
				if(Right != 120) Center = (Right + Left) / 2;
				else
				{
				  Center = Left + Budao;
					if (Center > 128) Center = 128;
					if (Center < (Right + Left) / 2) Center = (Right + Left) / 2;
			}
		}

	if (Left == 12 && Right != 120)  
		{
				for (i = Saoxian; i >= 12; i--)
				{
						Left = i;
						if(Pixel[i] == 0) break;
				}
				if(Left != 12) Center = (Right + Left ) / 2;
				else
				{
					if (Right >= Budao) Center = Right - Budao;
					else Center = 0;
					if (Center > (Right + Left) / 2) Center = (Right + Left) / 2;
			}
		}
		
	if (Left != 12 && Right != 120) Center = (Right + Left) / 2;

	if(Center <= 63)
	{
		if(63 - Center <= 7)											FTMDuty = 4700 + (63 - Center) * a1;
		if(63 - Center <= 15 && 63 - Center > 7)  FTMDuty = 4700 + (63 - Center) * a2;
		if(63 - Center <= 25 && 63 - Center > 15) FTMDuty = 4700 + (63 - Center) * a3;
		if(63 - Center <= 40 && 63 - Center > 25) FTMDuty = 4700 + (63 - Center) * a4;
		if(63 - Center >  40)											FTMDuty = 4700 + (63 - Center) * a5;
		
		FTM_PWM_ChangeDuty(FTM0_CH4_PA7,FTMDuty);
		if(FTMDuty >= 5900) FTMDuty = 5900;
	}
	if(Center >= 64)
	{
		if (Center - 64 <= 7)											 FTMDuty = 4700 - (Center - 64) * a1;
		if (Center - 64 <= 15 && Center - 64 > 7)  FTMDuty = 4700 - (Center - 64) * a2;
		if (Center - 64 <= 25 && Center - 64 > 15) FTMDuty = 4700 - (Center - 64) * a3;
		if (Center - 64 <= 40 && Center - 64 > 25) FTMDuty = 4700 - (Center - 64) * a4;
		if (Center - 64 >  40)    								 FTMDuty = 4700 - (Center - 64) * a5;

		FTM_PWM_ChangeDuty(FTM0_CH4_PA7,FTMDuty);
		if(FTMDuty <= 3700) FTMDuty = 3700;
	}
	Saoxian = Center;
	OLED_Write_Num3(0,0,Center);
	OLED_Write_Num3(4,0,Left);
	OLED_Write_Num3(9,0,Right);
}
Exemple #20
0
/**
  * @brief  鍏抽棴sin涓柇锛屽叧闂璓WM 
  * @param  None
  * @retval None
  */
void AD7687_StopConver (void)
{
	NVIC_DisableIRQ (AD7687_SIN_IRQ);
	FTM_PWM_ChangeDuty(FTM1_CH1_PB1,0);
}
Exemple #21
0
/**
  * @brief  When SDI and CNV are low, SDO is driven low. With SCK 
  *			high, a rising edge on CNV initiates a conversion.
  *			寮�鍚疨WM锛屽苟镓揿紑SIN镄勪笂鍗囨部涓柇
  *
  * @param  None
  * @retval None
  */
void AD7687_StartConver (void)
{
	FTM1->CNT = 0;
	FTM_PWM_ChangeDuty(FTM1_CH1_PB1,FTM_DUTY);
	NVIC_EnableIRQ (AD7687_SIN_IRQ);
}
Exemple #22
0
/*****************************
*
*  函数名称CCD_HeiXian
*  功能说明:采集黑线位置进行黑线点数计算
*  参数说明:
*  函数返回:无
*  修改时间:
*  备    注:
*************************************************************************/
void CCD_HeiXian(void)
{
	uint8_t i,x1,x2;
	for (i = saoxian;i <= 122;i++)
	{
		Right = i;
		if (Pixel[i] == 0) break;
	}
	for (i = saoxian;i >= 6;i--)
	{
		Left = i;
		if (Pixel[i] == 0) break;
	}
	if (Left != 6 && Right != 122 && leixin == 0) Budao = (Right - Left) / 2;
	
	/***********************buxianchuli*************************************/
	
	if (Left != 6 && Right == 122)
	{
		for (i = saoxian; i <= 122; i++)
		{
			Right = i;
			if (Pixel[i] == 0) break;
		}
		if (Right!= 122) Center = (Right + Left) / 2;
		else
		{
			Center = Left + Budao;
			if (Center > 128) Center = 128;
			if (Center < (Right + Left) / 2) Center = (Right + Left) / 2;
		}
	}

	if (Left == 6 && Right != 122)  
	{
		for (i = saoxian; i >= 6; i--)
		{
				Left = i;
				if(Pixel[i] == 0) break;
		}
		if (Left != 6) Center = (Right + Left ) / 2;
		else
		{
			if (Right >= Budao) Center = Right - Budao;
			else Center = 0;
			if (Center > (Right + Left) / 2) Center = (Right + Left) / 2;
		}
	}
	
	if (Left != 6 && Right != 122) Center = (Right + Left) / 2;
	
	/***********************heixian***************************/
	
//	if (Right == Left)
//	{
//		if (flag_black ==0) flag_miss = 1;
//	}
//	if (flag_miss == 1)
//	{
//		for (i = saoxian;i <= 122;i++)
//		{
//			Right = i;
//			if (Pixel[i] == 0)
//			{
//				flag_miss = 0;
//				break;
//			}
//		}
//		for (i = saoxian;i >= 6;i--)
//		{
//			Left = i;
//			if (Pixel[i] == 0)
//			{
//				flag_miss = 0;
//				break;
//			}
//		}
//		if (Left != 6 && Right == 122)
//		{
//			Center = Left + Budao;
//			if (Center > 128) Center = 128;
//			if (Center < (Right + Left) / 2) Center = (Right + Left) / 2;
//		}

//		if (Left == 6 && Right != 122)  
//		{
//			if (Right >= Budao) Center = Right - Budao;
//			else Center = 0;
//			if (Center > (Right + Left) / 2) Center = (Right + Left) / 2;
//		}
//		
//		if (Left != 6 && Right != 122) Center = (Right + Left) / 2;
		
		if (Right == Left)
		{
//			flag_black = 0;
//			flag_miss = 0;
			if (CenterLast[0] <  63) Center = 10;
			if (CenterLast[0] >= 63) Center = 118;
		}
//	}
	
	/*****************************shizhi*****************************************/
	
	if (Right ==122 && Left == 6 && Cross_flag_wan == 0 && Cross_flag == 0)
	{
		Cross_flag = 1;
		Center = 64;
	}
	if (Right ==122 && Left == 6 && Cross_flag_wan == 1 && Cross_flag == 1)
	{
		Cross_flag = 0;
		Center = 64;
	}
	if(Cross_flag)
	{
		x1 = x2 = a3;
		if (leixin == 1) Cross_flag_wan = 1;
	}
	else
	{
		x1 = a1;
		x2 = a2;
		if (leixin == 0) Cross_flag_wan = 0;
	}
	
	/*********************************************************************/	
	
	if (Center > 44 && Center <88 && CenterLast[0] > 44 && CenterLast[0] < 88 )
	{
		leixin = 0;//zhidao
		jiansuflag = 0;
	}
	
	if ((Center <= 44 && Left <= 13) || (Center >=84 && Right >= 115))
	{
		leixin = 1;//wandao
		jiasuflag = 0;
	}
	
	LeftLast  = Left;
	RightLast = Right;

	CenterLast[1] = CenterLast[0];
	CenterLast[0] = Center;
	
	if (Center  >= 122)  Center = 122;
	if (Center  <= 6) 	 Center = 6;
	
	saoxian = Center;
	if (Cross_flag == 0)
	{
		if (Center <= 63) FTMDuty = 4896 - (63 - Center)*(63 - Center) * x1 / 10;
		if (Center >= 64) FTMDuty = 4896 + (Center - 64)*(Center - 64) * x2 / 10;

		if (FTMDuty <= 4000) FTMDuty = 4000;
		if (FTMDuty >= 5800) FTMDuty = 5800;
		
		FTM_PWM_ChangeDuty(FTM0_CH4_PA7,FTMDuty);
	}
	if (Cross_flag == 1)
	{
		if (Center <= 63) FTMDuty = 4896 - (63 - Center) * x1 / 10;
		if (Center >= 64) FTMDuty = 4896 + (Center - 64) * x2 / 10;

		if (FTMDuty <= 4000) FTMDuty = 4000;
		if (FTMDuty >= 5800) FTMDuty = 5800;
		
		FTM_PWM_ChangeDuty(FTM0_CH4_PA7,FTMDuty);
	}

}
Exemple #23
0
int main(void)
{
	unsigned char i;          
	unsigned char Send_Count; 
	uint32_t DMA_Value0 = 0;
	uint32_t DMA_Value1 = 0;
	PIT_InitTypeDef PIT_InitStruct1;
	GPIO_InitTypeDef GPIO_InitStruct1;
	FTM_InitTypeDef FTM_InitStruct1;
	DMACNT_InitTypeDef DMACNT_InitStruct1;
	SystemClockSetup(ClockSource_EX50M,CoreClock_100M);
	UART_DebugPortInit(UART0_RX_PA14_TX_PA15,115200);
	DisplayCPUInfo();
	DelayInit();
	OLED_Init();
	DMACNT_InitStruct1.DMACNT_Mode = DMACNT_MODE_FALLING;  //ÉÏÉýÑؼÆÊý
	DMACNT_InitStruct1.DMA_Chl = DMA_CH0;                 //ʹÓÃͨµÀ 0
	DMACNT_InitStruct1.GPIOx = PTC;                       //PTC5
	DMACNT_InitStruct1.GPIO_Pin = GPIO_Pin_5; 
	DMACNT_Init(&DMACNT_InitStruct1);

	GPIO_InitStruct1.GPIO_Pin = GPIO_Pin_0;
	GPIO_InitStruct1.GPIO_InitState = Bit_RESET;
	GPIO_InitStruct1.GPIO_IRQMode = GPIO_IT_DISABLE;
	GPIO_InitStruct1.GPIO_Mode = GPIO_Mode_OPP;
	GPIO_InitStruct1.GPIOx = PTB;
	GPIO_Init(&GPIO_InitStruct1);
	
	GPIO_InitStruct1.GPIO_Pin = GPIO_Pin_1;
	GPIO_InitStruct1.GPIO_InitState = Bit_SET;
	GPIO_InitStruct1.GPIOx = PTB;
	GPIO_Init(&GPIO_InitStruct1);
	
	PIT_InitStruct1.PITx=PIT2;
	PIT_InitStruct1.PIT_Interval=100;
	PIT_Init(&PIT_InitStruct1);
	NVIC_EnableIRQ(PIT2_IRQn);
	PIT_ITConfig(PIT2,PIT_IT_TIF,ENABLE);
	
	PIT_InitStruct1.PITx=PIT0;
	PIT_InitStruct1.PIT_Interval=20000;
	PIT_Init(&PIT_InitStruct1);
	PIT_ITConfig(PIT0,PIT_IT_TIF,ENABLE);
	NVIC_EnableIRQ(PIT0_IRQn);
	FTM_InitStruct1.Frequency = 800;
	FTM_InitStruct1.FTM_Mode = FTM_Mode_EdgeAligned;
//	FTM_InitStruct1.InitalDuty = 10000;
	FTM_InitStruct1.FTMxMAP = FTM0_CH0_PC1;
	FTM_Init(&FTM_InitStruct1);
	UART_printf("DMACNT_CH0_Value:%d \n",*Pid_Out);


	while(1)
	{
//		if(key_detect1()){
//			Pid_Set += 500;
//		}
//		if(key_detect3()){
//			Pid_Set -= 500;
//		}
		GPIO_ResetBits(PTB,GPIO_Pin_0);
		PidError[2] = Pid_Set - *Pid_Out;
		PidOut =  Kp * (PidError[2] - PidError[1]);
		PidOut += Ki *  PidError[2] * Td;
		PidOut += Kd * (PidError[2] - 2 * PidError[1] + PidError[0]) / Td;
		PidError[0] = PidError[1];
		PidError[1] = PidError[2];
		PID_FinalOut =PidOut*2;
		
		
//		
//		if(key_detect5()){
//			Kd+=0.2;OLED_Clear();
//		}
//		else if(key_detect6()){
//			Kd-=0.2;OLED_Clear();
//		}
//		
//		OLED_Write_String(2,0,"Kp");
//		OLED_Write_String(2,2,"Ki");
//		OLED_Write_String(2,4,"Kd");
//		OLED_Write_Num3(6,0,Kp*10);
//		OLED_Write_Num3(6,2,Ki*10);
//		OLED_Write_Num3(6,4,Kd*10);
//		OLED_Write_Num4(9,6,*Pid_Out-1000);
//		
		
		if(PID_FinalOut>10000) PID_FinalOut=10000;
		else if(PID_FinalOut<0) PID_FinalOut=0;
		
		FTM_PWM_ChangeDuty(FTM0_CH0_PC1,PID_FinalOut);
		
	}
}
Exemple #24
0
int main(void)
{

	SystemClockSetup(ClockSource_EX50M,CoreClock_100M);
	DelayInit();
	OLED_Init();
	Sd_Init();
	chuinit_Init();
	DataInit();
	Data_Uart_Init();
	
	while(1)
	{
		Menu_Init();
		//ccd测试
		while(Flag == 1)
		{
			if(TIME1flag_20ms==1)
			{
				TIME1flag_20ms=0;
				ImageCapture(Pixel);
//				Sd_X();
//				Sd_D();
//				UART_Send_Con();
				erzhi();
				LB();
				oled_collect();
				oled_show();
			}
			CCD_HeiXian();
			OLED_ZhongXian();
			if(Key_1 == 0) //发车
			{
				DelayMs(100);
				if(Key_1 == 0)
				{
					OLED_Clear();
					Flag = 2;
					SD_X = 0;
					PIT_Start(PIT1);
				}
			}
			if(Key_down == 0) //菜单
			{
				DelayMs(100);
				if(Key_down == 0)
				{
					OLED_Clear();
					Flag = 0;
					PIT_Stop(PIT1);
					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
				}
			}
		}
		
	//发车
		while(Flag == 2)
		{
			if(TIME1flag_20ms==1)
			{
				TIME1flag_20ms=0;
				ImageCapture(Pixel);
				erzhi();
				LB();
//				Sd_X();
			}
			CCD_HeiXian();
			if(Center - 64 >= 7 || 63 - Center >= 7) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,FTMDuty_2);
			if(Center - 64 <= 7 || 63 - Center >= 7) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,FTMDuty_1);
			if(Key_down == 0)//菜单
			{
				DelayMs(100);
				if(Key_down == 0)
				{
					OLED_Clear();
					Flag = 0;
					PIT_Stop(PIT1);
					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
				}
			}
		}
//			while(SD_Flag)
//			{
//				Sd_D();
//				UART_Send_Con();
//			}
	}
}