setting values and percentages


Closed Thread
Results 1 to 38 of 38

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    Quote Originally Posted by richard View Post
    maybe malcom could refresh us on the issue , but as I understand it
    1.the external pwm chip has 4096 steps
    2.the loop update time is in 1 sec intervals
    3. the desired fade in /out period divided by the loop time yields too few "pwm" steps for a smooth looking transition if you simply divide 4096 by the number of available steps

    my theory is that if the steps are chosen well the effect may be smoother
    Close

    With a friends help I've implemented a routine using the internal timers to get timings under a second.

    Code:
    ASM
    INT_LIST  macro   ;  IntSource,   Label,        Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   ASM,  yes        
        endm
        INT_CREATE                                  ; Creates the interrupt processor
    ENDASM
    
    T1CON = %00000001                               ; free-running, 1:1 prescaler
    TMR1H = %11111111
    TMR1L = %11111011
    @   INT_ENABLE   TMR1_INT                       ; enable Timer1 interrupts
    And

    Code:
    ToggleLED1:
    TMR1H = %11111111
    TMR1L = %11111011
    pcaPwmValue0=pcaPwmValue0+1 
    pcaPwmValue1=pcaPwmValue1+1 
    @ INT_RETURN
    I can go from 0 - 4095 in less than two minutes, which helps in test runs.

    The ramp up is controlled by the case statement

    Code:
    case DAWN
    lcdout $FE,$80+15,"DAWN "  
    if pcaPwmValue0 => blue_delay_in then 
    B_PWM=B_PWM+1
    pcaPwmValue0 = 0 
    endif
    if B_PWM => B_MAX then   
    Blue_Day_Cycle = DAY
    endif
    The value for the pulse width is then written to the PCA chip in the main loop

    Code:
    pcaChannel = 0                                              ;Set a PWM channel
    lcdout $FE,$80,"CH1"
    i2cControl = $6 + 4*pcaChannel                              ;LED0_ON_L $6
    I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,0,B_PWM ]
    I have everything working fine, when using pre-set values for the fade in times and brightness and can do a full dawn, day, dusk, night cycle in five minutes, I just need to be able to sort out the manual settings for adjusting the the brightness so I can enter 0-100% rather than 0 - 4095 on the LCD

    Hope this additional information helps

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    How about
    Code:
    PWMValue = Percentage */ 10483
    ?

  3. #3
    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

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    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.

  5. #5
    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 19:21.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    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.

  7. #7
    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

Similar Threads

  1. POT part values
    By Michael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th January 2009, 10:41
  2. Port Values
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 2nd January 2007, 20:44
  3. t in POT, c's values
    By selbstdual in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th August 2006, 23:30
  4. Numeric Values
    By Armando Herjim in forum General
    Replies: 8
    Last Post: - 28th June 2006, 01:54
  5. Wrong values with COSINE!
    By Eng4444 in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 8th May 2006, 16: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