用于EagleEye3.0 规则集漏报和误报测试的示例项目,项目收集于github和gitee
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.7 KiB

5 months ago
#include "stm32f10x.h"
#include "motor.h"
void MotorInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM1_TimeBase;
TIM_OCInitTypeDef TIM1_OC;
//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>GPIO PA12 13 14 15 <EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD><EFBFBD> //PA8 PA11 PWM
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //ʹ<EFBFBD><EFBFBD>AFIOʱ<EFBFBD><EFBFBD>
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable , ENABLE);//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>SW<EFBFBD><EFBFBD>JTAG <EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>GPIO<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_11 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
TIM1_TimeBase.TIM_Period = 99; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD>ؼĴ<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5000Ϊ500ms
TIM1_TimeBase.TIM_Prescaler =720-1; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>Ƶֵ 10Khz<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>
TIM1_TimeBase.TIM_ClockDivision = 0; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ӷָ<EFBFBD>:TDTS = Tck_tim
TIM1_TimeBase.TIM_CounterMode = TIM_CounterMode_Up; //TIM<EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><EFBFBD><EFBFBD>ģʽ
TIM_TimeBaseInit(TIM1, &TIM1_TimeBase);
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƚ<EFBFBD>
TIM1_OC.TIM_OCMode=TIM_OCMode_PWM1;
TIM1_OC.TIM_OCPolarity=TIM_OCPolarity_High;
TIM1_OC.TIM_OutputState=TIM_OutputState_Enable;
TIM1_OC.TIM_Pulse=0;
TIM_OC1Init(TIM1,&TIM1_OC);
TIM_OC4Init(TIM1,&TIM1_OC);
TIM_CtrlPWMOutputs(TIM1,ENABLE); //MOE <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>
//ʹ<EFBFBD><EFBFBD>Ԥװ<EFBFBD>ؼĴ<EFBFBD><EFBFBD><EFBFBD>
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC4PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM1, ENABLE);
TIM_Cmd(TIM1, ENABLE); //ʹ<EFBFBD><EFBFBD>TIM1
}
//ֹͣ
void Stop(void)
{
GPIO_ResetBits(GPIOA,GPIO_Pin_12);
GPIO_ResetBits(GPIOA,GPIO_Pin_13);
GPIO_ResetBits(GPIOA,GPIO_Pin_14);
GPIO_ResetBits(GPIOA,GPIO_Pin_15);
}
//ǰ<EFBFBD><EFBFBD>
void Turnfront(void)
{
GPIO_SetBits(GPIOA,GPIO_Pin_12);
GPIO_ResetBits(GPIOA,GPIO_Pin_13);
GPIO_SetBits(GPIOA,GPIO_Pin_14);
GPIO_ResetBits(GPIOA,GPIO_Pin_15);
}
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Turnback(void)
{
GPIO_ResetBits(GPIOA,GPIO_Pin_12);
GPIO_SetBits(GPIOA,GPIO_Pin_13);
GPIO_ResetBits(GPIOA,GPIO_Pin_14);
GPIO_SetBits(GPIOA,GPIO_Pin_15);
}
//<EFBFBD><EFBFBD>ת
void Turnleft(void)
{
GPIO_SetBits(GPIOA,GPIO_Pin_12);
GPIO_ResetBits(GPIOA,GPIO_Pin_13);
GPIO_ResetBits(GPIOA,GPIO_Pin_14);
GPIO_SetBits(GPIOA,GPIO_Pin_15);
}
//<EFBFBD><EFBFBD>ת
void Turnright(void)
{
GPIO_ResetBits(GPIOA,GPIO_Pin_12);
GPIO_SetBits(GPIOA,GPIO_Pin_13);
GPIO_SetBits(GPIOA,GPIO_Pin_14);
GPIO_ResetBits(GPIOA,GPIO_Pin_15);
}