Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
16613 Discussions

motor speed variable using FPGA

Altera_Forum
Honored Contributor II
1,544 Views

Hi. How to design variable speed motor using FPGA. I want to design line follower robot in different surface application for example, on roughness(slow) or smooth floor(fast).

0 Kudos
12 Replies
Altera_Forum
Honored Contributor II
784 Views

What kind of motor? (stepper, DC, ....) 

What kind of control for motor driver? (pulse, pwm, analog, ... )
0 Kudos
Altera_Forum
Honored Contributor II
784 Views

 

--- Quote Start ---  

What kind of motor? (stepper, DC, ....) 

What kind of control for motor driver? (pulse, pwm, analog, ... ) 

--- Quote End ---  

 

 

Hi Cris72, I plan to use DC motor and pwm as a driver. Can u give an idea?
0 Kudos
Altera_Forum
Honored Contributor II
784 Views

If you are only supposed to generate a pwm signal for open loop drive control, it's an easy task with fpga.  

You basically need a counter+comparator and possibly some extra logic for setting the pwm level. 

Whiile if you want a complete closed loop controller, your system must provide some sort of feedback signals 

in order to adjust the pwm level in real-time.
0 Kudos
Altera_Forum
Honored Contributor II
784 Views

 

--- Quote Start ---  

If you are only supposed to generate a pwm signal for open loop drive control, it's an easy task with fpga.  

You basically need a counter+comparator and possibly some extra logic for setting the pwm level. 

Whiile if you want a complete closed loop controller, your system must provide some sort of feedback signals 

in order to adjust the pwm level in real-time. 

--- Quote End ---  

 

I have some different opinion about this. 

 

If the stepper motor controler is supposed with PWM,the stepper motor's speed is relation with the pwm's frequency.That is to say,if I want to get the  

 

variable stepper motor speed,I should get variable frequency of pwm. 

 

If the input frequency of FPGA is 50MHz,using the counter++,may get those frequency,like 25MHz,12.5MHz,6.25Mhz,....and so on. 

 

But,there is some frequency can no be reached,like 20MHz,or 999999Hz. 

 

I do not kown how to deel with this. 

 

Do you have any opinion about those?
0 Kudos
Altera_Forum
Honored Contributor II
784 Views

 

--- Quote Start ---  

I have some different opinion about this. 

 

If the stepper motor controler is supposed with PWM,the stepper motor's speed is relation with the pwm's frequency.That is to say,if I want to get the  

 

variable stepper motor speed,I should get variable frequency of pwm. 

 

If the input frequency of FPGA is 50MHz,using the counter++,may get those frequency,like 25MHz,12.5MHz,6.25Mhz,....and so on. 

 

But,there is some frequency can no be reached,like 20MHz,or 999999Hz. 

 

I do not kown how to deel with this. 

 

Do you have any opinion about those? 

--- Quote End ---  

 

 

generate clock enable using modulo accumulator. add your word non-stop. then at overflow generate a pulse The equation for frequency becomes: 

f = clk speed * accum word value/accum resolution 

 

e.g. if accum is 32 bits and word is 2^30 and clock is 50MHz then: 

f = 50 * 2^30/2^32 = 50/4 Mhz
0 Kudos
Altera_Forum
Honored Contributor II
784 Views

 

--- Quote Start ---  

generate clock enable using modulo accumulator. add your word non-stop. then at overflow generate a pulse The equation for frequency becomes: 

f = clk speed * accum word value/accum resolution 

 

e.g. if accum is 32 bits and word is 2^30 and clock is 50MHz then: 

f = 50 * 2^30/2^32 = 50/4 Mhz 

--- Quote End ---  

 

 

I konw what you mean. 

e.g. if accum is 32 bits and word is 2^30 and clock is 50MHz then: 

f = 50 * 2^30/2^32 = 50/4 Mhz.I can get 12.5Mhz frequency pwm,this is surely. 

 

But if I want to get stable frequency of 12.4Mhz,or 12.6MHz,this way can not work.
0 Kudos
Altera_Forum
Honored Contributor II
784 Views

There's another way to generate a frequency with a (almost) continous range. 

You must use an adder with an overflow detector.  

