Help me generate PWM in Verilog HDL

Status
Not open for further replies.

Hafeez Anwar

Newbie level 5
Joined
May 8, 2007
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,344
Hi,
I have a little problem in generating the PWM in verilog. Will any body help me or even give me a link on this topic
 

pwm verilog

PWM is the train of pulses with defined duty cycle.
Normally PWM having 10-90% duty cycle.
You can defined output as per required duty cycle and frequency to output with reference to input clock.

Regards,
Sachin
 

pwm verilog code

thankx a lot. but i wanna know that how can i use this wave to transmit my data which is used to be in binary format? and also how can i implement this idea in verilog? just help me in making the algo.
 

verilog pwm testbench

Here is a prog. which will generate the evenly distributed PWM signal. Use the following

module header
module pwm_even (duty,clk,oe,pwm_sig);
input [0:7] duty;
input clk,oe;
output pwm_sig;
tri pwm_sig;

where duty is the duty cycle, it is set using the 8 dip switches on board and can be varied from 0
to 255, for example, duty would equal 10, say clk is the on board 25MHz.
clock, oe is the tri-state output enable for pwm_sig (use active high enable), connect this to one of
the two pushbutton switches, and pwm_sig is the pulse width modulated signal.

HINT – This can be implemented using one counter, which is incremented in steps of duty at each clk (Trying to do a division, such as 256/10, is not the way to approach this problem).

Might be this will help you.

Sachin
 
fpga verilog pwm

Hi,
I have a project on pwm in verilog programming language. "pwm and one bit dac". The aim of this project is to convert the dıgıtal data to analog. Ihave found codes.
I am usıng xilinx spartan 3E kit

module PWM(clk, PWM_in, PWM_out);
input clk;
input [7:0] PWM_in;
output PWM_out;

reg [8:0] PWM_accumulator;
always @(posedge clk) PWM_accumulator <= PWM_accumulator[7:0] + PWM_in;

assign PWM_out = PWM_accumulator[8];
endmodule



but,in the codes a pwm accumulator is mentıoned and there ıs a command it is"PWM_accumulator <= PWM_accumulator[7:0] + PWM_in;" I don't understand why this command is written in the program and what is the functıon of the pwm accumulator?
my second questıon is how can I give an ınput to pwm ? can I use switches by making them on and off and can I create a dıgıtal data?
ıf there is anyone to help me,I will be glad.
thanks
regards
 

sigma delta pwm verilog

is there anyone help me?
 

verilog code for pwm

Hi ,

You can use an excel to simulate this. Simply this is doing a modulu of the input data (which is the PWM ratio) on an internal counter. The overflow (over 128) is the value of the PWM.

PWM CNTR INPUT VAL
0 0 70
0 70 70
1 140 70
1 210 70
0 24 70
0 94 70
1 164 70
1 234 70
0 48 70
0 118 70

.....

Arik P.
 

pwm in verilog

I think, the correct result is different:

out accu[7:0] in
0 0 70
0 70 70
0 140 70
0 210 70
1 24 70
0 94 70
0 164 70
0 234 70
1 48 70
0 118 70

The average output duty cyle is 70/256 = 0.27. This is basically a first-order sigma-delta modulator. Although the modulator is representing an analog value by a a duty cycle, I wouldn't designate it a PWM.
 

pwm using verilog

I can not understand exactly what you mean,can you explaın more clear?
thanks
 

pwm en verilog

25 Dec 2008 15:52 Re: PWM in Verilog HDL


--------------------------------------------------------------------------------

I think, the correct result is different:

out accu[7:0] in // I don't understand the numbers below what are they for?
0 0 70
0 70 70
0 140 70
0 210 70
1 24 70
0 94 70
0 164 70
0 234 70
1 48 70
0 118 70

The average output duty cyle is 70/256 = 0.27. This is basically a first-order sigma-delta modulator. Although the modulator is representing an analog value by a a duty cycle, I wouldn't designate it a PWM.


Also,my project must be done by usıng pwm,so the sıgma-delta modulator is not useful for me I think,but I am not sure because I am not exper at verılog.yhis is my first project.
 

hdl pwm

Yes, I see. The basic difference is, that a sigma-delta modulator is intended to
shift all switching noise to high frequent spectral range, changing the switch output as fast as possible, while a PWM modulator produces a square wave with defined frequency. In my example, the PWM period is 256 clock periods, simply copying the signal resolution from the previous SD example. The PWM_out signal should be registered to avoid glitches.
Code:
module PWM(clk, PWM_in, PWM_out); 
input clk; 
input [7:0] PWM_in; 
output PWM_out;
reg PWM_out; 

reg [7:0] PWM_ramp; 
always @(posedge clk) 
begin
  PWM_ramp <= PWM_ramp + 1'b1; 
  PWM_out <= (PWM_in>PWM_ramp);
end
endmodule
 

pwm waveform in vhdl code

I have found new codes. I have sımulated it by moudle sımulator. and I get some results but I can nor understand whether they are rıght or not. can you help me to understand this?


module PWMMain(DC,CLK,Q);

input [7:0] DC;
input CLK;
output Q;
wire CLKO;
// synthesis attribute LOC clk "P9"
// synthesis attribute LOC Q "P1"
// synthesis attribute LOC DC "P11","P10","P7","P6","P5","P4","P3","P2"

//clkdiv div(CLK,CLKO);
PWM sev(DC,CLK,Q);

endmodule

module clkdiv(CLKIN,CLKOUT);
input CLKIN;
output CLKOUT;

wire iclk;
parameter BITS=13;
reg [BITS-1:0] COUNT;
initial COUNT=0;
assign CLKOUT=COUNT[BITS-1];
BUFG clkbuf(iclk,CLKIN);
always @(posedge iclk)
begin

COUNT = COUNT + 1;
end
endmodule



module PWM(DC,CLK,Q);
input [7:0] DC; // duty cycle input
input CLK;

output Q;
reg [8:0] acc; // accumulator has one more bit than the duty cycle
assign Q=acc[8]; // output is the 8th bit

initial acc=0; // for simulation only
always @(posedge CLK)
begin

acc=acc[7:0]+DC; // only add with 8 bits.
end
endmodule

testbench is below


module denemee;


reg [7:0] DC;
reg CLK;

// Outputs
wire Q;

// Instantiate the Unit Under Test (UUT)
PWMMain uut (
.DC(DC),
.CLK(CLK),
.Q(Q)
);


always
begin
CLK = 1;
#0.1;
CLK = 0;
#0.1;
end




the ouıtput of thıs stımulus,does it give the right output?
please help me...
thanks
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…