LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert a number to duty cycle (FPGA)

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

0 Kudos
Message 1 of 5
(2,675 Views)

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?

0 Kudos
Message 2 of 5
(2,656 Views)

Why don't you multiply your numerator by 100 before doing the division using Quotient & Remainder.

Randall Pursley
0 Kudos
Message 3 of 5
(2,645 Views)

 

  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--

Message 4 of 5
(2,637 Views)

Hi Alex

 

Thank you very much.

 

Dinesh

0 Kudos
Message 5 of 5
(2,622 Views)