Smooth LED fading via PWM


Closed Thread
Results 1 to 40 of 55

Hybrid View

  1. #1
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Smooth LED fading via PWM

    How about something like this:

    Code:
    Data 1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3, _
      3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,5,5,5, _
      5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,8,8,8,8,8,8,9,9, _
      9,9,10,10,10,10,10,11,11,11,11,12,12,12,13,13,13,13, _
      14,14,14,15,15,15,16,16,16,17,17,18,18,18,19,19,20,  _
      20,20,21,21,22,22,23,23,24,24,25,26,26,27,27,28,29,  _
      29,30,31,31,32,33,33,34,35,36,36,37,38,39,40,41,42,  _
      42,43,44,45,46,47,48,50,51,52,53,54,55,57,58,59,60,  _
      62,63,64,66,67,69,70,72,74,75,77,79,80,82,84,86,88,  _
      90,91,94,96,98,100,102,104,107,109,111,114,116,119,  _
      122,124,127,130,133,136,139,142,145,148,151,155,158, _
      161,165,169,172,176,180,184,188,192,196,201,205,210, _
      214,219,224,229,234,239,244,250,255
     
    Smooth_fade:
        IF Count1 = 0 THEN 
             duty = 0
        ELSE
             IF Count1 < 26 THEN 
                 duty = 1
             ELSE
                 Read Count1-25, duty
             ENDIF
        ENDIF
        RETURN
    
    WriteUserByte:
        WRITE 255, UserByte
        RETURN
    
    ReadUserByte:
        READ 255, UserByte
        RETURN

    Now you have the upper 25 EEPROM addresses to use. More space could be saved by using similar logic. But this hopefully gets the point across.

    Good luck,
    Steve
    Last edited by SteveB; - 20th September 2011 at 04:56.

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Smooth LED fading via PWM

    My math was a little off, the line for the reading of the EEPROM should be

    Code:
    READ count1-26, duty
    As a side note, you could make it really simple just by leaving the original table as-is and using this:

    Code:
    Smooth_fade: 
         IF Count1 = 0 THEN 
              duty = 0 
         ELSE 
              Read Count1, duty 
         ENDIF
    RETURN
    
    WriteUserByte: 
         WRITE 0, UserByte 
         RETURN
    
    ReadUserByte: 
         READ 0, UserByte 
         RETURN
    Last edited by SteveB; - 20th September 2011 at 06:03.

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Smooth LED fading via PWM

    Bert.. re putting my table into program memory....it's still a work in progress and with only 400 bytes left...it only takes a couple of debug commands and I'm over the limit :-(

    Byte_Butcher ...that's a good lead!

    SteveB..... if I'm reading your code right, it's what Byte_butcher proposed? (& is good clawback of EEPROM)

    I'll have a dabble later....many thanks for the input.

  4. #4
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Smooth LED fading via PWM

    Quote Originally Posted by HankMcSpank View Post
    SteveB..... if I'm reading your code right, it's what Byte_butcher proposed? (& is good clawback of EEPROM)
    Yes, I took the suggestion from Byte_Butcher and fleshed it out a little.

  5. #5
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default Re: Smooth LED fading via PWM

    I've gotta go stack wood, so this is quickk and needs fixing, but this is the sort of thing I was thinking:


    Code:
    count = count + 1
    
    If count < 33 then address = 1                   'all "counts" less than 33 point to address 1 
            if count < 1 then 
            address = 0                                     'unless count is 0. Then it points to address 0
            endif
            else address = count - 33                     'all counts above 33 get offset down so they pick up the sequence starting at address 2
    endif


    steve

    edited to add:

    Never mind, Steve B already did it.
    Last edited by Byte_Butcher; - 20th September 2011 at 22:57.

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Smooth LED fading via PWM

    IS there a rapido way of seeing the whole contents of EEPROM?

    I'm storing a user determined byte, using this type of way..

    Code:
    DEFAULT_CONFIG  DATA 1
    default_config_shadow var byte
    
    default_config_shadow = 101010              '
    WRITE default_config_shadow, default_config   'write the above to EEPROM
    
    read default_config, default_config_shadow
    
    DEBUG "def_shadow=",BIN default_config_shadow,13,10
    then immdeiately afterwards, I lob another 254 bytes into EEprom too...
    Code:
    data   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, _
    1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, _
    2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4, _
    4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,8,8, _
    8,8,8,8,9,9,9,9,10,10,10,10,10,11,11,11,11,12,12,12, _
    13,13,13,13,14,14,14,15,15,15,16,16,16,17,17,18,18,18, _
    19,19,20,20,20,21,21,22,22,23,23,24,24,25,26,26,27,27,28, _
    29,29,30,31,31,32,33,33,34,35,36,36,37,38,39,40,41,42,42, _
    43,44,45,46,47,48,50,51,52,53,54,55,57,58,59,60,62,63,64, _
    66,67,69,70,72,74,75,77,79,80,82,84,86,88,90,91,94,96,98, _
    100,102,104,107,109,111,114,116,119,122,124,127,130,133,136, _
    139,142,145,148,151,155,158,161,165,169,172,176,180,184,188, _
    192,196,201,205,210,214,219,224,229,234,239,244,250,255
    just wondering how that all gets accounted for in EEprom, because I'm sure there's going to be some impact with the way I read that table type data back (eg is my user defined bye stored in EEPROM memory slot0, with the rest filling sequentially afterwards?) I was previously using a counter variable to look up/reference the the data stored in EEprom, but now I'm wondering if I need to offset it by 1? (due to the user stored byte in Eeprom too ....or can I store the one user defined byte at the end of the EEPRM...the last slot)


    can I look at EEprom via the Pickit2 (I had a dabble but it wasn't obvious to read!)

    Many thanks.

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


    Did you find this post helpful? Yes | No

    Default Re: Smooth LED fading via PWM

    Hi Hank,
    First off all, it seems as if your WRITE statement is "reversed", you should do WRITE Adress, Value but to me it seems you have it the other way around, ie. writing whatever is in default_config to adress 42 (101010) when I think you actually want the value 42 written to adress 0, or 1 perhaps.

    Second, I think (pretty sure) you should be able to read the EEPROM with the PICKit2, I only have a PK3 but if you can't figure it out I'll have a go later. With that said you could dump the EEPROM content over a serial line (if you have one) with something like:
    Code:
    Count VAR BYTE
    Result VAR BYTE
    
    For Count = 0 to 255
      Read Count, Result
      HSEROUT ["EEPROM Location: ", DEC3 Count, ": ", DEC RESULT,13]
    NEXT
    Third, if the first location in EEPROM (location 0) is reserved for that "userbyte" of data then you should start your DATA table with something like DATA @1, 1, 1, 1... Which will put the first entry at location 1 instead of location 0.

    Finally, remeber that DATA isn't something that executes when the program runs, it only tells the compiler/assembler to put that data in the ".hex image" so that the programmer (your PICKit2) can program the values into EEPROM together with the actual program. WRITE, on the other hand is a runtime command and does write to the EEPROM when the program executes.

    Hope that helps.
    /Henrik.

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