• AVR Freaks

Hot!Problem using MPLAB X IDE simulator Stopwatch with XC8 assembler code

Author
tomcrane
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2021/02/22 08:45:36
  • Location: 0
  • Status: offline
2021/02/24 08:40:31 (permalink)
5 (1)

Problem using MPLAB X IDE simulator Stopwatch with XC8 assembler code

I am attempting to time some loop code using the simulator's Stopwatch. My target is the PIC16F1459.

I am able to use the stopwatch in another project with the same target but in C rather than assembler.  This small standalone project's assembler code (shown below) actually contains loops generated by the XC8 C compiler from calls to __delay_ms() which I have copied from the compiler's .lst file and made into a separate (Assembler) project.  I am doing this largely out of curiosity about the code and its timing.

In the simulator I can build and debug the assembler project, set a couple of breakpoints, at the top and bottom of a loop, run to the first breakpoint, clear the stopwatch and run to the second breakpoint.  The stopwatch however always reports 'Stopwatch cycle count = undefined'.

I believe I have set the relevant CONFIG parameters correctly, which are derived from those generated by MCC for the C project.

Any ideas?

Thanks
Tom Crane

I am using MPLAB X IDE v.5.45.
-----------------------------------------------------------------------

processor       16F1459

 #include <xc.inc>
; Configuration word 1
CONFIG FOSC=INTOSC
CONFIG WDTE=OFF
CONFIG PWRTE=OFF
CONFIG MCLRE=OFF
CONFIG CP=OFF
CONFIG BOREN=ON
CONFIG CLKOUTEN=OFF
CONFIG IESO=OFF
CONFIG FCMEN=OFF
; Configuration word 2
CONFIG WRT=OFF
CONFIG CPUDIV=NOCLKDIV
CONFIG USBLSCLK=1 ; 1 = USB Clock divide-by 8 (48 MHz system input clock expected)
CONFIG PLLMULT=1  ; 1 = 3x PLL Output Frequency is selected
CONFIG PLLEN=ENABLED
CONFIG STVREN=ON
CONFIG BORV=LO
CONFIG LPBOR=OFF
CONFIG LVP=OFF


PSECT resetVec, class="CODE", delta=2
resetVec:
PAGESEL main
goto main

PSECT code
inner_loop_cnt     equ     0x70
outer_loop_cnt     equ     0x71

;main.c: 380:         _delay((unsigned long)((64)*(48000000/4000.0)));
main:
       movlw   4
       movlb   4       ; select bank4
       movwf   outer_loop_cnt
       movlw   230
       movwf   inner_loop_cnt           ; 3-deep nested loop count no. ~= 1*1*98 + 4*(230-1)*256 = 234594
       movlw   98 u4197:
       decfsz  9,f                      ; NB: Register at address 09 is the W register
       goto    u4197
       decfsz  inner_loop_cnt,f
       goto    u4197
       decfsz  outer_loop_cnt,f
       goto    u4197
       nop
l5195:


;main.c: 382:         _delay((unsigned long)((1000)*(48000000/4000.0)));
       movlw   61
       movlb   4       ; select bank4
       movwf   outer_loop_cnt
       movlw   225
       movwf   inner_loop_cnt           ; 3-deep nested loop count no. ~= 1*1*63 + 61*(225-1)*256 = 3498047
       movlw   63
u4207:
       decfsz  9,f                      ; NB: Register at address 09 is the W register
       goto    u4207
       decfsz  inner_loop_cnt,f
       goto    u4207
       decfsz  outer_loop_cnt,f
       goto    u4207
       nop2

END resetVec
 
 
#1

