PDA

View Full Version : MPLab SIM question



presario1425
- 30th November 2007, 19:56
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 –



1 ReadDS18B20:
2 OWOUT Comm_Pin, 1, [$CC, $44] ' Skip ROM search & do temp conversion
3 ReadBusy:
4 OWIN Comm_Pin, 4, ' Read busy-bit
5 IF Busy = 0 THEN [B]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:


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.

mister_e
- 30th November 2007, 22:38
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

KVLV
- 30th November 2007, 23:17
have you tried lower the pull up resistor ? I got the problem other day, and lower the resistor to 2k2 then everything work.

mister_e
- 30th November 2007, 23:50
pssst... it's more about MPLAB SIM

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.

KVLV
- 1st December 2007, 04:46
sorry, i misread.

Jerson
- 1st December 2007, 07:23
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.

presario1425
- 3rd December 2007, 21:22
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 :D ). 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.