-
Notifications
You must be signed in to change notification settings - Fork 0
Software
The Coding Language used for this system is C++ with the operating system as Linux on the Raspberry Pi. As it can be seen from the system diagram of the home page, the Raspberry Pi measures the generated voltage from the DC motor, adjusts the blade pitch accordingly using a PWM (Pulse-Width-Modulation) Proportional Controller and displays these information on the Linux Terminal.
As stated in Electronics, the ADS1015 is used to allow the Raspberry Pi to read analog signals. It has a programmable gain from 2/3x to 16x to amplify small signals and read them with higher precision. A written C++ library for using the ADs1015 can be found on https://github.com/hallgrimur1471/Adafruit_ADS1X15_RPi. This library uses the wiringPi library to conduct I2C communications.
Following the single-ended example provided by the library, a script is written for reading the voltage generated in milliVolts (mV). This can be demonstrated with the test code provided. A programmable gain of one is given to define the voltage range to +/-4.096 V as this is the closest to the Raspberry Pi's range of 3.3 V.
The ADS1015 provides 12 bits of data (2^12=4096 levels) in binary two's complement format. A simple algorithm is needed to convert the two's complement binary to voltage in mV. This was done by multiplying the data from the ADC by (3.3 divided by 4096) to give the voltage in volts and a further multiplication of 1000 to give the voltage in mV. The sampling frequency for this application is 100Hz.
The blade pitch is controlled using a servo motor (S3003) which requires an electric pulse of variable width (PWM) that determines the amount of movement of the shaft. The S3003 servo motor turns 45° in both directions for a total of 90° movement. The PWM signal sent to the servo motor determines the position of the shaft. The duration of the pulse turns the rotor to the desired position.
The wiringPi library is used to generate the PWM signal from the Raspberry Pi's GPIO Pin 1. Most generic servo motors expect to see a pulse every 20 ms (50Hz) and the length of the pulse determines how far they turn. The PWM frequency is set using the formula below.
To obtain a PWM frequency of 50Hz, the PWM Clock and Range is set to 192 and 2000 respectively. Servo motors often respond to pulse lengths of 0.5ms to 2.5ms. With the mechanical design of the turbine, the best range of PWM pulse length is 0.75ms (blade about 40° from perpendicular airflow) to 1.1ms (blade perpendicular to airflow).
A proportional controller was designed to generate PWM pulse length according to the change in generated voltage readings as shown in the figure below.
Due to the impact of Covid-19, the op-amp circuit was not included during the software development. The input voltage range obtained from blowing air to the model turbine using a hair dryer is about 0-24 mV. Using this input voltage range, the accepted desired voltage was set to 10mV. An error is calculated from the difference between the desired voltage and actual voltage. If the error is more than 1 (actual voltage not within 10±1 mV), a new PWM pulse length is calculated using the formula shown below.
To ensure the software respond in real-time, two threads were introduced. One to obtain the input voltage reading and the other to respond with a new PWM signal according to the readings obtained. The software diagram is shown below.

With the controller in place, a graph shown below is obtained to show its response.