Skip to main content
kb24
Senior
August 28, 2020
Solved

Why is MCU freezing?

  • August 28, 2020
  • 18 replies
  • 4666 views

I am using STM32G030K8 and driving 3 DC motors with relays in the circuit. Also I am controlling voltage of motors with MOSFET. Most of the time its working well but sometimes when I change the direction of motor with relays MCU stops working. I am using buttons for controlling motors. If relay pins were set when it happens, pins stay set and motors still working, it is becoming dangerous. Timer or GPIO interrupts stop working. 10% of times it goes hardfault_handler, %90 of times it stops working without going hardfault_handler. What causes this? and how can I solve this problem?

Thank you.

This topic has been closed for replies.
Best answer by kb24

@TDK​ @Community member​ @MM..1​ @Dvorak.Peter​ @Laurent Ca...​ 

Thank you for all your answers. After long time I turned back to this project again. I had same problem with totally new design and pcb. Then I started to use CubeIde instead of Keil. I saw its going to HardFault_Handler every time, Keil cant catch it most of the time. In debug console I saw this:0693W000008xOVJQA2.jpgthen we searched for SIGTRAP. In https://github.com/stm32duino/Arduino_Core_STM32/issues/1206 this link I saw "For the clock issue, it seems your board have an issue with the HSE Bypass (clock provided by the STLink).". My problem was valid all the time not only during debugging process. Also I saw something about HSI in errata. So we decided to change clock configurations. I was using 64 MHz with PLL, I changed it like 16 MHz with HSI. Now I have no problem. Everything is working fine. What I dont understand is this if I use 64 MHz and PLL and run MOTORS its going to hard fault but if I run LEDS or just switch relays without any load its working fine. So drawing high current damages PLL and it makes this error?

18 replies

TDK
August 28, 2020

Examine the SCB registers to determine the source of the error.

Sounds like a power issue when motors switch directions. Measure the rails during an event.

"If you feel a post has answered your question, please click ""Accept as Solution""."
kb24
kb24Author
Senior
August 28, 2020

I will examine SCB registers and let you know on Monday. Thank you.

waclawek.jan
Super User
August 28, 2020

How do you switch the relay? Do you have freewheeling diode, snubbers? Post relevant portion of schematics.

JW

kb24
kb24Author
Senior
August 29, 2020

0693W000002lhlCQAQ.jpgOur switch circuit is totally same with the circuit in the picture. Its my bad to ask question on Friday evening, I cant access the circiut or documents until Monday.

Dvorak.Peter
Associate II
August 29, 2020

RE : when I change the direction of motor with relays MCU stops working. 

I suspect relay contact arcing coupling to the controller

PCB layout is critical

kb24
kb24Author
Senior
August 29, 2020

If the problem is this, how can we prevent this? Is there any circuitry sample to prevent this? Then we can try that solution.

waclawek.jan
Super User
August 29, 2020

Disconnect the motor. Make the relay switch fast, like 3Hz. Still problems?

If no,it's on the swiching (motor) side. As Peter said, switching inductive loads results in high voltage spikes even arcing. This is a group of problems which don't have a single simple solution, so you have to read and decide yourself; using a suitable snubber network may be a starting point.

JW

kb24
kb24Author
Senior
August 29, 2020

Okay, I will try and let you know the results. Thank you all.

ST Technical Moderator
September 6, 2020

​Hello @kb24​ ,

Please share the way that solved your problem, it may be helpful for other community users.

Then, please select the post of user which is "Best Answer" or mark your post as answered the question.

Best Regards,

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
MM..1
Super User
September 13, 2020

And for critical safety motor design you need watchdog implemented and stop motors after error simply

Laurent Ca...
Senior III
September 24, 2020

Dear @kb24​ 

What is the status about your problem?

Did the @Dvorak.Peter​ and @MM..1​ answers help you to solve it?

Best regards

Laurent Ca...

kb24
kb24Author
Senior
September 24, 2020

Actually I am not the person who is working on hardware, I am doing software part and as I said before I am using old circuitry with STM instead of PIC. I uploaded same code to that board and everything is working fine so problem was our new designed circuitry. I told friends' answers to person who is working on hardware, he will consider those answers but for now he is working on different project and we don't know when he can start this project again.

Laurent Ca...
Senior III
October 20, 2020

Dear @kb24​ 

Therefore I consider this thread closed for the moment.

Feel free to reopen it when you will be back on it by posting a new answer.

Best regards

Laurent Ca...

kb24
kb24AuthorBest answer
Senior
March 19, 2021

@TDK​ @Community member​ @MM..1​ @Dvorak.Peter​ @Laurent Ca...​ 

Thank you for all your answers. After long time I turned back to this project again. I had same problem with totally new design and pcb. Then I started to use CubeIde instead of Keil. I saw its going to HardFault_Handler every time, Keil cant catch it most of the time. In debug console I saw this:0693W000008xOVJQA2.jpgthen we searched for SIGTRAP. In https://github.com/stm32duino/Arduino_Core_STM32/issues/1206 this link I saw "For the clock issue, it seems your board have an issue with the HSE Bypass (clock provided by the STLink).". My problem was valid all the time not only during debugging process. Also I saw something about HSI in errata. So we decided to change clock configurations. I was using 64 MHz with PLL, I changed it like 16 MHz with HSI. Now I have no problem. Everything is working fine. What I dont understand is this if I use 64 MHz and PLL and run MOTORS its going to hard fault but if I run LEDS or just switch relays without any load its working fine. So drawing high current damages PLL and it makes this error?