无线节能组信标为什么会自动切换? 排查故障的过程真的像谜一样无法解释

 

01 存在的问题


1.问题描述

第十六届全国大学智能汽车竞赛竞速比赛 中的节能无线信标组中的 信标控制模块 在2021-04-10测试的时候发现存在以下问题:

问题描述: 当信标灯被串联在一起的时候,与主控制器相连,发现在进入测试状态的的时候,信标灯大约每隔一段时间就会自动切换到下一个信标。

这个自动切换的时间间隔大约是5秒钟。

▲ 测试中的信标灯在主控器控制下点亮

▲ 测试中的信标灯在主控器控制下点亮
他们会自动过一段时间自动完成切换

2.初步排除

(1)MCU固件排除

龙邱公司对于信标做了如下的实验,初步将问题确定在控制器中的U6(也就是控制无线充电控制MCU)部分:

  • 将原来旧的U1(通讯控制MCU)固件下载,发现故障依然存在;
  • 将U6从电路板拆除,故障消失;

(2)信号测试

U6影响U1是通过KEY1引线,来模拟之前的线圈放大信号。使用示波器测量KEY1信号,初步没有看到特别的且囊括。

 

02 修改U6的程序


1.简化U6程序

将U6的主函数简化成只剩下对于看门狗喂狗的过程。上面的自动切换过程依然存在!!!

那么这个问题究竟是在什么地方呢?

▲ 主控制盒显示每隔5秒钟信标灯在自动切换

▲ 主控制盒显示每隔5秒钟信标灯在自动切换

这与前面判断与U6有关的结论相互矛盾。

2.将U6单片机拆除下来

将U6拆除下来,重新观察,会看到自动切换现象消除了。

▲ 将U6单片机拆除下来

▲ 将U6单片机拆除下来

3.临时将ADC0_PIN修改成IN

将ADC0_PIN临时修改成输入管脚。此时故障消失了。所以判断对于U1造成自动切换的问题仍然来自于U6的ADC0_PIN管脚。

但是由于ADC0_PIN成为输入,所以程序在无法对于U1发送触发信号了。

那么怎么办呢?

4.将ADC0_PIN的逻辑修改成与HALL一样

也就是将ADC0_PIN的状态,平时修改高电平。当信号板中的AHLL被磁铁触发之后,HALL管脚下降,那么再将ADC0_PIN修改低电平。

问题神奇的解决了!!!

到此为止,通过试凑获得解决问题的办法,但原因是什么?还不得而知!

 

▌【结论】


有些故障就像迷一样,来无踪去无影。我们总是在有限的时间、精力、测量手段下悲壮的往前行。

另外有同学询问,发光灯盘是否可以独自工作,而不需要控制盒。此时,只需要将发光盘上的4PIN控制端口中的ION与GDN短接即可。

▲ 灯盘自动点亮的设置

▲ 灯盘自动点亮的设置

■ 相关文献链接:

/**
  ******************************************************************************
  * File Name          : main.c
  * Description        : Main program body
  ******************************************************************************
  *
  * COPYRIGHT(c) 2021 STMicroelectronics
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx_hal.h"

/* USER CODE BEGIN Includes */
#include "math.h"
#include "stm32f0xxa.h"
#include "serialtxt.h"
#include "control.h"

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc;
DMA_HandleTypeDef hdma_adc;

IWDG_HandleTypeDef hiwdg;

TIM_HandleTypeDef htim3;

UART_HandleTypeDef huart1;
DMA_HandleTypeDef hdma_usart1_rx;

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_ADC_Init(void);
static void MX_IWDG_Init(void);
static void MX_TIM3_Init(void);
static void MX_USART1_UART_Init(void);

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC_Init();
  MX_IWDG_Init();
  MX_TIM3_Init();
  MX_USART1_UART_Init();

  /* USER CODE BEGIN 2 */
  STM32F0XXAInit();
  ControlInit();
  printf("BEACON Wireless Driver. -- by Dr.ZhuoQing[%d] %s,%s\r\n", SystemCoreClock, __DATE__, __TIME__);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  int nCount = 0;
  int nShowCount = 0;
  
  g_nAdjustFlag = 1;                        // Begin Adjust I
  int nOutFlag = 0;
  
  PWMOff();
  WaitTime(150);
  //----------------------------------------------------------------------------
//  while(1) {
//    HAL_IWDG_Refresh(&hiwdg);
      
