This is probably quite simple


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    It's just plain bad practice to stop your code dead like that with an end statement... The end statement is there to tell the compiler there's no more code to compile, NOT to tell the processor to stop!

    If you want to end execution, send the device into an endless loop...

    deadloop:
    pause 1000
    goto deadloop ' loop till doomsday

    If you examine what's happening in your PIC, the program counter keeps incrementing and your PIC will keep on executing whatever code is remenant in the PIC. When you program a PIC, unless you specify otherwise, your PIC will not first be erased, all that happens is your new code replaces what was there previously. If your new code is smaller than what was previously in memory, then some of the previous content will remain and once your code executes, it will happilly continue into whatever garbage was there previously. You must therefore terminate your program logically. Most if not all programs are continuous loops. If your application demands a 'once-only' execution, you must program-in a suitable termination. Even if your PIC has first been erased, the PIC will continue with NOP statements untill it reaches the end of program codespace at which point what it will do will be unpredictable... it might restart, it might not, but it sure as hell will be unstable.

    Oh... and the reason I put a PAUSE statement in is that PICBasic will insert code to keep the watchdog timer happy. If you just had...

    deadloop:
    goto deadloop

    then the Watchdog (if enabled) will time out and restart the PIC as PICBasic would not had inserted a CLRWDT in that instance.

    ...or of course use PICBasics STOP statement!

    you example expanded...
    .. ..
    PAUSE 5000 'turn on sound for 5 seconds
    PORTB.1 = 0
    PORTB.4 = 0 ' TURN OFF POWER
    STOP
    end

  2. #2
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    Thanks much for the info, I am learning (more by making mistakes than otherwise). I am embarrased to say this, but even tho I wrote it in my program "use 10k pullup on MCLR", I neglected to do it. Now that it is installed, things work like I expect.

  3. #3
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    I tried the pause loop and the stop command but both leave the oscillator running and the current draw is 800 microamps. I tried sleep $FFF with the watchdog timer turned off;this stops the oscillator and, after a few minutes, it settles down to 40 microamps current draw which is quite acceptable.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    >I tried the pause loop and the stop command but both leave the oscillator running and the current draw is...

    Yes, but getting the current down is moot because if you look at your logical flow when you get your hardware sorted out the PIC will switch itself off before you get to the STOP point... it's only until then you need a way of stopping you code, thereafter, if everything is working as it should, you'll never get to that point (well in reality you will but the PSU would be in the throws of shutting down anyway).

  5. #5
    tbriggs's Avatar
    tbriggs Guest


    Did you find this post helpful? Yes | No

    Question Disable watchdog timer

    How do you disable the watchdog timer in picbasic? I am trying to step through a program with the ICD2 and I keep getting the error that you can't debug with the watchdog timer enabled.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    You've not specified what PIC you're using... so, go look in the Datasheet for your PIC... it's usually a setting of the Config Word and that information can be found in the "Special Features of the CPU" section of the Datasheet. When you program your PIC, it should appear as one of the options you can manually switch ON or OFF.

  7. #7
    tbriggs's Avatar
    tbriggs Guest


    Did you find this post helpful? Yes | No

    Smile Watchdog timer on PIC18F452

    Sorry about that....I am using the PIC18F452 that came with the PICDEM2 board.

    I started poking around in some of the files and came across "_WDT_OFF_2H" in a "__config" statement. That solved my problem.

    Thanks for the help!

Similar Threads

  1. Simple RF remote control code
    By Bruce in forum Code Examples
    Replies: 13
    Last Post: - 22nd January 2014, 11:45
  2. Simple Blinking LED - WTF!!
    By johnnylynx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st February 2010, 07:19
  3. Simple LCD code not working!...WHY?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th November 2009, 20:48
  4. Replies: 0
    Last Post: - 3rd February 2009, 00:23
  5. Replies: 4
    Last Post: - 7th September 2005, 15:11

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