For...Next loop Steps DEC questions


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96

    Red face For...Next loop Steps DEC questions

    Anyone,
    Can you create a decimal step for the FOR....NEXT LOOP?
    How about a Variable step?

    Ex:

    D VAR BYTE
    D = VALUE/10
    FOR value = 0 to 12 STEP + D

    or....
    For value = 0 to 12 step + .1
    I realize I am dealing with decimal values....can I use DEC3 command or somthing else to make this work?

    thanks
    Padawan-78

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by earltyso View Post
    Anyone,
    Can you create a decimal step for the FOR....NEXT LOOP?
    How about a Variable step?

    Ex:

    D VAR BYTE
    D = VALUE/10
    FOR value = 0 to 12 STEP + D

    or....
    For value = 0 to 12 step + .1
    I realize I am dealing with decimal values....can I use DEC3 command or somthing else to make this work?

    thanks
    Variable step . . .
    Code:
    myVar Var byte ' up to 255 counts stored here
    If PortA.0 = 1 then myVar=12
    
    FOR value = 0 to myVar STEP + D
    or something to that effect . . .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Unhappy another try

    I thought I had better restate what I am trying to do.
    I want to simulate an 8 bit input from A2D (referenced to Vpp +5V)
    using a FOR....NEXT loop. I want to see 0.00 climb up to 5.00 VDC...... on my LCD

    Can someone tell me why my code below does not work?

    Y var word
    Value var byte

    FOR Value = 0 to 0 STEP 255
    Y =(Value/255)*5 '8 bit resolution math
    LCDOUT 254,row1+1,"BATTERY ",DEC Y,".",DEC2 Y, " VDC" 'decimal point 3 sig figs
    pause 10
    next Value

    All I get on my screen is "BATTERY 0.00 VDC" and no change

    thanks...
    Padawan-78

  4. #4
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    your For value = 0 to 0 will only go through once.

  5. #5
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    another try

    --------------------------------------------------------------------------------
    OK, so i screwed up my copy and paste, code still not working....
    any ideas??

    Y var word
    Value var byte

    FOR Value = 0 to 255
    Y =(Value/255)*5 '8 bit resolution math
    LCDOUT 254,row1+1,"BATTERY ",DEC Y,".",DEC2 Y, " VDC" 'decimal point 3 sig figs
    pause 10
    next Value

    All I get on my screen is "BATTERY 0.00 VDC" and no change

    thanks...
    Padawan-78

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Try this:

    Code:
    Y var word
    Value var byte
    
    FOR Value = 0 to 255
        Y = ( Value * 51 ) / 26   'divided down from * 255 / 130
        LCDOUT 254,row1+1,"BATTERY:",DEC1 ( Y / 100 ),".",DEC2 ( Y // 100 )," VDC"
        pause 100
    Next Value

  7. #7
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Talking perfect

    SkiMask,

    Working great now....I realized that I had
    Y VAR BYTE instead of Y VAR WORD which caused my math to be all funky...
    I have also never used the // modulus math command either, I think I understand how that works now, I will play with 4 sig figs now to see If I get the rest all worked out.

    thanks a million!
    Padawan-78

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by earltyso View Post
    SkiMask,
    Working great now....I realized that I had
    Y VAR BYTE instead of Y VAR WORD which caused my math to be all funky...
    I have also never used the // modulus math command either, I think I understand how that works now, I will play with 4 sig figs now to see If I get the rest all worked out.
    thanks a million!
    If you've got PBP 2.50, you can use LONGs and get quite a bit of resolution...of course that'll be limited to your ADC also. 4 sig figs are easily doable with a 10-bit ADC...which obviously the PICs usually have.

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 17:48
  2. Using input from Switch to control a loop
    By MrRoboto in forum mel PIC BASIC
    Replies: 9
    Last Post: - 2nd February 2009, 06:02
  3. PBPL 2.50 observations
    By BrianT in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 18th September 2007, 00:58
  4. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 18:42
  5. Newbie question:
    By Izone in forum mel PIC BASIC
    Replies: 2
    Last Post: - 26th February 2006, 17:24

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