//  }
  
  //----------------------------------------------------------------------------
  
  while (1)
  {
    if(nOutFlag == 0) {
        if(++nCount & 0x200) ON(LED);
        else OFF(LED);
    } else {
        if(++nCount & 0x40) ON(LED);
        else OFF(LED);
    }
    
    WaitTime(1);
    
    HAL_IWDG_Refresh(&hiwdg);

    //--------------------------------------------------------------------------    
    
    if(VAL(HALL_PIN) != 0x0) {
        ON(ADC0_PIN);
        
        if(g_ucLastHall != 0) {
            PWMOff();
            nOutFlag = 0;
        }
        
        g_ucLastHall = 0;
        
    } else {
        OFF(ADC0_PIN);
        
        PWMOn();
        g_ucLastHall = 1;
        nOutFlag = 1;
    }
  
    //--------------------------------------------------------------------------
    
    if(VAL(CTRL_PIN) != 0x0) {
        PWMOn();
        nOutFlag = 1;
        
        if(VAL(HALL_PIN) == 0) {
            OFF(ADC0_PIN);
            WaitTime(50);
            ON(ADC0_PIN);
            WaitTime(50);
            OFF(ADC0_PIN);
            WaitTime(50);
            ON(ADC0_PIN);
            WaitTime(50);

        }
                
    } else {
        if(VAL(HALL_PIN) != 0) {
            PWMOff();
            nOutFlag = 0;
        }
        
    }

    //--------------------------------------------------------------------------
    
    //--------------------------------------------------------------------------
    if(++nShowCount >= 500) {
        nShowCount = 0;                
    }
    
    //------------------------------------------------------------------
                    
    CONSOLE_DEBUG;
    
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}

/** System Clock Configuration
*/
void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_PeriphCLKInitTypeDef PeriphClkInit;

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI14|RCC_OSCILLATORTYPE_LSI
                              |RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
  RCC_OscInitStruct.HSI14CalibrationValue = 16;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);

  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
  PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK;
  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

/* ADC init function */
void MX_ADC_Init(void)
{

  ADC_ChannelConfTypeDef sConfig;

    /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
    */
  hadc.Instance = ADC1;
  hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC;
  hadc.Init.Resolution = ADC_RESOLUTION12b;
  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
  hadc.Init.EOCSelection = EOC_SINGLE_CONV;
  hadc.Init.LowPowerAutoWait = DISABLE;
  hadc.Init.LowPowerAutoPowerOff = DISABLE;
  hadc.Init.ContinuousConvMode = DISABLE;
  hadc.Init.DiscontinuousConvMode = DISABLE;
  hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc.Init.DMAContinuousRequests = DISABLE;
  hadc.Init.Overrun = OVR_DATA_PRESERVED;
  HAL_ADC_Init(&hadc);

    /**Configure for the selected ADC regular channel to be converted. 
    */
  sConfig.Channel = ADC_CHANNEL_0;
  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
  HAL_ADC_ConfigChannel(&hadc, &sConfig);

    /**Configure for the selected ADC regular channel to be converted. 
    */
  sConfig.Channel = ADC_CHANNEL_1;
  HAL_ADC_ConfigChannel(&hadc, &sConfig);

}

/* IWDG init function */
void MX_IWDG_Init(void)
{

  hiwdg.Instance = IWDG;
  hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
  hiwdg.Init.Window = 4095;
  hiwdg.Init.Reload = 4095;
  HAL_IWDG_Init(&hiwdg);

}

/* TIM3 init function */
void MX_TIM3_Init(void)
{

  TIM_ClockConfigTypeDef sClockSourceConfig;
  TIM_MasterConfigTypeDef sMasterConfig;
  TIM_OC_InitTypeDef sConfigOC;

  htim3.Instance = TIM3;
  htim3.Init.Prescaler = 0;
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim3.Init.Period = 239;
  htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  HAL_TIM_Base_Init(&htim3);

  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig);

  HAL_TIM_PWM_Init(&htim3);

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);

  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 120;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1);

}

/* USART1 init function */
void MX_USART1_UART_Init(void)
{

  huart1.Instance = USART1;
  huart1.Init.BaudRate = 500000;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  huart1.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED ;
  huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  HAL_UART_Init(&huart1);

}

/** 
  * Enable DMA controller clock
  */
void MX_DMA_Init(void) 
{
  /* DMA controller clock enable */
  __DMA1_CLK_ENABLE();

  /* DMA interrupt init */
  HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  HAL_NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);

}

