cancel
Showing results for 
Search instead for 
Did you mean: 

Why is MCU freezing?

kb24
Senior

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.

1 ACCEPTED SOLUTION

Accepted Solutions

@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?

View solution in original post

18 REPLIES 18
TDK
Guru

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".

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

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

JW

Dvorak.Peter
Senior II

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

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.

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

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

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

​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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen