0
\$\begingroup\$

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!

\$\endgroup\$
  • 3
    \$\begingroup\$ Watchdog? Brown out ? Undesired Voltage on Reset pin? Could be many thing! A schematic of the problematic area would be good start \$\endgroup\$ – MaNyYaCk Jan 16 '17 at 12:23
  • 2
    \$\begingroup\$ Not to mention software bugs, including race conditions between interrupts and main line. Given the small amount of information you've provided, it could be many different things. \$\endgroup\$ – DoxyLover Jan 16 '17 at 13:55
1
\$\begingroup\$

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.


Extract from Atmel SAM C21 datasheet - RCAUSE register


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!

\$\endgroup\$
  • 1
    \$\begingroup\$ I used the RCAUSE which outputted a reset due to the watchdog although I never activated it in the first place. Is there a way to disable it or does this outline an underlying error? Thank you! \$\endgroup\$ – Eliott W Jan 16 '17 at 19:58
  • 1
    \$\begingroup\$ I have tried to set the enable enum in the config to false but this is returning an error. I have also tried to clear the early warning period at each iteration but the reset still occured. \$\endgroup\$ – Eliott W Jan 16 '17 at 20:16
  • 1
    \$\begingroup\$ @EliottW - Glad I could help you to answer the question about the cause of the resets. Now your work begins :-) Without seeing all your notes on the development, and having your hardware in front of me, it's not sensible for me to try to list all the troubleshooting possibilities, as they depend on that. Earlier you said the resets were at variable times, and now you explained you didn't activate (and presumably don't "feed") the watchdog. Therefore the watchdog should trigger at a fixed interval, not a variable one. I would investigate that. As you know, the MCU can be configured to start the \$\endgroup\$ – SamGibson Jan 16 '17 at 23:18
  • 1
    \$\begingroup\$ [cont.] watchdog at power-on, but a blank MCU has that disabled. So perhaps you've managed to set that option in the "NVM User Row" (in MCU Flash), or your toolchain is setting that (is that what you meant by the "enable enum"?). In the past I've seen Flash corruption due to power issues, so don't ignore that possibility, depending on when this problem started. As I mentioned in my answer, knowing when this problem started can be used to help you focus on what changed (and what didn't change) before that. There are so many troubleshooting possibilities - simplify the situation first. \$\endgroup\$ – SamGibson Jan 16 '17 at 23:18
  • 1
    \$\begingroup\$ Thank you, I will first try to disable the WDT in my code, if this fails, I will simplify it until i converge on the source of the problem. \$\endgroup\$ – Eliott W Jan 16 '17 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.