Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PWM for LED module to choose duty cycle

Status
Not open for further replies.

manush30

Member level 1
Joined
Jul 14, 2016
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
340
Hi friends,

I driving LED with this TI's driver
https://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...:cry::idea::???: Capture.JPG
 

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.
 

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;



LED PWM.JPG
 
Last edited by a moderator:

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
 

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.
 

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.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top