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

网友投稿 578 2022-05-29

01

存在的问题

1.问题描述

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

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

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

2.初步排除

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

将原来旧的U1(通讯控制MCU)固件下载,发现故障依然存在;

将U6从电路板拆除,故障消失;

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

02

修改U6的程序

1.简化U6程序

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

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

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

2.将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短接即可。

■ 相关文献链接:

第十六届全国大学智能汽车竞赛竞速比赛规则

无线节能信标核心板V4-测试-2021-4-3

/** ****************************************************************************** * 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****/

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

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

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

/* **============================================================================== ** 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 //------------------------------------------------------------------------------

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

单片机

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:kafka系统入门教程
下一篇:【python】每天一个小练习
相关文章