11 Mar 2014

PWM using Spartan 3E FPGA & Rotary Encoder

Hello Friends, Meanwhile I was working on Digilent’s Spartan 3E Starter Board having Spartan 3E XC3S500 FPGA present on it.

I basically work on Embedded Application using FPGA, but usually I find most of my friends who work in the Power Electronics Domain use FPGAs for pulse generation for driving MOSFETs & IGBTs. So just gave a thought about writing a simple VHDL program to generate PWM.


I wrote a rough VHDL program to toggle the pin to HIGH and LOW depending on the pulse width, but I wanted to control the pulse width as per my requirements using hardware. To my rescue, I found that the FPGA development board which I was using “Spartan 3E starter Board”, contains a rotary encoder.

Luckily I got a reference rotary encoder VHDL code from some open source website and modified it for my application. Finally I combined my PWM generation VHDL code and Rotary Encoder code and got this working.

Using this experimental project, I am able to generate PWM pulses and depending on the rotary encoder’s direction of rotation, I am able to increase or decrease the pulse width.

You can see the demo video for your reference.



I used Xilinx 12.4 with Web Pack License. You can find completed VHDL source codes here:


Contents:

  1. top.vhd
  2. pwm.vhd
  3. rotary_encoder.vhd
  4. rotaryencoder.ucf (You should change this file as per your Board’s Configuration)


I hope you will find this useful!

Clarifications & Suggestions for improvement are always welcome. Thanks

Related Post :


6 comments:

  1. sir, pls can u tell me the operation of 9 level cascaded multilevel inverter simulation

    ReplyDelete
    Replies
    1. its self explanatory...whats ur doubt?

      Delete
  2. Hello Amit,
    your program is nice, but i have one problem, whenever i change th PW th voltage range changes too. For example: my voltage range starts at +-0.3V, but if i increase the PW the voltage range changes to -0.2V +0.4V.can you tell me where you defined the voltage range or maybe you even have a solution for my problem
    Kind regards Georg

    ReplyDelete
  3. if you would use a "PDM" which I believe is the digital form of pwm, how would the code look like?

    ReplyDelete
  4. Sir, I am using VHDL for the first time, so was unable to understand a few things in the program. Can u please send me some explanation of the program

    ReplyDelete

If you liked this blog then Join me at:
Facebook
Twitter
RSS