Online ServicesRemote LabRiders
Acrome’s Ball Balancing Table's already extensive software option now comes with the C option which enables it to be used with one of the most popular microcontrollers STM32!! Check out the below video to see how it works. Details on how to use this new option is explained in this document.
A feature requested from our users is using the STM32 microcontrollers and C programming language. The STM family of microcontrollers are one of the most popular microcontroller devices, and used by academia in laboratories, hobbyists and private companies as well.
In this blog document, we would like to give an example on how to use STM32 microcontroller with a classical control experiment such as Ball Balancing Experiment system using the PID control and make it possible to use the C language for PID controller design principles. If you are not familiar with the PID controller design principles, feel free to read our other blog document about PID available in https://acrome.net/post/control-systems-what-is-pid-control
Before diving into the details of the system, let's give some brief information about STM32 and IDE used to program it:
STM32 microcontrollers are integrated circuits that STMicroelectronics produces. They are widely utilized in a wide range of applications, including those in the industrial, medical, consumer electronics sectors, research and in academia as well. They have 32-bit Arm Cortex-M processors in their foundation, and they provide a selection of peripheral ports and memory configurations.
Because of its adaptability, affordable price, and strong support from STMicroelectronics, the STM32 microcontroller series are well known. With its wide variety of peripheral interfaces, including USB, Ethernet, and CAN, a ready-to-use IDE named CubeIDE and with cross-compilers for mostly used IDEs, they are very suitable for a wide range of applications. Engineers favor it because of its real-time capabilities, large memory options, and low power consumption.
The process of developing software for microcontrollers is done with integrated development environments (IDEs). A variety of IDEs, including the widespread CubeIDE created by STMicroelectronics, are supported by the STM32 microcontroller series, as well as other industry-recognized IDEs including Keil uVision, IAR Embedded Workbench, and Atollic TrueSTUDIO. Editors, compilers, debuggers, and system setup tools are all provided by these IDEs as part of their extensive toolkit for software development. Personal preference and the precise project needs are frequently determining factors in IDE selection.
STMicroelectronics' CubeIDE has a number of benefits over other IDEs when used with the STM32 microcontroller line. First off, it offers a user-friendly interface that streamlines the design process and enables engineers to effectively take advantage of the STM32's full capabilities. The CubeIDE also seamlessly combines with other STMicroelectronics development tools, such the STM32CubeMX, for an efficient development process. This accelerates the development process by removing the need to switch between various tools.
Since CubeIDE is created by STMelectronics, it fully supports all STM32 microcontrollers including STM32F3 family which is used in our system. 1st and 3rd party libraries are included in CubeIDE which can be used to program endless things.
The ball balancing table system is a classic example of a dynamic control system that requires precise and quick control inputs to balance a ball on a platform. The input to this system can be the position and orientation of the ball relative to the platform. This input is obtained through a touchscreen that is equipped across the system's table. The output of the system would be the control signals applied to the platform motors to keep the ball in balance.
The controllable parameters of the ball balancing table system are the motor speeds and the angle of tilt of the platform. By controlling these parameters, the platform can be adjusted to keep the ball in a stable position. The PID controller takes the difference between the desired position of the ball and its actual position as input and outputs the control signals for the motors.
C programming language is used, as it is the major programming language for programming the ARM and STM controllers.
Our sample code written in C language mainly consists of 3 parts: Main file that contains all necessary functions to run the system, PID controller file and communication file. The most important key features included in the code are:
The example code in the video consists of 3 files:
As the name suggests, the main file contains the functions and commands that make the system work.
This is where the PID controller’s Kp, Ki and Kd gains can be adjusted manually.
A PID controller is a type of feedback control system that uses a set of equations to calculate and manipulate the output of a system in order to control a process and maintain it at a desired setpoint. The controller uses the error between the setpoint and the current process value, as well as the historical values of the error, to calculate the necessary corrective action. This action is then applied to the system in the form of a control signal, which can be used to adjust the system's output and bring it closer to the desired setpoint.
For the communication between Acrome controller and STM32 controller; USART protocol is used.
USART, or Universal Synchronous/Asynchronous Receiver/Transmitter, is a type of serial communication protocol that allows devices to transmit and receive data over a single communication line.
In synchronous mode, the transmission of data is synchronized to a fixed clock signal, which allows for faster transmission speeds but requires that both devices operate at the same clock frequency.
In addition; CRC32 algorithm is used in the communication to prevent any error in the data to be transmitted.
Important details about some features:
Cyclic Redundancy Check 32, is a type of checksum algorithm that is used to detect errors in data transmission or storage. It is called a "cyclic redundancy check" because it uses a series of calculations based on the binary data being transmitted or stored, and the resulting checksum value is determined by a cyclic algorithm. The CRC32 algorithm produces a 32-bit checksum value, which can be used to detect errors in the transmitted or stored data. If the data being transmitted or stored is changed in any way, the resulting checksum value will be different, allowing the receiving device to detect the error and take appropriate action. The CRC32 algorithm is widely used in many different applications, including data transmission and storage, error correction, and data integrity verification.
Button debouncing is a technique used to prevent a single press of a button or switch from being registered multiple times by a computer or other electronic device. When a button is pressed, it can sometimes bounce, causing the electrical contacts inside the switch to make and break multiple times in rapid succession. This can cause the device to register multiple presses of the button, even though the user only intended to press it once. Button debouncing involves adding a small delay to the processing of the button press, allowing the electrical contacts to settle and ensuring that only a single press is
registered. This can improve the reliability and accuracy of the device and prevent unintended multiple presses of the button.
When this button is pressed on the STM32 controller, the system starts calibrating the ball until the error becomes lower than Deadband.
PID control stands for Proportional- Integral- Derivative control, so its the combination of 3 controllers with each having its own function. Because each controller has its own advantages and disadvantages, combining the 3 of them in 1 controller eliminates the disadvantages of using each one individually.
A proportional controller modifies the control signal proportionally to the difference between the desired setpoint and the actual process variable. In other words, it calculates the control signal by multiplying the mistake by a gain factor. Due to the control signal's direct relationship to the error's magnitude, the process is subsequently more precisely controlled. They are easy to implement, have a quick response time, and require little tuning. In some systems, however, proportional controllers might be unable to deliver the requisite level of stability and control, and additional control elements like derivative or integral controllers can be needed to achieve the desired performance.
An integral controller calculates the integral of the error, which is the sum of all past errors, and multiplies it by a gain factor to determine the control signal. This helps to eliminate steady-state error, which occurs when a proportional controller is unable to drive the process variable to its desired setpoint. Integral controllers are commonly used in conjunction with proportional controllers to provide improved performance and stability in control systems. They have the ability to drive the process variable to the setpoint and maintain it there, even in the presence of disturbances. However, integral controllers can cause overshoot and oscillations if not properly designed and tuned. They also have a slower response time compared to proportional controllers and may be less-suitable for dynamic systems.
A derivative controller adjusts the control signal based on the rate of change of the error. It calculates the derivative of the error, which is the rate at which the error is changing, and multiplies it by a gain factor to determine the control signal. This helps to improve the response time and stability of the control system by anticipating the future behavior of the process variable and reducing overshoot. Derivative controllers are commonly used in conjunction with proportional and integral controllers to provide a more complete control solution. They are particularly useful in high-dynamic systems where a fast response time is required. However, derivative controllers can also amplify noise in the measurement signal and cause instability if not properly designed and tuned.
Whether you are a seasoned programmer or just starting out with C, we encourage you to explore the full potential of this new option and see what you can accomplish with the Acrome ball balancing table system.
You can check Ball Balancing Table and its other software options and our other products by checking our website ! together we shape the engineers of the future.