WTF? Am I crazy?


Closed Thread
Results 1 to 6 of 6
  1. #1
    RichardBowser's Avatar
    RichardBowser Guest

    Question WTF? Am I crazy?

    Hi everyone

    I am really puzzled, though I suspect my difficulty has a TRIVIAL solution. I am trying to insert a parameterized iteration of do-nothings to allow simple tuning of application software to match target hardware. It SHOULD be easy: I declare “TtW” CON $n” for (Time to Wait). Then here’s what I try:

    movlw _TtW,0
    movwf _WaitCt,0
    movlw _TtW
    movwf _WaitCt,0
    decf _WaitCt,F,0
    btfss STATUS,Z ;normally WaitCt <> 0, so Z is clear
    goto $-2

    Only it doesn’t work. If TtW = 1, it immediately falls through. If TtW = 2, then it hangs infinitely. If I correct that by inserting a second “decf” then WaitCt = 0 when it reaches the bit test and then it just falls through. Yet I’ve seen similar code used in MANY known working routines. But it ONLY skips hanging if TtW = the nunber of "decf" instructions before the "btfss".

    Why will the above not just keep on decrementing WaitCt until it reaches a terminal 0?
    Last edited by RichardBowser; - 6th July 2006 at 21:53.

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


    Did you find this post helpful? Yes | No

    Default

    for sure you use a 18F serie right? change your GOTO $-2 to GOTO $-4

    what happen now?
    Steve

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

  3. #3
    RichardBowser's Avatar
    RichardBowser Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for your responsive suggestion. I am using an 18F8720. I tried a goto $-4 as you suggested, but it stall hangs infinitely. Evidently I need to understand relative relocation better. It has seemed to me that each count represented one instruction, and each instruction in the 18 series occopies one program word. So that made sense to me. I won't bother listing everything I tried, but I just downloaded MPLAB 7.40 and I would like to try it in single step mode in their SIM debugger. I'm sure I'm dong something wrong!

    Thanks again for trying!

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hey Bowser,

    Try this...
    Code:
        CHK?RP  _WaitCt
        movlw   _TtW
        movwf   _WaitCt
    DelayLoop
        decfsz  _WaitCt, F
        goto    DelayLoop
    DT

  5. #5
    RichardBowser's Avatar
    RichardBowser Guest


    Did you find this post helpful? Yes | No

    Smile Thanks, Darrel

    You answered my question quite succinctly: YES - I was crazy. Your solution solved the problem that was bugging me. And after getting that fixed, I took a better look at my code. I had several at least questionable lines in there. A cleaned up and working version is:

    movlw _TtW
    wloop
    decfsz _Wct,F
    goto wloop

    That helped a BUNCH. (Sometimes it's good to know the truth.)

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Richard,

    Great! Glad it worked out for you.

    I guess I was a little short there, but now that you've got that figured out, you might want to take a look at this routine.
    http://www.picbasic.co.uk/forum/showthread.php?p=22098

    With that you can just go...
    Code:
    @  DelayUS  6
    for a 6us delay.

    It looks really big, but it actually compiles to almost exactly the same thing you have. Without having to worry about OSC freq.

    Don't know if that helps or not, but thought I'd mention it.
    <br>
    DT

Similar Threads

  1. 12f675 making me a crazy person
    By Meriachee in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 16th September 2009, 21:55
  2. 18f4550 usb problem.. so im getting crazy..
    By MeSaKu in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th May 2009, 22:03
  3. Using portb as inputs PIC goes crazy
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th November 2005, 14:15
  4. My Code get crazy after i add interrupt
    By jetpr in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th May 2005, 04:43

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