Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Simulator for PIC - suggestions

Status
Not open for further replies.

augustinetez

Active Member
As referenced in another post, I use the Oshonsoft sim for doing various bits & pieces of simulation, but sitting there for 30-40 minutes waiting for it to do a simulation of something like a 1 Second delay gets very tiring :( (I'm running an i5 quad core 2.6GHz PC with Win 10 Pro).

Any suggestions for other Sims that don't cost both arms and legs that may be quicker.
 
Is there a way to tell if it's in the simulator or not? I have a flag which reduces all delays during simulation. Tie an unused pin low so if it's in hardware it's low and software high - use internal pullup to set it high. I use the simulator in MPLABX!!!!!

Mike.
 
It's definitely in the simulator.

The hardware is on the other side of the world so the software needs to be right before it is sent for final testing.

Nothing special about this one, it is basically just a set of 7 pulse generation routines for testing the calibration of a piece of equipment.
 
I find the Oshonsoft SIM runs very fast when you close the Basic code window and select "Ultimate" speed. Set "Break" points in the code to stop where you want, if you want, then re-open the Basic compiler window to see where it stopped.
I've run 15 second timer simulations that take a minute or two to run when the Basic Compiler window is closed and the PIC Microcontroller "View" is set to watch the pins and their activity.
 
There's nothing in the Basic code window (I code in ASM outside of Oshonsoft program) and if I try to close it, it shuts the whole program down.

I have the Breakpoints manager open which also seems to be a time hog.
 
I had a quick look at it yesterday and while it says Win 10 64 bit compatible, from what I read in that quick look, you have to compile it rather than there just being an install file that can be downloaded and installed/run.

Still quite possible I may have missed that though if there is one.

Update (I wrote the above yesterday before but forgot to post it :banghead:)

Downloaded and installed Gpsim but it will only open COD files and of course, MPlab 8.92 produces COF files instead of the old COD files, so that was a waste of 10 minutes.
 
Any suggestions for other Sims that don't cost both arms and legs that may be quicker.
If you're trying to test those timing subsystems, the Simulator and Stopwatch in the old MPLAB v8.92 work well for 'cycle counting' on older chips like the 16F628A.

tempx.png
 
I use that oh so rarely and thought I would give it a go a couple of days ago - remembering how to use it was the first problem - then somehow managed to turn animation on, which slowed it right down to a crawl and couldn't get it turned off again :banghead: .

Going to give it another bash after getting the weeding done - the last delay is a 10 second (1s mark, 9s space) one and I don't fancy waiting for hours for the Oshonsoft sim to chunk it's way through that one :rolleyes:
 
I think you want to <set PC to cursor> by right-clicking on a line in your source and then use the <RUN> command to run to a breakpoint rather than using the extremely slow <ANIMATE> command. Using the <RUN> command on the 10-second delay below took about 10 seconds on my very old and very slow laptop.

Also, if you happen to be checking out my DelayCy() subsystem, I should mention that it really wasn't intended for long delays (you would need to increase the 'dloop' size to a rather large value). Instead, you might consider using smaller delays and a loop which also allows you to sample switches or other events at reasonable intervals during very long delays.

Good luck... Have fun...

tempx.png
 
Not quite sure whats going on but having a hell of a time making the MPlab sim work properly (and most likely me causing the problem).

Got it to do the 100mS cycle count ok and then when I tried to get it to do the 900mS one (by moving the breakpoints) it just refused to co-operate to the point I had to shut down MPlab completely to reset everything.

Going to go through the tutorials again tomorrow to work out what I'm doing wrong.

Just for an idea of how sloooow the Oshonsoft sim is, after 5 hours it was only just on halfway through simulating the 9 second delay.
 
As referenced in another post, I use the Oshonsoft sim for doing various bits & pieces of simulation, but sitting there for 30-40 minutes waiting for it to do a simulation of something like a 1 Second delay gets very tiring :( (I'm running an i5 quad core 2.6GHz PC with Win 10 Pro).

Any suggestions for other Sims that don't cost both arms and legs that may be quicker.
I ran the the 1 second delay in Oshonsoft PIC18F simulator, Basic window open and it took about 29 seconds. I think in the PIC16F simulator it would be about the same.
Intel I5 4200U, Windows 7
The Basic Program tracking must be disabled, otherwise it takes minutes
 
Hi Terry:

I wonder if there may be a code or setup problem? I had to set the 'clock' and 'dloop' constants in the DelayCy macro to 20 and 80, respectively. Also, you need to select 'absolute' mode for the project in MPLAB.

Here's the program I used to test the 1-sec/9-sec timing (below). Writing isochronous code can be daunting. You might consider using timer interrupts once you work out your simulation problems.

Good luck.

Code:
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        include <P16F628A.inc>
        errorlevel -302         ; suppress bank warnings
        list st=off             ; suppress symbol table
        radix   dec             ; default radix = decimal

  __CONFIG _LVP_OFF & _WDT_OFF & _INTOSC_OSC_NOCLKOUT & _MCLRE_OFF

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;            variables            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        cblock  0x70            ; common RAM
delayhi                         ; DelayCy() subsystem variable
        endc

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;  K8LH DelayCy() subsystem macro generates four instructions     ~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        radix dec
clock   equ     20              ; 4, 8, 12, 16, 20 (MHz), etc.
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     usecs*1000      ; cycles/millisecond multiplier
dloop   equ     80              ; loop size (minimum 5)
;
;  -- loop --  -- delay range --  -- memory overhead ----------
;  5-cyc loop, 11..327690 cycles,  9 words (+4 each macro call)
;  6-cyc loop, 11..393226 cycles, 10 words (+4 each macro call)
;  7-cyc loop, 11..458762 cycles, 11 words (+4 each macro call)
;  8-cyc loop, 11..524298 cycles, 12 words (+4 each macro call)
;
DelayCy macro   cycles          ; range, see above
    if (cycles<11)|(cycles>(dloop*65536+10))
        error " DelayCy range error "
    else
        movlw   high((cycles-11)/dloop)+1
        movwf   delayhi
        movlw   low ((cycles-11)/dloop)
;       rcall   uLoop-(((cycles-11)%dloop)*2)    ; (18F version)
        call    uLoop-((cycles-11)%dloop)        ; (16F version)
    endif
        endm

;******************************************************************
;  reset vector                                                   *
;******************************************************************
        org     0x000
;
swold   equ     0x20
count   equ     0x21
duration equ    0x22

        movlw    7              ;                                 |B0
        movwf    CMCON          ; camparator module off           |B0
        bsf     STATUS,RP0      ; bank 01                         |B1
        movlw   b'00111110'     ; make RA0 and output             |B1
        movwf   TRISA           ;  "                              |B1
        bcf     STATUS,RP0      ; bank 00                         |B0

        movlw   20              ; value for 100-msecs             |B0
        movwf   duration        ;  "                              |B0
        movwf   count           ;  "                              |B0
        bsf     PORTA,RA0       ;                                 |B0 <-- set PC here and
;                                                                         zero stopwatch
;   wreg  ____---____-----_____   inverted active lo sample
;  swold  _____---____-----____   switch state latch
;   wreg  ____-__-___-____-____   changes, press or release
;   wreg  ____-______-_________   filter out 'release' bits
;
durtmr
        comf    PORTA,W         ; sample active lo switches       |B0
        andlw   1<<RA3          ; on RA3 pin only                 |B0
        xorwf   swold,W         ; changes, press or release       |B0
        xorwf   swold,F         ; update switch state latch       |B0
        andwf   swold,W         ; filter out 'release' bits       |B0
        skpz                    ; new press? no, skip, else       |B0
        goto    nextfx          ; branch (exit timer loop)        |B0
d1      DelayCy(50*msecs-11)    ; 50-ms minus 11 cycle loop time  |B0
        movlw   1<<RA0          ; RA0 output 'toggle' mask        |B0
        decfsz  count,F         ; done? yes, skip, else           |B0
        goto    durtmr          ; loop (another 50 msecs)         |B0
toggle
        xorwf   PORTA,F         ; toggle RA0 output               |B0 <-- breakpoint
        movlw   20^180          ; toggle 1-sec & 9-sec timing     |B0
        xorwf   duration,W      ;  "                              |B0
        movwf   duration        ;  "                              |B0
        movwf   count           ; setup new timer loop count      |B0
        nop                     ;                                 |B0
        goto    d1              ;                                 |B0
nextfx
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;  K8LH DelayCy() subsystem 16-bit uLoop subroutine               ~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

a = dloop-1
    while a > 0
        nop                     ; (cycles-11)%dloop entry points  |
a -= 1
    endw
uLoop   addlw   -1              ; subtract 'dloop' loop time      |
        skpc                    ; borrow? no, skip, else          |
        decfsz  delayhi,F       ; done?  yes, skip, else          |
;       bra  uLoop-dloop*2+10   ; do another loop (18F version)   |
        goto uLoop-dloop+5      ; do another loop (16F version)   |
        return                  ;                                 |

        end
 
Last edited:
This is what I'm using for the timing sims (rather than running the whole program) and compiling in absolute mode.

I just drop in the delay code I'm working on at the time - the code does have an 'end' statement, I just missed it in the copy and paste.

Code:
; *******************************************************************************
;
    radix     dec
    errorlevel -302        ; Skip 'out of bank' nuisance messages

    include    <P16F628A.INC>

    __config _CP_OFF&_LVP_OFF&_BODEN_ON&_MCLRE_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC
;
; *******************************************************************************
; *           Allocate variables in general purpose register space               *
; *******************************************************************************
;
    CBLOCK    0x20        ; Start Data Block
    pulsetime
    CounterA        ; for time delay
    CounterB        ;     "    
    CounterC        ;     "    

    ENDC            ; End of Data Block
;
; *******************************************************************************
; * The 16F628 resets to 0x00.                                                  *
; * The Interrupt vector is at 0x04.                                            *
; *******************************************************************************
;
    ORG    0x00              
    goto    start        ;
;
    ORG    0x04
    goto    start        ;
;
start
    clrf    PORTA        ; Clear PORTA
    clrf    PORTB         ; start with LED off
    clrf    pulsetime
    movlw    0x07        ; Code to turn off the analog comparators
    movwf    CMCON        ;
    BANKSEL    TRISA        ;
    movlw    B'00001000'    ; PORTA,3 input rest all outputs
    movwf    TRISA        ;
    clrf    TRISB        ; PORTB to all outputs
    BANKSEL    PORTA        ;

incrat


;--------------------------------------------------------------------------------
p6    ;*** Overall 1SEC pulse 100mS mark 900mS space ***DONE***
    movlw    b'00100000'
    movwf    PORTB
p6a
    bsf    PORTA,0
    ;PIC Time Delay = 0.09999980 s with Osc = 20000000 Hz
    movlw    D'3'
    movwf    CounterC
    movlw    D'138'
    movwf    CounterB
    movlw    D'84'
    movwf    CounterA
loop6
    decfsz    CounterA,1
    goto    loop6
    decfsz    CounterB,1
    goto    loop6
    decfsz    CounterC,1
    goto    loop6
    NOP
    NOP
    btfss    PORTA,3        ; is switch pressed?
    goto    incrat
    bcf    PORTA,0

    ;PIC Time Delay =  899999.80uS with Osc = 20MHz
    movlw    D'14'
    movwf    CounterC
    movlw    D'183'
    movwf    CounterB
    movlw    D'27'
    movwf    CounterA
loop6a
    btfss    PORTA,3        ; is switch pressed?
    goto    incrat
    decfsz    CounterA,1
    goto    loop6a
    decfsz    CounterB,1
    goto    loop6a
    decfsz    CounterC,1
    goto    loop6a
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    goto    p6a

I ran the the 1 second delay in Oshonsoft PIC18F simulator, Basic window open and it took about 29 seconds.
Are you running just the original Oshonsoft Sim software or the Oshonsoft Basic Compiler with sim?

I'm running the last one.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top