Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17253 ディスカッション

sine wave using Different duty cycles of PWM

Altera_Forum
名誉コントリビューター II
2,143件の閲覧回数

Hi i am having problem in generating different duty cycles of PWM. can somebody check my code and tell what is wrong. well code is generating a duty cycle but it does not change it automatically as the code says. plz help

0 件の賞賛
11 返答(返信)
Altera_Forum
名誉コントリビューター II
1,387件の閲覧回数

Your case(counter[15:0]) statement only covers 256 out of 65536 possibilities. I'm sure that's not what you intended. 

 

Have you simulated this? I suspect not. I can see immediately what's wrong having done so and that your 'duty_cycle' value never 'appears' to change. It does change, but it always ends up at the same value for 65280/65536 of the time. (65280 = 65536-256) 

 

Cheers, 

Alex
Altera_Forum
名誉コントリビューター II
1,387件の閲覧回数

yes i tested this one using altera DE2 board. and even i changed the size of counter to [7:0] from [15:0] but it still gives me only one duty cycle and this time it is little distorted. i use GPIO pins one positive and one negative to directly connected to scope. is there any problem with my code?

Altera_Forum
名誉コントリビューター II
1,387件の閲覧回数

this takes only one duty cycle the first one it does not switch to other as clock proceed.

Altera_Forum
名誉コントリビューター II
1,387件の閲覧回数

So you've 'tested' it but you haven't simulated it - is that right? 

 

Try simulating your code - like I did. The problem will be much clearer when you're looking at the behaviour of your code and not just the resulting output signal. 

 

Once again simulate your code! Make sure you're happy with the simulation before you even try it on hardware. 

 

Cheers, 

Alex 

 

hint: perhaps try counter[15:8] - (not the whole solution but a start...)
Altera_Forum
名誉コントリビューター II
1,387件の閲覧回数

having problem in simulation output shows red line. i think i have problem calling the components. which components should it include the test bench module pwm or wave. 

help!!! 

there is really no time
Altera_Forum
名誉コントリビューター II
1,387件の閲覧回数

Make sure all your variables/registers are initialized at the start of simulation. 

 

Cheers, 

Alex
Altera_Forum
名誉コントリビューター II
1,387件の閲覧回数

thanks it's works, but i haven't understand why it is not picking up with counter[0:7], i think there is a relationship between the counter and the period. as i go from [15:8] to [14:7] and so on the period is increasing. is it so. does the range depends on MSB(most significant bit) to LSB(least significant bit). is there any relationship between these??? 

yes thanks for the guide
Altera_Forum
名誉コントリビューター II
1,387件の閲覧回数

Yes, there must be a "relationship between these" - and the frequency is clearly dependent on which bits you select, as you've seen. I suggest you keep playing around with it - I'm sure you can work out the relationship for yourself. 

 

Cheers, 

Alex
Altera_Forum
名誉コントリビューター II
1,387件の閲覧回数

thanks for the help sir, it works now i will be back soon with a new problem

Altera_Forum
名誉コントリビューター II
1,387件の閲覧回数

 

--- Quote Start ---  

yes i tested this one using altera DE2 board. and even i changed the size of counter to [7:0] from [15:0] but it still gives me only one duty cycle and this time it is little distorted. i use GPIO pins one positive and one negative to directly connected to scope. is there any problem with my code? 

--- Quote End ---  

 

 

how were you able to connect the GPIO pins to a scope? and how to assign pins from the code to the GPIO pins? can you please share a picture of the hardware setup?
Altera_Forum
名誉コントリビューター II
1,387件の閲覧回数

I use quartus and you have to set it in pin assignments not in the code. you can download the file from internet be sure it is in csv format.

返信