Mplab Sim


Closed Thread
Results 1 to 16 of 16

Thread: Mplab Sim

  1. #1
    Join Date
    Apr 2007
    Posts
    5

    Question Mplab Sim

    Hi everyone! Let me start by saying that I'm new to PIC, I have done some programing VB, C, C++, and some others. I have written a program in MCSP, it appears to compile fine. I then loaded the *.hex file in to MPLab and started the simulator with simulator logic analyzer, and stimulus. When if fire an input nothig changes, and it some times crashes, is there a trick to get it to work right? Or is there a better way of checking out a program before building the circut and programing a chip?

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    show us your code - otherwise the sky is the limit for guesses as to why you are having issues
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Apr 2007
    Posts
    5


    Did you find this post helpful? Yes | No

    Exclamation Mp Sim

    this go in a car, it plays a sound track and flashes some leds with the sound track. It also lights the leds with the head lights and flashes them with the turn signals. there are two diffrent way it plays the soundtrack dependingon rather the car is running or not. I have to make the circut board for this as well so I need to know that this runs correctly so the PCB will work or if I need to change the PCB. That's where MPLAB SIM comes in, But I can't get it to work. I have till mid june to have everything complete and instaled in the car for a national show, that is design and make the PCB program the PIC and the sound track, put it all together and instal it. BTW I'm using a 16F628 chip.

    'Declared variables
    PLAYOUT var PORTA.0
    RESET VAR PORTA.1
    CAT_EYE_l VAR PORTA.2
    CAT_EYE_R VAR PORTA.3
    ARMED VAR PORTA.4
    ACC VAR PORTB.0
    LIGHTS VAR PORTB.1
    TURN_L VAR PORTB.2
    TURN_R VAR PORTB.3
    PIR VAR PORTB.4
    PUSH_BUTTON VAR PORTB.5
    WAITOUT VAR PORTB.7

    'DEFINE PORT DIRECTIONS & VALUES
    TRISA = %11111111
    TRISB = %11000000 'portb.6 and .7 out puts all others in put
    '================================================= ==============================
    '///////set initial pin states/////////////////////////
    '================================================= ==============================
    LOW PLAYOUT
    LOW RESET
    LOW CAT_EYE_L
    LOW CAT_EYE_R
    LOW ARMED
    HIGH WAITOUT
    '================================================= ==============================
    '////////MAIN PROGRAM STARTS HERE//////////////
    '================================================= ==============================
    Pause 30000
    LOW WAITOUT
    HIGH ARMED
    '================================================= ==============================
    '///////MAIN LOOP STARTS HERE
    '================================================= ==============================
    MAIN:
    IF ACC = 1 THEN
    GOSUB RUN
    ELSE
    GOSUB SHOW
    ENDIF
    GOTO MAIN
    '================================================= ==============================
    'RUN LOOP STARTS HERE
    '================================================= ==============================
    RUN:

    IF LIGHTS = 1 THEN
    HIGH CAT_EYE_L
    HIGH CAT_EYE_R
    ELSE
    LOW CAT_EYE_L
    LOW CAT_EYE_R
    ENDIF
    IF PUSH_BUTTON = 1 THEN
    GOSUB PLAY
    HIGH ARMED
    LOW WAITOUT
    ENDIF
    GOSUB TURN
    RETURN
    '================================================= ==============================
    'SHOW LOOP STARTS HERE
    '================================================= ==============================
    SHOW:
    IF PIR = 1 THEN
    LOW ARMED
    HIGH WAITOUT
    GOSUB PLAY
    PAUSE 60000
    LOW WAITOUT
    HIGH ARMED
    ENDIF
    RETURN
    '================================================= ==============================
    'PLAY STARTS HERE
    '================================================= ==============================
    PLAY:
    LOW ARMED
    HIGH WAITOUT

    HIGH CAT_EYE_L
    HIGH CAT_EYE_R

    PulsOut RESET,10
    Pause 100

    PulsOut PLAYOUT,10
    Pause 820

    LOW CAT_EYE_L
    LOW CAT_EYE_R
    Pause 50

    HIGH CAT_EYE_L
    HIGH CAT_EYE_R
    Pause 2550

    LOW CAT_EYE_L
    LOW CAT_EYE_R
    Pause 50

    HIGH CAT_EYE_L
    HIGH CAT_EYE_R
    Pause 5500

    LOW CAT_EYE_L
    LOW CAT_EYE_R
    RETURN
    '================================================= ==============================
    'TURN STARTS HERE
    '================================================= ==============================
    TURN:
    IF LIGHTS = 1 THEN
    IF TURN_L = 1 THEN
    LOW CAT_EYE_L
    ELSE
    HIGH CAT_EYE_L
    ENDIF
    IF TURN_R = 1 THEN
    LOW CAT_EYE_R
    ELSE
    HIGH CAT_EYE_R
    ENDIF
    ELSE
    IF TURN_L = 1 THEN
    HIGH CAT_EYE_L
    ELSE
    LOW CAT_EYE_L
    ENDIF
    IF TURN_R = 1 THEN
    HIGH CAT_EYE_R
    ELSE
    LOW CAT_EYE_R
    ENDIF
    ENDIF
    RETURN

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink I/O salad ...

    Hi,

    The first thing I see is you have mixed inputs and outputs ...

    ex; if PIR = 1 then ... etc.etc. ... and PIR is declared as an output ( possible ... but really surprising here !!! )

    same for "lights" ...

    Begin by checking all your I/0 declares ... ( 0 for OUTPUT and 1 for Input = simple !!! )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Apr 2007
    Posts
    5


    Did you find this post helpful? Yes | No

    Question Mplab Sim

    That is " if pir is high then...", same with the lights "if lights high then...".
    Or have I done something wrong?

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Talking

    Hi,

    I've just tried to explain you you were reading your outputs instead of the inputs ...

    Of course, MPSIM has some trouble with that !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi,
    I've just tried to explain you you were reading your outputs instead of the inputs ...
    Of course, MPSIM has some trouble with that !!!
    Alain
    The HIGH and LOW commands automatically set the respective pins to outputs....but the few input statement still won't work....

    Also, PIR is a named register on PICs. You might not want to use that name for a variable. Might mess you up in the future. Same with RESET (could be confused with the MCLR function somewhere sometime) and ACC (some might confuse that with Accumulator).

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink Cool, cool ...

    Hi, Skimask

    the "reserved word" is PIR1 ... then, no Pb with PIR.


    Now look at output initialisation :

    - the named outputs are declared as inputs in the TRIS ... and vice-versa.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Skimask
    the "reserved word" is PIR1 ... then, no Pb with PIR.

    Now look at output initialisation :
    - the named outputs are declared as inputs in the TRIS ... and vice-versa.

    Alain
    PIR - just pointing the PIR out as well as the others for future reference, something that might cause a problem in the future.

    I/O - yep, noticed that right away, but you got to it first

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Talking

    Hi, Skimask

    You know what ???

    I really DO HATE "tuning" ....

    LOL

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile I/O Salad indeed ...

    More to try

    1)Turn the Comparators OFF to get PORTA to work as intended

    2)
    Code:
    TRISA = %11111111
    You set all of PORTA inputs here but make them outputs in your code

    3)
    Code:
    TRISB = %11000000 'portb.6 and .7 out puts all others in put
    You got the comment backwards (0=output, 1 = Input)

    4)Remember RA4 is open drain so it needs a pullup on your real circuit

    5)
    Oh, and it it were me, I would start with this and make this work with the Simulator
    Code:
    TRISB=1
    MAIN:
    IF PORTB.0 = 1 then
    	PORTB.1=1
    ELSE
    	PORTB.1=0
    ENDIF
    GOTO MAIN
    Post back after you try some of these
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  12. #12
    Join Date
    Apr 2007
    Posts
    5


    Did you find this post helpful? Yes | No

    Question Mplab Sim

    I have made these changes:
    1 trisa is now %00000000
    2 trisb is now %00111111
    3 pir is now pirin this should reduse any confusition.
    Would this be correct? I will later change armed from porta.4 to portb.6 to not have to use a pull up resister and reduse current draw to a min.

  13. #13
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Question

    Quote Originally Posted by Acetronics View Post
    I really DO HATE "tuning" ....
    Alain
    I think I missed something in the translation...

  14. #14
    Join Date
    Apr 2007
    Posts
    5


    Did you find this post helpful? Yes | No

    Cool Mplab Sim

    Now that i have the input output thing fixed, I have determined that the program is hanging in the "pause" statments, is there a trick to get thes to work? I changed them to "pauseus" and everything seem to be perfict. Thank you to all that help this noobe.

  15. #15
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink The show might go on, then ...

    Quote Originally Posted by steelman View Post
    Now that i have the input output thing fixed, I have determined that the program is hanging in the "pause" statments, is there a trick to get thes to work? I changed them to "pauseus" and everything seem to be perfict. Thank you to all that help this noobe.

    Hi,

    your answer is in the FAQs ... MPSIM is a simulator, yes ... but not a REAL TIME simulator !!!

    See MPSIM Help section will show you that ... in official details.

    Time to understand the difference between simulated world and real World ... LOL !

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  16. #16
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by steelman View Post
    I have determined that the program is hanging in the "pause" statments, is there a trick to get thes to work? I changed them to "pauseus" and everything seem to be perfict. Thank you to all that help this noobe.
    Is it actually hanging up in the pause statement in the sim or is MPSIM just simulating them really slowly? Try changing the pause statements in the program to something a lot lower than you have and see what happens.

Similar Threads

  1. MPLAB SIM timing vs Real life
    By Bronurstomp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th July 2008, 16:32
  2. MPLab SIM question
    By presario1425 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 3rd December 2007, 21:22
  3. Linker/COFF debugging in MPLAB SIM
    By RichardBowser in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th January 2007, 18:28
  4. Tracing code in MPLAB Sim
    By ErnieM in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th August 2005, 16:00
  5. pause loop lockup with mplab sim
    By power67 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th February 2005, 13:10

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts