//大舵机2.5%-12.5%满占空比调节 270度左右 PWM设置25-125 //一般舵机7%为中间值,4.5%-10%左右范围 void stepperMoterInit() { TIM5_Init();//左边的电机前四个 TIM8_Init();//用于手爪的吸力电机 TIM4_Init();//右边的电机前四个 TIM1_Init(); }
void vidInit(void) { /*Populate DMA_TEST*/ //int i=0; //int a=0xFF; /*for(i=0; i<100;i++){ if(i%2 != 0) DMA_TEST[0][i]=a; }*/ vidClearScreen(); TIM8_Init(); TIM_Configuration(); DMA_Config(); //TIM5_Init(); }
void DMA_Config(void){ NVIC_InitTypeDef NVIC_InitStructure; DMA_InitTypeDef DMA_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; __IO uint32_t Timeout = 50000; //int i; /* Enable DMA clock & TIM3 Clock*/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); /*Enable GPIOB Pins as digital output*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_High_Speed; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB,&GPIO_InitStructure); TIM8_Init(); /* Reset DMA Stream registers (for debug purpose) */ DMA_DeInit(DMA2_Stream2); /* Configure DMA Stream */ DMA_InitStructure.DMA_Channel = DMA_Channel_7; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(GPIOB->ODR); //;0x40000010 &(GPIOB->ODR)//dest DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)fb; //source TAVA fb DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; DMA_InitStructure.DMA_BufferSize = (uint32_t)VID_HSIZE+2; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_INC16; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA2_Stream1, &DMA_InitStructure); /* Enable DMA Stream Transfer Complete interrupt */ DMA_ITConfig(DMA2_Stream1, DMA_IT_TC, ENABLE); DMA_Cmd(DMA2_Stream1,ENABLE); /* Enable DAC Channel2 */ Timeout = 50000; while ((DMA_GetCmdStatus(DMA2_Stream1) != ENABLE) && (Timeout-- > 0)) { } /* Check if a timeout condition occurred */ if (Timeout == 0) { /* Manage the error: to simplify the code enter an infinite loop */ while (1) { } } DMA2->LIFCR = 0xC40; /* Enable the DMA Stream IRQ Channel */ NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //TIM_Cmd(TIM8,ENABLE); }