I am using an ATMEL SAMC21 MCU on an ebike project. The MCU is involuntarily resetting every 30s to 1min. This causes a problem as it's controlling the bike in real time, giving noticeable gaps in power and resetting to defaults the power mode selection. I am inputting three analog voltages in it, I have an alphanumeric LCD plugged to it and I am outputting a voltage with a DAC. The program runs PID algorithms for control as well as battery capacity estimation ones. I also coded a timer in microseconds. Knowing this, is there anyway to know what are the different reasons these resets could be due to, so that I investigate? Thank you for your help!
is there anyway to know what are the different reasons these resets could be due to, so that I investigate?
Yes - read and act on (or display etc.) the
RCAUSE register when the MCU restarts (i.e. examine it at the start of your code), as mentioned in the SAM C21 "complete datasheet". That register contains the reason for the last MCU reset.
Software bugs might also be able to trigger resets e.g. a fault triggered in a fault handler (reset cause
SYST in the
RCAUSE register), in addition to the more obvious Watchdog reset (if you are using the Watchdog).
From your question, we don't know when these resets started during the development of your project. When you think back to when they started, you might be able to identify a change or set of changes just before they started, to give you a focus for your troubleshooting.
There are several troubleshooting techniques you can also use. A straightforward one (although it has limitations) is to simplify your project, step-by-step, making sure you can reverse each step of the simplification, until the problem stops happening. Then consider the implications of the simplification change you last made before the problem stopped.
Considering the project, a power-related problem seems quite likely and that may need investigation of the schematics, board layout and wiring etc. to troubleshoot it in detail, as well as use of an oscilloscope. Depending on whether the problem happens with the "ebike" stationary or not, you may have other challenges to the troubleshooting. Good luck!