I'm currently working on a project using the FRDM-KL25Z development board and programming using Keil MDK-lite (5.14a). What we're supposed to do is create a simple traffic light using three corresponding LEDs and a push button to expedite the light change(not immediately like a real traffic light but to check after each delay). The problem I'm having is my program works perfectly fine in the simulator but when running on the development board it reset itself almost immediately. I've narrowed it down to the loops I'm using for a 30 second delay. Any tips to find out why this is happening or how to find more information in the debugger would be great.

Here's a cutout of the loop I'm using.

reset   LDR R1, =0x00000002     ;Change light to red
        BL changelight          ;

        LDR R3, =0x00000011     ;Put value into counter (1 loop just to show code works)
 d30_1  BL buttonpress          ;Check for button press
        SUBS R3, #17            ;Subtract # of ticks in loop (17) from counter
        CMP R3, #0
        BGT d30_1

        CMP R6, #1              ;Check for button press
        BEQ reset               ;Reset to red if pressed
        LDR R1, =0x00000010     ;Change light to green
        BL changelight          ;

        LDR R3, =0x05B8d800     ;Put value into counter (5 seconds, the board resets when counter is this high)
d30_2   BL buttonpress          ;Check for button press
        SUBS R3, #17            ;Subtract # of ticks in loop (17) from counter
        CMP R3, #0
        BGT d30_2

Here is the branch buttonpress

        LDR R0, =0x400FF090     ;Put address of PORTC_PDIR into R0
        LDR R1, [R0]            ;Put value of PORTC_PDIR into R1
        LDR R0, =0x00000080     ;Put value of monitored input pin
        TST R1, R0              ;Check for button press
        BNE nopress             ;Break from process if button not pressed
        MOVS R6, #1             ;Put 1 in R6 if button has been pressed
nopress BX LR
  • 1
    \$\begingroup\$ is there a watchdog? is it disabled? \$\endgroup\$ – Brian Drummond Nov 30 '15 at 20:20
  • \$\begingroup\$ Increase your delay by a factor of 10 or 100 and see what happens. \$\endgroup\$ – mkeith Nov 30 '15 at 21:59
  • \$\begingroup\$ First suspect would be a neglected watchdog, next a fault due to something like an attempt to access an invalid or unaligned address or even a clock start failure, and third runaway execution. Also make sure your use of the label "reset" isn't getting mixed up with something in start code (which seems to be missing? you don't seem to configure GPIOs or clock domains or anything like that) \$\endgroup\$ – Chris Stratton Nov 30 '15 at 22:29

I checked the Reset Control Module (RCM) while debugging. The cause of the reset can be attributed to the watchdog timer Computer Operating Properly (COP) timing out. I added the following to my initialization to solve the problem. Thank you guys!

;Disable watchdog COP timer
    LDR R0, =SIM_COPC   ;Load address of SIM_COPC to R0
    LDR R1, =0x0        ;Disable watchdog COPT
    STR R1, [R0]        ;
| improve this answer | |

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.