+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Junior Member level 1
    Points: 251, Level: 3

    Join Date
    Jul 2016
    Posts
    17
    Helped
    0 / 0
    Points
    251
    Level
    3

    PWM for LED module to choose duty cycle

    Hi friends,

    I driving LED with this TI's driver
    http://www.ti.com/lit/ds/symlink/tps92512.pdf

    I'm trying to write a code with PWM dimming control.
    According to the datasheet the dimming range is 100Hz to 1kHz(Pg. 12)

    In pg. 17 they give an example to a design with oscilloscope images(pg. 20) (PWM signals)
    I try to write a code with the ability to choose duty cycle to work with.
    (My board connect to outside CPU to select duty cycle thru I2C)
    attached a little clock diagram.

    I really need help here guys...Click image for larger version. 

Name:	Capture.JPG 
Views:	7 
Size:	39.1 KB 
ID:	139021

    •   Alt28th May 2017, 14:22

      advertising

        
       

  2. #2
    Super Moderator
    Points: 22,934, Level: 36
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Portugal
    Posts
    6,969
    Helped
    853 / 853
    Points
    22,934
    Level
    36
    Blog Entries
    5

    Re: PWM for LED module to choose duty cycle

    I really need help here
    I can't see your code.
    I can't see your math results.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  3. #3
    Super Moderator
    Points: 64,046, Level: 61
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    10,609
    Helped
    3441 / 3441
    Points
    64,046
    Level
    61

    Re: PWM for LED module to choose duty cycle

    Nobody can help you if we don't know what happens in the CPLD.

    You are putting I2C data into it and presumably it produces PWM output to the TPS92512 but we have no idea how you want it to operate internally or if it does other jobs as well. Are you asking for the hardware design of an I2C interface and pulse width modulator and if so, which CPLD and which language?

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   Alt28th May 2017, 22:56

      advertising

        
       

  4. #4
    Junior Member level 1
    Points: 251, Level: 3

    Join Date
    Jul 2016
    Posts
    17
    Helped
    0 / 0
    Points
    251
    Level
    3

    Re: PWM for LED module to choose duty cycle

    Hi guys,

    I'm sorry about the ignition and my lacking explanation/information...
    Ignore the previous messaging.
    Again. excuse me about it.

    i try to drive PWM dimming for the LED driver above.
    I attached only the PWM code and not entire the code.

    I wrote the code but after i ran test banch, i saw my PWM frequency is 40 Hz instead 1kHz and my duty cycle (PWM_SW) work fine.

    I need help to find my mistake in the code. why i see 40Hz and not 1kHz..
    I decied to work with state machine.

    Also, i add image for my simulation
    1kHz clock generate at my "top" design.

    Thx u a lot guys!!

    Code VHDL - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    
    LIBRARY IEEE;
    USE IEEE.STD_LOGIC_1164.ALL;
    USE IEEE.STD_LOGIC_ARITH.ALL;
    USE IEEE.STD_LOGIC_UNSIGNED.ALL;
    USE IEEE.NUMERIC_STD.ALL;
     
     
    ENTITY UV_PWM IS
        PORT( 
            MCLK        : IN    STD_LOGIC;
            RESET       : IN    STD_LOGIC;
            UV_ENABLE   : IN    STD_LOGIC_VECTOR(2 DOWNTO 1); ---- ENABLING the 48V ON BOARD
            PWM_SW      : IN    STD_LOGIC_VECTOR(6 DOWNTO 0); ---- SOFTWARE IDICATES WHICH PWM WILL OPERATE
            CLK1KHZ     : IN    STD_LOGIC;-------------------- 1KHz WILL CONNECTED AT MY TOP 
            UV_DIAG     : IN    STD_LOGIC_VECTOR(3 DOWNTO 1);   ---- IGNORE IT, SOME INDICATION ON MY CIRCUIT
            PWM_ON      : OUT   STD_LOGIC );    ------- PWM SIGNAL OUTPUT TO THE DRIVER
    END UV_PWM;
     
    ARCHITECTURE ARC_UV_PWM OF UV_PWM IS
     
    SIGNAL  PWM_CNT         : STD_LOGIC_VECTOR(6 DOWNTO 0);----- 100%---64h----1100100b
    SIGNAL  CLK1KHZ_O       : STD_LOGIC;
    SIGNAL  PWM_SW_I        : STD_LOGIC_VECTOR(6 DOWNTO 0);
    TYPE    STATE IS (STATE1, STATE2, STATE3, STATE4);
    SIGNAL  NS            : STATE;
     
     
    BEGIN
    PROCESS(MCLK,RESET)
    BEGIN
        IF RESET='0' THEN       
            PWM_CNT <=  (OTHERS=> '0') ;
            PWM_SW_I <= (OTHERS=> '0') ;
            PWM_ON  <= '0' ;
        ELSIF (MCLK'EVENT AND MCLK= '1') THEN
            CLK1KHZ_O  <= CLK1KHZ;
            PWM_SW_I <= PWM_SW;
            -- IF UV_ENABLE = "11" THEN 
            IF UV_ENABLE = "11" THEN    
                IF UV_DIAG = "000" THEN
                    IF ((CLK1KHZ = '1') AND (CLK1KHZ_O = '0')) THEN
                
                        CASE NS IS  
            
                            WHEN STATE1 =>
                            
                                IF PWM_SW_I = "0000000" THEN
                                    PWM_ON <= '0';
                                    NS <= STATE1;
                                ELSE
                                    NS <= STATE2;
                                END IF;
                                
                            WHEN    STATE2 =>
                                IF PWM_CNT < PWM_SW_I THEN
                                    PWM_ON <= '1';
                                    PWM_CNT <= PWM_CNT + 5 ;
                                    NS <= STATE2;
                                ELSE
                                    NS <= STATE3;
                                END IF;
                    
                            WHEN    STATE3 =>   
                                IF PWM_CNT < "1100100" THEN 
                                    PWM_ON <= '0';
                                    PWM_CNT <= PWM_CNT + 5;
                                    NS <= STATE3;
                                ELSE
                                    NS <= STATE4;
                                END IF;
                                    
                            WHEN    STATE4 => 
                                IF PWM_CNT = "1100100" THEN
                                    PWM_CNT <= (OTHERS => '0');
                                    NS <= STATE1;
                                END IF;
                        END CASE;
                    END IF;
                END IF;
            END IF;     
        END IF;
    END PROCESS;
    END ARC_UV_PWM;

    Click image for larger version. 

Name:	LED PWM.JPG 
Views:	2 
Size:	191.9 KB 
ID:	139401
    Last edited by FvM; 14th June 2017 at 14:07. Reason: Added syntax tags



  5. #5
    Super Moderator
    Points: 230,196, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    39,747
    Helped
    12128 / 12128
    Points
    230,196
    Level
    100

    Re: PWM for LED module to choose duty cycle

    How can you expect 1 kHz PWM frequency if you are advancing the PWM counter at only 1 kHz? You get PWM frequency = 1 kHz/number of pwm counter states



    •   Alt14th June 2017, 14:16

      advertising

        
       

  6. #6
    Junior Member level 1
    Points: 251, Level: 3

    Join Date
    Jul 2016
    Posts
    17
    Helped
    0 / 0
    Points
    251
    Level
    3

    Re: PWM for LED module to choose duty cycle

    Sorry.
    I did not understand u.

    You meaning i have 10Hz pwm frequency?
    the cntr i try to do is for 0-100% duty cycle from 1kHz..
    PWM_ON is the output after calculating that.



  7. #7
    Super Moderator
    Points: 230,196, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    39,747
    Helped
    12128 / 12128
    Points
    230,196
    Level
    100

    Re: PWM for LED module to choose duty cycle

    You have 20 + something pwm counter states by increasing the pwm counter by 5.

    I really don't know what I should explain more, the behavior is completely obvious when you look at the simulation. Just don't understand why you expect 1 kHz pwm frequency.



--[[ ]]--