The registered adder output is fed back to one of the inputs, while the second input is a value proportional to the desired frequency. 

 

For example, let's suppose a 32bit wide adder, with inputs A and B and output (registered) Q. Let P be the overflow output. 

You connect Q back to A. At each clock pulse you have Q = Q + B, then the overflow pulse is generated every 2^32 / B clocks. 

In other words, the frequency of P signal is Fclock x B / 2^32 which can be modulated with a good resolution, provided you don't get too close to Fclock. 

 

This is easy, if you only need a frequency synthesizer.  

Generating the actual pwm could be more tricky, especially if you need an exact duty cycle rather than fixed width pulses,
0 Kudos
Altera_Forum
Honored Contributor II
784 Views

Oops, Sorry. I didn't see you had already got an answer

0 Kudos
Altera_Forum
Honored Contributor II
784 Views

 

--- Quote Start ---  

I konw what you mean. 

e.g. if accum is 32 bits and word is 2^30 and clock is 50MHz then: 

f = 50 * 2^30/2^32 = 50/4 Mhz.I can get 12.5Mhz frequency pwm,this is surely. 

 

But if I want to get stable frequency of 12.4Mhz,or 12.6MHz,this way can not work. 

--- Quote End ---  

 

 

you will get any frequency.  

In many cases the exact pulse frequency wouldn't be as a clean clock but over a window of time it will be correct and for stepper motor it should be more than enough. 

 

example 50MHz * 2333456/2^32 = ?  

 

Anyway from 50MHz you cannot get exact frequencies except for cases like half/quarter etc unless you use variable analogue PLL
0 Kudos
Altera_Forum
Honored Contributor II
784 Views

 

--- Quote Start ---  

There's another way to generate a frequency with a (almost) continous range. 

You must use an adder with an overflow detector.  

The registered adder output is fed back to one of the inputs, while the second input is a value proportional to the desired frequency. 

 

For example, let's suppose a 32bit wide adder, with inputs A and B and output (registered) Q. Let P be the overflow output. 

You connect Q back to A. At each clock pulse you have Q = Q + B, then the overflow pulse is generated every 2^32 / B clocks. 

In other words, the frequency of P signal is Fclock x B / 2^32 which can be modulated with a good resolution, provided you don't get too close to Fclock. 

 

This is easy, if you only need a frequency synthesizer.  

Generating the actual pwm could be more tricky, especially if you need an exact duty cycle rather than fixed width pulses, 

--- Quote End ---  

 

 

Yes,maybe my expression is wrong. 

In fact,I need generate fixed width pulses. 

Your reply seems feasible.I will try it.
0 Kudos
Altera_Forum
Honored Contributor II
784 Views

 

--- Quote Start ---  

you will get any frequency.  

In many cases the exact pulse frequency wouldn't be as a clean clock but over a window of time it will be correct and for stepper motor it should be more than enough. 

 

example 50MHz * 2333456/2^32 = ?  

 

Anyway from 50MHz you cannot get exact frequencies except for cases like half/quarter etc unless you use variable analogue PLL 

--- Quote End ---  

 

 

you are right. 

"from 50MHz you cannot get exact frequencies except for cases like half/quarter etc." 

I have try s lot,but fail.I cannot get exact frequencies except for cases like half/quarter. 

I will try your suggestion,hope this is average frequency really enough for stepper motor.
0 Kudos
Altera_Forum
Honored Contributor II
784 Views

 

--- Quote Start ---  

you are right. 

"from 50MHz you cannot get exact frequencies except for cases like half/quarter etc." 

I have try s lot,but fail.I cannot get exact frequencies except for cases like half/quarter. 

I will try your suggestion,hope this is average frequency really enough for stepper motor. 

--- Quote End ---  

 

 

No doubt you failed, despite how smart you could be. As Kaz pointed out, it is impossible to generate other than half, third, quarter... frequency, unless you accept an 'average' frequency, like in the adder solution we both presented. 

That's because frequency is the inverse of period and the pwm period must necessarily be a multiple of your system clock. 

 

In any case, for motor control a frequency in the 20-100kHz range is what is usually needed, so I don't see any problem in the frequency discretization you have in the MHz range
0 Kudos
Reply