10-05-2010 02:28 AM - edited 10-05-2010 02:29 AM
Hi
I want to convert a numerical number to a duty cycle value in FPGA module so I could use it to generate a PWM signal for the numerical value.
I tried dividing it but it shows an error in FPGA as it would produce a float value. I tried even the example of scaled division but the quotient is rounded of to 0 (I wanted to convert an output by multiplying 10/36).
In my project the 100% duty cycle is 360 degrees and 0% is 0 degrees of the motor shaft rotation.
Please help me I need to use it for my project.
Thank you
Dinesh
10-05-2010 10:55 AM
Can you show your code? If you just need to take a number and multiply by 10, then divide by 36, why not simply multiply by 10/36 = .27777?
10-05-2010 12:46 PM
Why don't you multiply your numerator by 100 before doing the division using Quotient & Remainder.
10-05-2010 01:22 PM
I am not exactly sure how your duty cycle is setup, but here is a way we have used a number to create a PWM in our FPGA.
If you have 360 deg. then I would guess you want to create a PWM duty cycle that is some fraction of 360, say "number"/360. You could use a for loop where 360 is wired to the "N" and then your "number" can be compared to the current loop count. That comparison would be true/false which could triger a DIO to be high or low. Therefor, if (loop count) < "number" then DIO is HIGH, if (loop count) >= "number then DIO is LOW. This would send out a PWM that has a duty cycle of "number"/360, (multiply by 100 to get in %)
I hope this helps.
--Alex--
10-05-2010 02:51 PM
Hi Alex
Thank you very much.
Dinesh