/** Configure pins as 
        * Analog 
        * Input 
        * Output
        * EVENT_OUT
        * EXTI
*/
void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __GPIOF_CLK_ENABLE();
  __GPIOA_CLK_ENABLE();

  /*Configure GPIO pins : PA2 PA4 */
  GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_4;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PA3 PA7 */
  GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_7;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

#ifdef USE_FULL_ASSERT

/**
   * @brief Reports the name of the source file and the source line number
   * where the assert_param error has occurred.
   * @param file: pointer to the source file name
   * @param line: assert_param error line source number
   * @retval None
   */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */

}

#endif

/**
  * @}
  */ 

/**
  * @}
*/ 

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/*
**==============================================================================
** CONTROL.C:             -- by Dr. ZhuoQing, 2015-11-29
**
**==============================================================================
*/
#include "stm32f0xx_hal.h"
#include "stm32f0xxa.h"
#include "math.h"
#define CONTROL_GLOBALS        1                       // Define the global variables
#include "CONTROL.H"
//==============================================================================
//
//------------------------------------------------------------------------------
extern TIM_HandleTypeDef htim3;
extern ADC_HandleTypeDef hadc;
extern IWDG_HandleTypeDef hiwdg;
void ControlInit(void) {
    //--------------------------------------------------------------------------
    IN(HALL_PIN);
    OFF(HALL_PIN);
    OUT(ADC0_PIN);
    ON(ADC0_PIN);
    IN(CTRL_PIN);
    OFF(CTRL_PIN);
    PWMOff();
    //--------------------------------------------------------------------------
    HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);    
    HAL_ADC_Start_DMA(&hadc, (uint32_t *)g_nADCBuffer, ADC_BUFFER);
    //--------------------------------------------------------------------------
    SetPWMARR(320);                         // Set PWM frequency 150kHz
    //--------------------------------------------------------------------------
    g_fLastD = 0.1;
    g_nADCI = 0;    
    g_nAdjustFlag = 0;
    g_ucLastHall = 0;
    //--------------------------------------------------------------------------
    HAL_IWDG_Start(&hiwdg);
}
//------------------------------------------------------------------------------
void GetADCAverage(unsigned short * pADC) {
    unsigned int nSigma[ADC_CHANNEL];
    int i;
    for(i = 0; i < ADC_CHANNEL; i ++) 
        nSigma[i] = 0;
    unsigned short * p = g_nADCBuffer;
    for(i = 0; i < ADC_BUFFER; i ++) {
        int j;
        for(j = 0; j < ADC_CHANNEL; j ++)
            nSigma[j] += *(p ++);
    }
    for(i = 0; i < ADC_CHANNEL; i ++)
        *(pADC + i) = nSigma[i] / ADC_BUFFER;
}
//------------------------------------------------------------------------------
void SetPWMARR(unsigned int nDivide) {
    htim3.Instance->ARR = nDivide-1;
    htim3.Instance->CCR1 = nDivide / 2;
}
void SetPWMCCR(unsigned int nCCR) {
    if(nCCR >= htim3.Instance->ARR)
        nCCR = htim3.Instance->ARR - 1;
    htim3.Instance->CCR1 = nCCR;
}
//------------------------------------------------------------------------------
void AdjustIBus(void) {
    unsigned short nADC[ADC_CHANNEL];
    if(g_nAdjustFlag == 0) return;
    //--------------------------------------------------------------------------
    GetADCAverage(nADC);
    short nI = nADC[0];
    g_nADCI = nI;
    float dnew = 0.5;
    float f_pi = 3.1415926;
    if(nI > 10) {
        float a = sqrt(I_BUS_ADC_SET / (float)nI) * sin(f_pi * g_fLastD);
        if(a <= 1.0) {
            dnew = asin(a) / f_pi;
        }
    } 
    dnew = dnew * ADJUST_I_BETA + (1 - ADJUST_I_BETA) * g_fLastD;
    g_fLastD = dnew;
    if(g_fLastD < 0.01) g_fLastD = 0.01;
    unsigned int nCCR = (int)(320 * dnew);
    if(nCCR < 10) nCCR = 10;
    else if(nCCR > 160) nCCR = 160;
    SetPWMCCR(nCCR);
}
//------------------------------------------------------------------------------
void PWMOn(void) {
    g_nAdjustFlag = 1;
}
void PWMOff(void) {
    g_nAdjustFlag = 0;
    SetPWMCCR(0);
    g_fLastD = 0.0;
}
//==============================================================================
//                END OF THE FILE : CONTROL.C
//------------------------------------------------------------------------------
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页