If - then statements


Closed Thread
Results 1 to 13 of 13

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Hi Russ,

    When using Inline IF statements, you don't need the ENDIF.

    It's either

    if S4=0 then t =500

    -or-

    if S4=0 then
        t =500
    endif

    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Thanks, Darrel, I removed the endif and now the compiler is happy and so am I. I guess PicBasic Pro Demo does not support "else" which got me off track in the first place.

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


    Did you find this post helpful? Yes | No

    Default

    I've never used the DEMO version of PicBasic Pro. So, I can't really say for sure, but, It doesn't seem like it would be much of a DEMO if it couldn't even do IF-ELSE-ENDIF's.

    Maybe there was a problem there too.

    This should work.
    Code:
    IF S4=0 then 
        t =500
    ELSE
        t =5000
    ENDIF
    This will Not.
    Code:
    IF S4=0 then t =500 : ELSE t = 5000 : ENDIF
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Thanks, Darrel. I have another question: My timing was way off so I measured the frequency at clkout, it was 2.28 mHz instead of 1.0. I can adjust T to compensate, but is there a way to reset the oscillator?

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


    Did you find this post helpful? Yes | No

    Default

    What type of oscillator configuration are you using?

    Since you're expecting to see 1mhz on the clockout pin, I assume you're using the internal 4mhz oscillator. Otherwise you would see the crystal frequency, instead of FOSC/4.

    And while the internal oscillators are Never exactly 4.0000mhz, they'll Never be at 9.12mhz (2.28*4). (unless the chip is just bad, also unlikely)

    If instead, you're using an external crystal? You may have the wrong freq crystal, or the technique used to measure the frequency is affecting the oscillator, giving an incorrect reading.

    But since you say that the program is running at the wrong speed to begin with, I would guess it's the wrong crystal. Or possibly the wrong or no capacitors on the crystal.

    DT

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


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply. There is no crystal, I am using the internal oscillator with clock out. I read somewhere that the oscillator calibration should be preserved, but did not tell me how to do it. I assume that the oscillator is running at its max. My circuit is attached.
    Attached Images Attached Images  

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Smile Let me add some resistors to your schematic

    Pull up resistors as attached would be much safer.



    -------------------
    Attached Images Attached Images  
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 22:31
  2. if-then statements
    By CrazyCooter in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th August 2007, 06:28
  3. Multiple IF-THEN statements
    By DavidK in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 20th June 2007, 19:28
  4. Proton Commands & statements
    By Lotondo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th November 2006, 00:37
  5. time for PBP statements
    By fnovau in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 25th October 2006, 20:42

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