From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FPGA PWM Motor control

Hi, This is my first post on these forums i hope this is the right place.

 

Over summer i'm developing a self balancing ballbot for use as a demonstrator at my university. So far i have completed the vehicle dynamics, simulink/matlab model and build a labview model which works. Now i have to implement it in reality on the robot which has already been built.

 

The robot uses a 5 state IMU to give feedback to a controlrio unit consisting of an anolgue i/o module and 2 motor driver modules to control an x and y motor.

 

I have looked at countless articles and forums etc for information on the fpga and i think i understand everythign about it now but i still have some issues. Mainly, can i create a labview Vi that will generate a PWM signal to the motors in realtime?

 

Someone suggested opening a reference to a FPGA bit file which turns the motor on and off and then creating a PWM signal in the realtime Vi and then writing it back to the FPGA? In the realtime vi there is a control loop using a klamn filter and LQR to give the desired output voltages to the motors based on the state of the robot (that is ball angle, body angle, ball speed, body speed and current).

I take it i can read the analogue acceleration and rol signals directly into the real time vi then simply apply the control theory to it, and then with the final voltage output simply produce a PWM to send to the FPGA?

Does it have to be converted to the FPGA as the frequency of real time will be too low to allow the quick switching of motor voltages? Could i do it all in the FPGA module?

 

Sorry for all the questions, i will be very grateful for any help on the subject.

 

 

Sam Jackson 

 

0 Kudos
Message 1 of 8
(4,649 Views)

As you have already figured out, there are a lot of ways to create a PWM.  However, the easiest is probably to create the PWM signal in the FPGA and control it with your real-time loop.  I think you already figured that out.  Creating a PWM in the FPGA is not particularly difficult, nor do you need to do it yourself.  You have a couple of options:

 

  1. Use the FPGA Wizard to create the PWM and interfaces for you.  You can launch the FPGA Wizard from either the tools menu or from a right click on the project.
  2. Use one of the plethora of examples of PWM available.  For example, here, here, and here.

Good luck.  Let us know if you need more help.

0 Kudos
Message 2 of 8
(4,641 Views)

Ahhh ok, so would i then have to read the FPGA with the real time vi and apply the control theory to it and then send it back to the FPGA? Is it possible tp create state-space within the FPGA? As the kalman filter is effectively a set of A,B,C &D matrices and the lqr is just a set of 5 gains that are matrix multiplied by the state to give a voltage. It seems on the FPGA module vi there aren't nearly as many functions to use?

 

Thanks for your help already!

 

sam

0 Kudos
Message 3 of 8
(4,638 Views)

You can do all your calculations in the FPGA, but the FPGA module does not currently have a native floating point library.  You will need to either implement your own floating point or use integers or fixed point.  Implementing your own floating point takes a lot of FPGA fabric, but can be high performance.  You are usually much better off using the native fixed point or integers, although it may mean algorithm changes.  Unfortunately, I am not the person to help you here.  I have never tried to do this.  However, lots of people have.  Search these forums and ni.com for examples and you can probably find something that is close to what you want to do.

 

You are correct in that a lot of the functionality of LabVIEW is not available on the FPGA.  But that should not stop you from writing your own.  The difficulty in porting the full LabVIEW functionality to the FPGA is that it would need to work in all circumstances, leading to a lot of inefficiency in many circumstances.  You, as a developer, do not have this issue.  You can write something that works efficiently for your application, but lacks functionality that would be needed in the general case.

 

Good luck and have fun!

0 Kudos
Message 4 of 8
(4,607 Views)

Ok it looks like i will create the pwm in fpga. I will collect the imu data in the real-time controller and then apply the contreol theory to it to produce a correct voltage and then write this to the fpga to generate a pwm signal to actually drive the motor. 

 

One thing i dont understand though is that at the moment i have the compactRIO etherneted up to my laptop. When i want to run the ballbot without being connected to my laptop how do i do it? The real-time controller has a front panel user interface that i can change when its on my pc however i want to run the robot without being connected up and theoretically it should work as the control is automatic. What tool do you have to use to run the project/vi's on the compact rio without it being hooked to a pc?

 

Thanks for all your help, it's been very useful! 

 

sam

0 Kudos
Message 5 of 8
(4,592 Views)

It has been awhile since I worked with FPGAs, and I have never done this, but I asked someone who does know.  You can set an FPGA VI to run when downloaded by checking the appropriate option in your buildspec in the project.  You can set an FPGA VI to run when the FPGA device is turned on with the RIO utility found in the NI-RIO directory of your start menu.

0 Kudos
Message 6 of 8
(4,580 Views)

Thankyou, i will build an RT application when i have finished the labview programming and then it should hopefully run straight away on startup.

 

I've been looking at the PWM signal again today and have came upon a snap. The input to the signal is a duty cycle percentage. So if i want the max voltage then the duty cycle is 100%. The output voltage from my control simulation is simply an analogue voltage that needs to be applied to the motor so cannot be directly passed to the pwm code. However am i right in thinking that if my max voltage is 24v, if i divide the voltage out of my control loop by 24 and multiply it by 100 this will give me the desired duty cylce percent? 

 

Regards,

 

sam

0 Kudos
Message 7 of 8
(4,570 Views)

That is correct!  Divide your input 0-24V signal by 24 and multiply by 100 to get the duty cycle.

0 Kudos
Message 8 of 8
(4,555 Views)