- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
this takes only one duty cycle the first one it does not switch to other as clock proceed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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...)- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Make sure all your variables/registers are initialized at the start of simulation.
Cheers, Alex- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks for the help sir, it works now i will be back soon with a new problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- 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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page