setting values and percentages


Closed Thread
Results 1 to 38 of 38

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,623


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    How about
    Code:
    PWMValue = Percentage */ 10483
    ?

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    Bit of a fudge, but it works well enough

    Code:
    '*******************************************************************************
    ' Set Brightness levels for each channel
    
    
    brightness:
    
    B_max = (4095/100)*maxbright
    
    Lcdout $FE,2
    LCDOUT $FE,$80,"Set Max Brightness"
    IF H_butt = 0 THEN GOSUB up
    IF M_butt = 0 THEN GOSUB down
    
    If maxbright  = 100 then
    LCDOUT $FE,$C0,"Channel 1 "
    LCDOut $FE,$D4,#maxbright,"%"
    endif
    
    If maxbright  =0 or maxbright <10 then
    LCDOUT$FE,$C0,"Channel 1 "
    LCDOut $FE,$D4,dec1 maxbright,"% "
    endif
    
    if maxbright >=10 and maxbright <100 then
    LCDOUT$FE,$C0,"Channel 1 "
    LCDOut $FE,$D4,dec2 maxbright,"%   "
    endif
         
    If S_butt = 0 then
        pause 100 
        goto brightness2
    endif 
    goto brightness
    
    
    
    brightness2: 
     
    W_max = (4095/100)*maxbright
    
    Lcdout $FE,2
    LCDOUT $FE,$80,"Set Max Brightness"
    IF H_butt = 0 THEN GOSUB up
    IF M_butt = 0 THEN GOSUB down
    
    If maxbright  = 100 then
    LCDOUT $FE,$C0,"Channel 2 "
    LCDOut $FE,$D4,#maxbright,"%"
    endif
    
    If maxbright  =0 or maxbright <10 then
    LCDOUT$FE,$C0,"Channel 2 "
    LCDOut $FE,$D4,dec1 maxbright,"% "
    endif
    
    if maxbright >=10 and maxbright <100 then
    LCDOUT$FE,$C0,"Channel 2 "
    LCDOut $FE,$D4,dec2 maxbright,"%   "
    endif
    
    pause 200
    If S_butt = 0 then
        pause 100 
        LCDOUT $FE,1   
        goto mainmenu
    endif
    goto brightness2
    
    up:
        maxbright = maxbright + 1
        IF maxbright >= 100 THEN maxbright = 100
        pause 250
    RETURN
    down:
        maxbright = maxbright - 1
        IF maxbright <= 0 THEN maxbright = 0
        pause 250
    RETURN
    Again, the lack of floating point maths in PBP means the calculations are not exact, but this way every 1% increment equals a block of 41 steps on the PCA chip, so 50% brightness = 2050 but that's close enough to the 2047 is should be and to be honest I doubt if the human eye could distinguish the difference

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,623


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    Hi,
    If it works it works.
    If you want it a little better PWMValue = Percentage */ 10483 will give you 2047 at 50%.

    /Henrik.

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    So using my variables B_max = (4095/100)*maxbright would that be

    Code:
    B_max = maxbright */10483
    Nope - that don't work
    Last edited by Scampy; - 29th June 2014 at 20:21.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,623


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    If B_Max is the value you send to the PWM controller (0-4095) and maxbright is the percentage value (0-100) as entered by the user then yes.
    Actually, at 100% it'll give you 4094 so make that B_max = maxbright */10484 instead.

    /Henrik.

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    Quote Originally Posted by HenrikOlsson View Post
    If B_Max is the value you send to the PWM controller (0-4095) and maxbright is the percentage value (0-100) as entered by the user then yes.
    Actually, at 100% it'll give you 4094 so make that B_max = maxbright */10484 instead.

    /Henrik.
    Yes - B_max and W_max are the values that are sent to the PCA chip (0 - 4095). And maxbright has a value between 0 and 100 as you assumed. But using that line of code the values for B_max and W_max do not change from the pre-programmed default of 4095 after the menu option is used to change the max brightness level

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,623


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    Hi,
    Strange..... I tested the following code
    Code:
    HSEROUT["Program start",13]
    For i = 0 to 5
        Lookup2 i,[1, 10, 25, 50, 75, 100], maxbright
        B_max = maxbright */ 10484
        HSEROUT ["Maxbright: ", DEC3 maxbright, "     B_Max: ", DEC4 B_max, 13]
    NEXT
    And got the following results:
    Code:
    Program start
    Maxbright: 001     B_Max: 0040
    Maxbright: 010     B_Max: 0409
    Maxbright: 025     B_Max: 1023
    Maxbright: 050     B_Max: 2047
    Maxbright: 075     B_Max: 3071
    Maxbright: 100     B_Max: 4095
    Seems to work fine here....

    /Henrik.

  8. #8
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    Quote Originally Posted by Scampy View Post
    the values for B_max and W_max do not change from the pre-programmed default of 4095 after the menu option is used to change the max brightness level
    Is the default of 4095 inside the main loop and resetting B_max and W_max after the menu option returns to the main loop.

Similar Threads

  1. POT part values
    By Michael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th January 2009, 11:41
  2. Port Values
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 2nd January 2007, 21:44
  3. t in POT, c's values
    By selbstdual in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th August 2006, 00:30
  4. Numeric Values
    By Armando Herjim in forum General
    Replies: 8
    Last Post: - 28th June 2006, 02:54
  5. Wrong values with COSINE!
    By Eng4444 in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 8th May 2006, 17:59

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