有没有做平衡小车 遇到编码程序与控制程序冲突的

2019-07-20 07:30发布

求解  屏蔽了编码程序  直立控制就能用     不屏蔽控制直接凉了 不起作用

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
Z一叶孤舟
2019-07-20 11:35
#include "encoder.h"
#include "usart.h"

///**************************************************************************
//º¯Êý¹¦ÄÜ£ºTIM3ÖжϷþÎñº¯Êý
//Èë¿Ú²ÎÊý£ºÎÞ
//·µ»Ø  Öµ£ºÎÞ
//**************************************************************************/
void TIM3_IRQHandler(void)
{                  
if(TIM3->SR&0X0001)//Òç³öÖжÏ
{                           
}      
TIM3->SR&=~(1<<0);//&Ccedil;&aring;&sup3;&yacute;&Ouml;&ETH;&para;&Iuml;±ê&Ouml;&frac34;&Icirc;&raquo;      
}
/*****************************************************************************/
void Encoder_L_Init_TIM3(void)//×ó±&szlig;±à&Acirc;&euml;&AElig;÷&micro;&Auml;&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;
{

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;  
TIM_ICInitTypeDef TIM_ICInitStructure;  
GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);   //TIM12&Ecirc;±&Ouml;&Oacute;&Ecirc;&sup1;&Auml;&Uuml;   
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);  //&Ecirc;&sup1;&Auml;&UumlORTB&Ecirc;±&Ouml;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);  

GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_TIM3);   
  GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_TIM3);   

TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
     
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;      
  TIM_TimeBaseStructure.TIM_Period = ENCODER_TIM_PERIOD;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);  

TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
  TIM_ICStructInit(&TIM_ICInitStructure);
  TIM_ICInitStructure.TIM_ICFilter = 0;
  TIM_ICInit(TIM3, &TIM_ICInitStructure);

TIM_ClearFlag(TIM3, TIM_FLAG_Update);
  TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
  TIM_Cmd(TIM3, ENABLE);
}
/****************************************************************************************/
void Encoder_R_Init_TIM4(void)//&Oacute;&Ograve;±&szlig;±à&Acirc;&euml;&AElig;÷&micro;&Auml;&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;  
TIM_ICInitTypeDef TIM_ICInitStructure;  
GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);   //TIM12&Ecirc;±&Ouml;&Oacute;&Ecirc;&sup1;&Auml;&Uuml;   
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);  //&Ecirc;&sup1;&Auml;&UumlORTB&Ecirc;±&Ouml;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13;  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOD, &GPIO_InitStructure);  
  GPIO_PinAFConfig(GPIOD,GPIO_PinSource12,GPIO_AF_TIM4);   
  GPIO_PinAFConfig(GPIOD,GPIO_PinSource13,GPIO_AF_TIM4);   
  
  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
  
  TIM_TimeBaseStructure.TIM_Prescaler = 0x0;        
  TIM_TimeBaseStructure.TIM_Period = ENCODER_TIM_PERIOD;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);  
  
  TIM_EncoderInterfaceConfig(TIM4, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
  TIM_ICStructInit(&TIM_ICInitStructure);
  TIM_ICInitStructure.TIM_ICFilter = 0;
  TIM_ICInit(TIM4, &TIM_ICInitStructure);
  
  TIM_ClearFlag(TIM4, TIM_FLAG_Update);
  TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
  TIM_Cmd(TIM4, ENABLE);
}

/**********************************************************************************/
int Read_Encoder(u8 TIMX)//&para;&Aacute;&Egrave;&iexcl;±à&Acirc;&euml;&AElig;÷&frac14;&AElig;&Ecirc;&yacute;
{
  int Encoder_TIM;   
  switch(TIMX)
  {
  case 2:  Encoder_TIM= (short)TIM2 -> CNT;  TIM2 -> CNT=0;break;
  case 3:  Encoder_TIM= (short)TIM3 -> CNT;  TIM3 -> CNT=0;break;
  case 4:  Encoder_TIM= (short)TIM4 -> CNT;  TIM4 -> CNT=0;break;
  default:  Encoder_TIM=0;
  }
  return Encoder_TIM;
}


到底死在哪条程序上。。。

一周热门 更多>