MPLab SIM question


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2007
    Posts
    20

    Default MPLab SIM question

    Well, my DS18B20 program is now running nicely on a PIC18F2620 with decimal values (Anyone interested in reading that thread can find it at http://www.picbasic.co.uk/forum/showthread.php?t=7533).

    Anyway, I discovered the fact that I can use MPLab SIM with PBP just 2 days ago and I am ecstatic! I tested some really basic PBP programs with MPLab SIM and was able to input to pins and read registers. Then I tried my DS18B20 program (the source-code is attached at the bottom of this post in text format).

    Consider the following lines from my program –
    Code:
    1	ReadDS18B20:  
    2   		OWOUT Comm_Pin, 1, [$CC, $44] ' Skip ROM search & do temp conversion
    3   		ReadBusy:
    4   		OWIN Comm_Pin, 4, [Busy] ' Read busy-bit
    5    		IF Busy = 0 THEN ReadBusy ' Loop until Busy=1 (Temp conversion complete)
    Here, Comm_Pin was set to PortB.4 at the top of the code somewhere (see the complete code). The problem I’m having is that after line 5, it jumps to line 3 and seems to be in an infinite loop. Of course I understand why it happens! It’s because PortB.4 never gets to 1 and this is where I ask for your help.

    I have tried to create a stimulus that sets RB4 to 1 at the beginning of the program and keeps it at 1 for good. But when I step through the program, I see RB4 changing periodically between 0 and 1. So, I am not able to simulate a valid bit “1” at RB4. Also, how does anyone go about implementing this:

    Code:
    OWIN Comm_Pin, 2, [RAWTEMP.LowByte, RAWTEMP.HighByte]
    I mean how can I simulate a bitstream arriving at PortB.4? Any help is much appreciated. Thanks.
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    never messed with this feature, but i think it's doable with Clock Stimulus and/or Pin/Register action

    Probably it's something i would never simulate anyways.. still and never been a sim user/fan
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Oct 2007
    Location
    Vancouver, BC, Canada
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    have you tried lower the pull up resistor ? I got the problem other day, and lower the resistor to 2k2 then everything work.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    pssst... it's more about MPLAB SIM
    Quote Originally Posted by POST #1
    my DS18B20 program is now running nicely on a PIC18F2620 .......I mean how can I simulate a bitstream arriving at PortB.4? Any help is much appreciated. Thanks.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Oct 2007
    Location
    Vancouver, BC, Canada
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    sorry, i misread.

  6. #6
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    It may be possible to do what you want. Look under Debugger->SCL generator->New workbook->Register injection.

    Here you will find that you can specify a stimulus file. I haven't used this feature, but I'm sure that it works and will be wonderful to use. I have played a lot with the stimulus features and can encourage others to try the simulator.

    Let us know how it goes with the injection feature.

  7. #7
    Join Date
    Nov 2007
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    It may be possible to do what you want. Look under Debugger->SCL generator->New workbook->Register injection.

    Here you will find that you can specify a stimulus file. I haven't used this feature, but I'm sure that it works and will be wonderful to use. I have played a lot with the stimulus features and can encourage others to try the simulator.

    Let us know how it goes with the injection feature.
    I guess I picked a difficult one to simulate.

    The problem is that OWIN and OWOUT are both toggling the TRISB.4 bit (changing this pin between Input and Output) and therefore a constant "1" for PortB.4 (The DS18B20's DQ pin) did not work for me. What I did was create an asynchronous event for RB4 (set RB to High) and whenever my TRISB was 00010000 (RB4 is input), I just hit this asynchronous event that set RB to 1. If I was careful and hit this event at the right time, the "Busy" variable would finally be 1 and thus the program would finally get out of the infinite loop.

    I didn't play with the PORT/Register injection. I guess the easiest thing would be to define a value for RAWTEMP at the beginning of the program (just for debugging process) and see if my temperature conversion subroutines worked correctly (and they did ). I wanted to check the negative temperature read and conversion routine in particular since I was inside my house and the outside temperature was not below zero, or I didn't feel like pouring liquid nitrogen on the sensor (not that I had any liquid nitrogen in my house).

    If anyone else wants to take a shot at simulating the One-Wire commands correctly (from a timing point of view), good luck.
    Last edited by presario1425; - 3rd December 2007 at 21:29.

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. Linker/COFF debugging in MPLAB SIM
    By RichardBowser in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th January 2007, 18:28
  3. Using MPLAB SIM
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th July 2006, 04:20
  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 : 1

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