8 Replies Related Threads

    1and0
    Access is Denied
    • Total Posts : 12265
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Problem using MPLAB X IDE simulator Stopwatch with XC8 assembler code 2021/02/24 16:58:00 (permalink)
    0
    tomcrane
    I am attempting to time some loop code using the simulator's Stopwatch. My target is the PIC16F1459.
    ...
    In the simulator I can build and debug the assembler project, set a couple of breakpoints, at the top and bottom of a loop, run to the first breakpoint, clear the stopwatch and run to the second breakpoint.  The stopwatch however always reports 'Stopwatch cycle count = undefined'.

    Did you input the Instruction Frequency in your Project Properties?
     
    #2
    tomcrane
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2021/02/22 08:45:36
    • Location: 0
    • Status: offline
    Re: Problem using MPLAB X IDE simulator Stopwatch with XC8 assembler code 2021/02/25 10:49:51 (permalink)
    0
    Thanks for the follow-up.
     
    Yes, I had set the Frequency at
    <TL panel> --> Projects  --> <project name> --> Right-click -->Properties --> Conf: [default] --> Simulator --> Oscillator options [PD menu] -->  Instruction frequency (Fcyc)
     
    to 12MHz but something had subsequently reset it to 1MHz.
     
    I changed it back to 12MHz but still got 'Stopwatch cycle count = undefined'.
     
    Then I found a/the fix was to make the project the 'main project'.  Thereafter the stopwatch worked.
     
    Prior to making it the main project, I was starting the debugger/simulator from <TL panel> --> Projects  --> <project name> --> Right-click --> Debug and then using the buttons on the IDE top ribbon to stop/start/set breakpoints etc.
     
    Do you know if this is the expected behaviour?
     
    Thanks
    Tom Crane.
    #3
    1and0
    Access is Denied
    • Total Posts : 12265
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Problem using MPLAB X IDE simulator Stopwatch with XC8 assembler code 2021/02/25 12:24:37 (permalink)
    +1 (1)
    tomcrane
    Then I found a/the fix was to make the project the 'main project'.  Thereafter the stopwatch worked.
     
    Prior to making it the main project, I was starting the debugger/simulator from <TL panel> --> Projects  --> <project name> --> Right-click --> Debug and then using the buttons on the IDE top ribbon to stop/start/set breakpoints etc.
     
    Do you know if this is the expected behaviour?

    I don't know what is the "expected behavior", as I always set a main project and never have such issue.  I do know if you don't tell the Simulator the instruction frequency the stopwatch will "undefined".
    #4
    1and0
    Access is Denied
    • Total Posts : 12265
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Problem using MPLAB X IDE simulator Stopwatch with XC8 assembler code 2021/02/25 14:49:15 (permalink)
    +2 (2)
    tomcrane
           decfsz  9,f                      ; NB: Register at address 09 is the W register



    The symbol for the W register is WREG.
     
    #5
    dan1138
    Super Member
    • Total Posts : 4316
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Problem using MPLAB X IDE simulator Stopwatch with XC8 assembler code 2021/02/25 18:44:29 (permalink)
    +3 (3)
    The simulation stopwatch counts instruction cycles. When the instruction cycle frequency is set accurately the time shown in the stopwatch output window "should" be what happens in the real hardware.

    The code you posted does not build because there are syntax and project setup issues.

    This code:
    ;
    ; File: main.S
    ; Target: PIC16F16F1459
    ; Author: tomcrane
    ; Date: 2021-02-25
    ; Compiler: pic-as(v2.31)
    ; IDE: MPLABX v5.45
    ;
    ;
    ; Add this line in the project properties box, pic-as Global Options -> Additional options:
    ; -Wa,-a -Wl,-presetVec=0h
    ;
    PROCESSOR 16F1459
    PAGEWIDTH 132
    RADIX DEC
    ;
    #include <xc.inc>
    ;
    ; CONFIG1
    CONFIG FOSC = INTOSC ; Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
    CONFIG WDTE = OFF ; Watchdog Timer Enable (WDT disabled)
    CONFIG PWRTE = OFF ; Power-up Timer Enable (PWRT disabled)
    CONFIG MCLRE = OFF ; MCLR Pin Function Select (MCLR/VPP pin function is digital input)
    CONFIG CP = OFF ; Flash Program Memory Code Protection (Program memory code protection is disabled)
    CONFIG BOREN = ON ; Brown-out Reset Enable (Brown-out Reset enabled)
    CONFIG CLKOUTEN = OFF ; Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
    CONFIG IESO = OFF ; Internal/External Switchover Mode (Internal/External Switchover Mode is disabled)
    CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)

    ; CONFIG2
    CONFIG WRT = OFF ; Flash Memory Self-Write Protection (Write protection off)
    CONFIG CPUDIV = NOCLKDIV ; CPU System Clock Selection Bit (NO CPU system divide)
    CONFIG USBLSCLK = 1 ;48MHz ; USB Low SPeed Clock Selection bit (System clock expects 48 MHz, FS/LS USB CLKENs divide-by is set to 8.)
    CONFIG PLLMULT = 1 ;3x ; PLL Multipler Selection Bit (3x Output Frequency Selected)
    CONFIG PLLEN = ENABLED ; PLL Enable Bit (3x or 4x PLL Enabled)
    CONFIG STVREN = ON ; Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
    CONFIG BORV = LO ; Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
    CONFIG LPBOR = OFF ; Low-Power Brown Out Reset (Low-Power BOR is disabled)
    CONFIG LVP = OFF ; Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)


    PSECT resetVec, global, class=CODE, delta=2
    resetVec:
    PAGESEL main
    goto main

    ;
    ; Data space in common RAM so we do not need bank selects to access
    PSECT MainData,global,class=COMMON,space=1,delta=1,noexec
    global inner_loop_cnt,outer_loop_cnt

    inner_loop_cnt: ds 1
    outer_loop_cnt: ds 1

    ;main.c: 380: _delay((unsigned long)((64)*(48000000/4000.0)));
    PSECT MainCode,global,class=CODE,delta=2
    global main,u4197,l5195,u4207
    main:
    movlw 4
    movlb 4 ; select bank4
    movwf outer_loop_cnt
    movlw 230
    movwf inner_loop_cnt ; 3-deep nested loop count no. ~= 1*1*98 + 4*(230-1)*256 = 234594
    movlw 98
    u4197:
    decfsz 9,f ; NB: Register at address 09 is the W register
    goto u4197
    decfsz inner_loop_cnt,f
    goto u4197
    decfsz outer_loop_cnt,f
    goto u4197
    nop
    l5195:


    ;main.c: 382: _delay((unsigned long)((1000)*(48000000/4000.0)));
    movlw 61
    movlb 4 ; select bank4
    movwf outer_loop_cnt
    movlw 225
    movwf inner_loop_cnt ; 3-deep nested loop count no. ~= 1*1*63 + 61*(225-1)*256 = 3498047
    movlw 63
    u4207:
    decfsz 9,f ; NB: Register at address 09 is the W register
    goto u4207
    decfsz inner_loop_cnt,f
    goto u4207
    decfsz outer_loop_cnt,f
    goto u4207
    nop

    hang: goto hang

    END resetVec


    Does build and simulates as expected.
    post edited by dan1138 - 2021/02/25 19:27:12

    Attached Image(s)

    #6
    tomcrane
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2021/02/22 08:45:36
    • Location: 0
    • Status: offline
    Re: Problem using MPLAB X IDE simulator Stopwatch with XC8 assembler code 2021/03/01 11:43:03 (permalink)
    0
    Dan1138,
    Thanks very much for the cleaned-up code and project configuration tip.  It does now build w/o any diagnostics.
     
    Thanks also to 1and0 for above comments.  When I started PIC programming back in the 90's the assembler (probably MPASM on Win3.11) accepted 'W' for this register and the habit stuck.
     
    Best regards
    Tom Crane
    #7
    1and0
    Access is Denied
    • Total Posts : 12265
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Problem using MPLAB X IDE simulator Stopwatch with XC8 assembler code 2021/03/01 12:27:12 (permalink)
    +1 (1)
    tomcrane
    Thanks also to 1and0 for above comments.  When I started PIC programming back in the 90's the assembler (probably MPASM on Win3.11) accepted 'W' for this register and the habit stuck.

    I don't think there was an 8-bit PIC device with a memory mapped WREG register back in the 90's. ;)  The symbol 'W' is for the destination bit.
     
    #8
    ric
    Super Member
    • Total Posts : 30223
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Problem using MPLAB X IDE simulator Stopwatch with XC8 assembler code 2021/03/01 12:31:03 (permalink)
    0
    +1.
    "w" was only ever recognised as a suffix, not a register name.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    Jump to:
    © 2021 APG vNext Commercial Version 4.5