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

    Join Date
    Jul 2016
    Posts
    26
    Helped
    0 / 0
    Points
    379
    Level
    4

    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: 25,592, Level: 38
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    7,697
    Helped
    956 / 956
    Points
    25,592
    Level
    38
    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 )



    •   Alt28th May 2017, 14:57

      advertising

        
       

  3. #3
    Super Moderator
    Points: 69,588, Level: 64
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    11,375
    Helped
    3763 / 3763
    Points
    69,588
    Level
    64

    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 3
    Points: 379, Level: 4

    Join Date
    Jul 2016
    Posts
    26
    Helped
    0 / 0
    Points
    379
    Level
    4

    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!!

    [syntax=vhdl]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;[/syntax]

    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: 239,598, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    41,511
    Helped
    12665 / 12665
    Points
    239,598
    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



  6. #6
    Junior Member level 3
    Points: 379, Level: 4

    Join Date
    Jul 2016
    Posts
    26
    Helped
    0 / 0
    Points
    379
    Level
    4

    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.



    •   Alt14th June 2017, 15:58

      advertising

        
       

  7. #7
    Super Moderator
    Points: 239,598, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    41,511
    Helped
    12665 / 12665
    Points
    239,598
    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.



--[[ ]]--