{"action":"closed","issue":{"url":"https://api.github.com/repos/esp8266/Arduino/issues/3680","repository_url":"https://api.github.com/repos/esp8266/Arduino","labels_url":"https://api.github.com/repos/esp8266/Arduino/issues/3680/labels{/name}","comments_url":"https://api.github.com/repos/esp8266/Arduino/issues/3680/comments","events_url":"https://api.github.com/repos/esp8266/Arduino/issues/3680/events","html_url":"https://github.com/esp8266/Arduino/issues/3680","id":263082631,"number":3680,"title":"while loop causes reset","user":{"login":"Phil1988","id":6054234,"avatar_url":"https://avatars2.githubusercontent.com/u/6054234?v=4","gravatar_id":"","url":"https://api.github.com/users/Phil1988","html_url":"https://github.com/Phil1988","followers_url":"https://api.github.com/users/Phil1988/followers","following_url":"https://api.github.com/users/Phil1988/following{/other_user}","gists_url":"https://api.github.com/users/Phil1988/gists{/gist_id}","starred_url":"https://api.github.com/users/Phil1988/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Phil1988/subscriptions","organizations_url":"https://api.github.com/users/Phil1988/orgs","repos_url":"https://api.github.com/users/Phil1988/repos","events_url":"https://api.github.com/users/Phil1988/events{/privacy}","received_events_url":"https://api.github.com/users/Phil1988/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-10-05T10:57:29Z","updated_at":"2017-10-06T01:11:46Z","closed_at":"2017-10-06T01:11:46Z","author_association":"NONE","body":"### Description\r\n\r\nI lost 4 hours now on this problem by searching the given debug messages and solder/desolder, rewrite the code etc but it might have something to do with a while loop and the watchdog...\r\n\r\nI am using a WeMos to control a DRV8825 and a stepper driver that is sitting on a rail.\r\nThe next step for me is to do a calibration drive, where the distance of the rail is beeing measured.\r\nBecause the the calibration should not beeing aborted by anything I want to use a while loop.\r\n\r\nThe problem is, that the while loop causes the WeMos to soft-reset.\r\nSee my very simplified example sketch to get an idea of the problem.\r\n\r\nI have had the messages:\r\nrst cause:2, boot mode:(3,6)\r\nrst cause:2, boot mode:(1,6)\r\nrst cause:4, boot mode:(1,6)\r\n\r\nIt's no power issue (measured with a good multimeter and a oscilloscope).\r\n\r\n#### Hardware\r\nHardware:\t\t\tWeMos D1 mini\r\nCore Version:      \t(I dont know)\r\n\r\n### Settings in IDE\r\n\r\nModule:  \t\t\tWeMos D1 R2 & mini\r\nFlash Size: \t\t4M (3M SPIFFS)\r\nCPU Frequency:\t\t80Mhz\r\nUpload Speed:\t\t921600\r\nUpload Using:\t\tSERIAL\r\n\r\n\r\n### Sketch\r\n\r\n```\r\nunsigned longcurrentTimeoutMillis = 0; \r\nunsigned long previousTimeoutMillis = 0;        \r\nunsigned int timeout = 10000;          \r\n\r\n// time variables for stepping to prevent blocking function ...\r\n// ... of delay() during stepping for smoother movements and faster reaction\r\nunsigned long currentMicros = 0;\r\nunsigned long previousStepperMicros = 0;       \r\n\r\n\r\n// time beween a HIGH and a LOW puls in µs \r\n// so this value * 2 is the time needed for one step)     \r\nunsigned int stepSpeed = 50;       \r\nbool stepPuls = 0;\r\n\r\nlong unsigned int stepCounter = 0;\r\nfloat distance = 0;\r\n\r\nvoid setup() \r\n{\r\n  //inputs and outputs and all the setup stuff is here\r\n}\r\n\r\nvoid loop() \r\n{\r\n  if (a_button_is_pushed)\r\n  {\r\n    calibrate();\r\n  }\r\n}\r\n\r\nvoid calibrate()\r\n{\r\n  //set direction to drive left\r\n  setDirectionLeft();\r\n\r\n  //save actual time\r\n  previousTimeoutMillis = millis();  \r\n\r\n  //check if the motor is not left and the timout didnt run out\r\n  while( !(sliderIsLeft()) && ((currentTimeoutMillis - previousTimeoutMillis) < timeout) )  \r\n  {\r\n\r\n\r\n//**** The program/motor stops here in the while loop after about 3 seconds ****//\r\n//**** with the given debug message below ****//\r\n\r\n\r\n    //save actual time for timeout\r\n    currentTimeoutMillis = millis();  \r\n\r\n    //save actual time for step-timing\r\n    currentMicros = micros();  \r\n    if (currentMicros - previousStepperMicros >= stepSpeed) \r\n    {\r\n      // save the last time a HIGH/LOW puls was given out\r\n      previousStepperMicros = currentMicros;\r\n\r\n      if (stepPuls == 1)\r\n      {\r\n        stepPuls = 0;\r\n      }\r\n      else if (stepPuls == 0)\r\n      {\r\n        stepPuls = 1;\r\n\r\n        //count the steps that was made\r\n        stepCounter++;\r\n      }\r\n      digitalWrite(stepPin , stepPuls); \r\n    }  \r\n\r\n  }\r\n  else\r\n  {\r\n    Serial.print(\"The motor is left now and has made \");\r\n    Serial.print(stepCounter);\r\n    Serial.println(\" steps.\");\r\n  }\r\n}\r\n```\r\n\r\n### Debug Messages\r\n\r\n```\r\nSoft WDT reset\r\n\r\nctx: cont \r\nsp: 3ffef260 end: 3ffef490 offset: 01b0\r\n\r\n>>>stack>>>\r\n3ffef410:  3ffee354 3ffee440 3ffee440 40202344  \r\n3ffef420:  3ffe8510 3ffee440 3ffee34c 40201fde  \r\n3ffef430:  3ffee364 00000000 3ffee440 40202320  \r\n3ffef440:  3ffee358 3ffee440 00000000 3ffee350  \r\n3ffef450:  3ffee358 00000000 3ffee45c 402020a1  \r\n3ffef460:  00000000 00000000 00000001 3ffee464  \r\n3ffef470:  3fffdad0 00000000 3ffee45c 402028e8  \r\n3ffef480:  feefeffe feefeffe 3ffee470 40100114  \r\n<<<stack<<<\r\n\r\n ets Jan  8 2013,rst cause:2, boot mode:(3,6)\r\n\r\nload 0x4010f000, len 1384, room 16 \r\ntail 8\r\nchksum 0x2d\r\ncsum 0x2d\r\nv09f0c112\r\n```\r\n\r\n\r\n"}}
{"actor":{"display_login":"devyte"}}