Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert...

24
ECE 09.321: Systems and Controls Solar panel positioning using stepper motors Stephen Glass Section 2 June 16, 2018 1 Abstract Alternative forms of energy such as solar power are used in developing areas which lack stable a source of energy. In these cases, the efficiency of a solar panel is im- portant to generate maximum electricity. A two-axis solar panel positioning system is implemented using NEMA 11 standard stepper motors. A proportional control system is developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper motors are able to move to any calculated position. The system is successfully able to rotate and tilt a solar panel to face the greatest light source. 2 Introduction Some 15% of the world’s population still lack access to electricity [1]. Alternative forms and renewable sources of energy are being used in rural areas to provide a sta- ble power source to these people. A form of renewable energy used in these regions are solar panels which convert energy from the sun to electrical potential. In these areas with no electrical infrastructure it is important the efficiency of the solar panels are maximized to produce greatest amount of power. However, stationary solar pan- els lose efficiency as the sun travels east to west due to lower amount of direct light projected onto the solar panel. The percentage loss efficiency of a solar panel due to misaligned positioning is de- fined by Loss(%) = 1 - cos(i) where i is the angle in degrees where the solar panel is misaligned [2]. Figure 1 below displays the direct power loss which occurs for vari- ous angles of misalignment for solar panels determined using the formula previously mentioned.

Transcript of Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert...

Page 1: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

ECE 09.321: Systems and Controls

Solar panel positioning using stepper motors

Stephen GlassSection 2

June 16, 2018

1 Abstract

Alternative forms of energy such as solar power are used in developing areas whichlack stable a source of energy. In these cases, the efficiency of a solar panel is im-portant to generate maximum electricity. A two-axis solar panel positioning system isimplemented using NEMA 11 standard stepper motors. A proportional control systemis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to aposition value while maintaining system stability. Stepper motors are able to move toany calculated position. The system is successfully able to rotate and tilt a solar panelto face the greatest light source.

2 Introduction

Some 15% of the world’s population still lack access to electricity [1]. Alternativeforms and renewable sources of energy are being used in rural areas to provide a sta-ble power source to these people. A form of renewable energy used in these regionsare solar panels which convert energy from the sun to electrical potential. In theseareas with no electrical infrastructure it is important the efficiency of the solar panelsare maximized to produce greatest amount of power. However, stationary solar pan-els lose efficiency as the sun travels east to west due to lower amount of direct lightprojected onto the solar panel.

The percentage loss efficiency of a solar panel due to misaligned positioning is de-fined by Loss(%) = 1 − cos(i) where i is the angle in degrees where the solar panelis misaligned [2]. Figure 1 below displays the direct power loss which occurs for vari-ous angles of misalignment for solar panels determined using the formula previouslymentioned.

Page 2: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

Figure 1: Direct power loss due to the misalignment angle of the solar panel

With a system that positions a solar panel towards the direction of the sun (solartracking), the efficiency of the solar panel can be optimized for maximum direct poweroutput. A system which positions a solar panel with a misalignment accuracy of ±5degrees will result in direct power output of approximately 99.6%.

In the context of providing electricity to rural areas where solar electricity is the onlysource of power, it is crucial the direct power output is maximized. Therefore, it is im-portant to implement either basic one-axis or two-axis positional control to tilt and/orthe solar panel to the greatest light source. This project implements a two-axis posi-tional system which could optimize the direct light on a solar panel and reduce panelmisalignment.

3 Standards and constraints

3.1 Standards and regulations

The project follows standards by the National Electrical Manufacturers Association byusing NEMA 11 standard stepper motors which ensure universal size of the motor.The microprocessor communicates with a PC using UART (Universal AsynchronousReciever and Transmitter) standard for serial communication. The embedded softwarefollows standard camel case naming convention for variables and functions.

Solar panel positioning using stepper motors 2

Page 3: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

3.2 Constraints

Hardware Constraints:

• Texas Instruments DRV8825 stepper motor driver IC requires 12V bipolar step-per motor

• Texas Instruments DRV8825 stepper motor driver IC is manufactured only inTSSOP surface mount package which requires special soldering techniques forPCB prototyping

• SparkFun ROB-10551 Stepper Motor load must not exceed 0.4A

• MSP430G2553 contains only 8 ADC pins and 12 GPIO pins

• MSP430G2553 does not have FRAM and stepper motors are not closed-loopsystems so the overall system will need to be manually reset to the startingposition whenever power is disconnected

• The stepper motor does not have a lot of torque so the physical size and massof the system must be minimal

• Stepper motor has a step degree of 7.5 therefore the minimum misalignmentangle is constrained by the motor

Software Constraints:

• MSP430G2553 does not have a hardware multiplier or FRAM so intense mathoperations such as trigonometry functions must be used sparingly

General Constraints:

• Limited time available to build the system and design the software

4 Control theory

4.1 System characterization

The system is characterized as a MISO (Multiple Input, Single Output) system. Theprocessor has five ADC inputs enabled for light-dependent resistors (photo-resistors)sensors. The voltage inputs from the photo-resistors are used to mathematically cal-culate the positional output of the system. The output of the system is the position ofthe stepper motors which result in maximum light to the array of photo-resistors. Thestepper motor utilizes a permanent magnet for motor control and will only move po-sition when commanded. Therefore, the system has no natural overshoot or settlingtime.

Solar panel positioning using stepper motors 3

Page 4: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

4.2 Ensuring stability

One thing that could cause instability in this system is an incorrect voltage readingfrom the ADC. The incorrect voltage would corrupt the desired position output of thesystem. However, this possible source of instability can be detected and preventedwith software.

We determine the sensor which is receiving the maximum amount of light. We thenfind the sensor which is receiving the greatest light excluding the previous sensorwhich was chosen; this new maximum must also neighbor the previous sensor. Wecan figure the greatest light source is some angular distance in between the two sen-sors. The arc tangent of the two sensor voltages is calculated to determine the dis-tance in between the two sensors the light source is maximized. The control loop fordetermining the distance to move between the two sensors is shown in the code blockbelow.

1 #pragma vec to r=TIMER0 A0 VECTOR2 i n t e r r u p t vo id Timer0 A0 ( vo id )3 4 i f ( waitSampleSensor >= SAMPLE RATE SENSOR)5 6 ADC10CTL0 |= ENC + ADC10SC;7 waitSampleSensor = 0 ;8 P2OUT ˆ= STATUS LED;9

10 else waitSampleSensor ++;11 i f ( wa i tPos i t i onMoto rs >= SAMPLE RATE MOTORS)12 13 i f ( updatedSensorValue )14 15 u i n t 1 6 t d i rec t i onX , d i rect ionXNear , moveAngle , resu l tS tep ,

r e s u l t S t e p T i l t ;16 f l o a t prec is ionAngle , p r e c i s i o n T i l t ;17 d i r e c t i o n X = maximumArray (SENSOR TOP, MAX SENSOR, MAX SENSOR) ;18 i f ( d i rect ionXSaved == SENSOR XNEG && d i r e c t i o n X == SENSOR XPOS)

r e Ch e c kS t a b i l i t y = t rue ;19 else i f ( d i rect ionXSaved == SENSOR XPOS && d i r e c t i o n X ==

SENSOR XNEG) re C h ec k S ta b i l i t y = t rue ;20 else i f ( d i rect ionXSaved == SENSOR YNEG && d i r e c t i o n X ==

SENSOR YPOS) r eC h e ck S t ab i l i t y = t rue ;21 else i f ( d i rect ionXSaved == SENSOR YPOS && d i r e c t i o n X ==

SENSOR YNEG) re C h ec k S ta b i l i t y = t rue ;22 direct ionXSaved = d i r e c t i o n X ;23 i f ( r e C h ec k S ta b i l i t y )24 25 r e Ch e c kS t a b i l i t y = f a l s e ;26 / / Perform code to f i n d arc tan o f the two sensors27 se tMoto rPos i t i on (MOTOR1, resu l tS tep ) ;28 se tMoto rPos i t i on (MOTOR2, r e s u l t S t e p T i l t ) ;29 30 31 wai tPos i t i onMoto rs = 0;32 33 else wa i tPos i t i onMoto rs ++;34

Solar panel positioning using stepper motors 4

Page 5: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

The control loop is triggered from TimerA0 on the MSP430G2553. Inside the maincode loop, two other loops are executed if the sampling rate is met. The ADC pinswill be sampled if SAMPLE RATE SENSOR criterion is met. If the criterion is met theADC will be triggered to start sampling and updating global variables with the currentlight readings of the sensors.

The control loop to perform mathematical operations on the sensor voltages and de-termine where to move to move the motors is performed if the SAMPLE RATE MOTORScriterion is met. The loop will only continue if there are updated values from the lightsensors. The code determines the sensor which is receiving the greatest amount oflight as discussed before. If the sensor found is not neighboring the sensor found inthe previous control loop execution we prevent any calculations from occurring duringthe loop to prevent instability. This is to ensure that system will not move uncontrol-lably and become unstable due to some unusual spike in sensor voltage. If we detectpossible instability the code will skip the current loop and wait for updated ADC read-ings. If the system is found to be stable, we perform calculations to determine theangular distance in between the two maximum sensors. A flowchart describing thisprocess is shown in Figure 2 below.

Figure 2: Flowchart describing process for ensuring stability in calculations

Solar panel positioning using stepper motors 5

Page 6: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

4.3 Proportional control for stepper motors

A proportion control in engineering is a type of linear feedback system in which acorrection is applied to the controlled variable which is proportional to the differencebetween the desired value (set point) and the measured value (process value) [3]. Inthis project the measured value is the amount of steps traveled by the stepper motor,which is logged in the software. The desired value is the position calculated to travelwhere the light source is the greatest. The desired position value is calculated in thecalculation control loop discussed in Section 4.2. The position value is processed inthe following function shown in the code block below.

1 vo id se tMoto rPos i t i on ( const u i n t 1 6 t motorID , u i n t 1 6 t p o s i t i o n )2 3 swi tch ( motorID )4 5 case MOTOR1:6 7 i f ( pos i t ionMotor1 != p o s i t i o n )8 9 / / Motor1 goes p o s i t i v e i n counter c lockwise d i r e c t i o n

10 i n t d is tance = 384 − f abs f ( fmodf ( f abs f ( pos i t ionMotor1 −p o s i t i o n ) , 768) − 384) ;

11 i f ( pos i t ionMotor1 + d is tance == p o s i t i o n ) se tMo to rD i rec t i on (MOTOR1, CCW) ;

12 else i f ( pos i t ionMotor1 − d is tance == p o s i t i o n )se tMo to rD i rec t i on (MOTOR1, CW) ;

13 else i f (768 − ( d is tance − pos i t ionMotor1 ) == p o s i t i o n )se tMo to rD i rec t i on (MOTOR1, CW) ;

14 else se tMo to rD i rec t i on (MOTOR1, CCW) ;15 stepAmountMotor1 = d is tance ;16 17 break ;18 19 20

The function takes the desired position value and the current position and determinesthe total distance to travel by the equation Distance = Revolution/2 − |(|current −desired| mod Revolution)−Revolution/2| where the total amount of steps in a revo-lution for our stepper motor is 768. The function sets appropriate values to tell a controlloop how many steps to travel and in which direction (clockwise or counter-clockwise).

The control loop to move the motors is triggered by TimerA1. If there are steps tomove, it sends a PWM pulse to the stepper motor to move a step in the correct direc-tion. The amount of steps to move is decremented by one each pulse. The controlloop is seen in the code block below.

1 #pragma vec to r=TIMER1 A0 VECTOR2 i n t e r r u p t vo id Timer1 A0 ( vo id )3 4 / / Toggle STEP pins5 i f ( stepAmountMotor1 > 0)6 7 i f (P2OUT & MOTOR1 STEP PIN) / / Motor A step p in i s HIGH

Solar panel positioning using stepper motors 6

Page 7: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

8 9 P2OUT &= ˜ ( MOTOR1 STEP PIN) ; / / Disable the step high LOW

10 i f (P2OUT & MOTOR1 DIR PIN)11 12 / / Clockwise d i r e c t i o n13 pos i t ionMotor1 −= 1;14 i f ( pos i t ionMotor1 == 0) pos i t ionMotor1 = 768;15 16 else17 18 / / Counter−c lockwise d i r e c t i o n19 pos i t ionMotor1 += 1;20 i f ( pos i t ionMotor1 >= 768) pos i t ionMotor1 = 0;21 22 stepAmountMotor1 −= 1; / / Lower steps l e f t because we j u s t went

through one cyc le23 24 else / / Motor A step p in i s LOW25 26 P2OUT |= (MOTOR1 STEP PIN) ; / / Enable the step i npu t HIGH27 28 29

When TimerA1 is triggered it checks if the stepper motor is to move any steps. If it is,the software sends a PWM pulse to the motor driver to step the motor once. We checkthe motor direction in software to determine to increment or decrements the currentposition of the motor. Because we stepped the motor one step, we decrements thestep amount variable by one. A flowchart describing this process is shown in Figure 3below.

Figure 3: Flowchart describing process for stepping the motor

Solar panel positioning using stepper motors 7

Page 8: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

5 Design discussion

5.1 Physical design

The design goal is to realize a two-axis solar tracker for positional control. Steppermotors are used to rotate and tilt the panel in any direction to face the panel towardsthe greatest light source. Stepper motors were chosen due to the cheap price, smallform factor, and the the ability to rotate continuously. Two platforms are attached toeach stepper motor oriented different directions. One stepper motor will rotate themain platform and the second platform on top tilts the panel. The physical systemwas designed in CAD and the assembly can be visualized in Figure 4 below. TheCAD designs were processed through a 3D printer and was realized as shown inFigure 5.

Figure 4: CAD render of physical system Figure 5: 3D printed realization of system

Photo-resistors are mounted in the holes of the sensor array tower which is ad-jacent to the positioning system. As the light moves around the sensor array, thepositioning system will adjust the motor position to the greatest light source as seenby the sensors. The sensor array tower has five sensors in facing every direction so itis able to determine the direction of a light source from any direction.

Figure 6: The sensor array with photo-resistors facing every direction

Solar panel positioning using stepper motors 8

Page 9: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

5.2 Hardware design

The Texas Instruments MSP430G2553 is chosen as the microcontroller because itis affordable and comes in a through-hole DIP package. The processor has 6 ADCpins and 12 GPIO pins which is suitable for our application. The MSP430G2553 doesnot have a hardware multiplier or FRAM so we must be cautious of overloading theprocessor with intensive operations.

To drive the stepper motors we use Texas Instruments DRV8825 motor driver IC.The motor driver is simple to use because it only requires a step PWM input and di-rectional input from the microprocessor. Typically, a stepper motor requires at leastfour GPIO pins, however, with the limited IO of the microprocessor this would not besuitable. The DRV8825 must be powered with 12V and requires use of a bipolar step-per motor. The SparkFun ROB-10551 NEMA 11 stepper motor was chosen becauseit was the cheapest 12V powered bipolar motor available. The motor and motor driverare powered using the 12V supply. A 3.3V linear voltage regulator output is used topower the MSP430G2553.

5.3 PCB Design

A prototype PCB was designed and manufactured using JLCPCB service. The two-layer PCB connects the MSP430G2553, sensor array, motor drivers, and stepper mo-tors in a small and convenient package. The board has header pins for easy connec-tivity to the stepper motors and the sensors.

Figure 7: PCB Schematic Figure 8: Manufactured PCB

The power input to the board is 12V which powers the stepper motors. There is a 3.3Vregulator which steps-down the voltage to power the MSP430G2553 microprocessor.The processor is programmed by using a TI MSP430G2553 LaunchPad DevelopmentBoard and connecting the TEST and RST pins to the appropriate pins on the PCBheaders. The software is stored on the microprocessor flash memory.

Additionally, on the board are headers for connecting the photo-resistor sensors.There are five photo-resistor sensors so there are five pairs of 1x2 male headers.

Solar panel positioning using stepper motors 9

Page 10: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

Each sensor is connected to the appropriate header which is connected to the ADCchannels on the microprocessor. The two stepper motors are connected to the appro-priate male headers on the board as well.

The PCB is designed with first and second-order design principles in mind. For exam-ple, bulk and bypass capacitors are used to ensure stability and noise cancellation.The TI DRV8825 ICs have proper thermal heat sinking and heat dissipation. Thespecification sheets and application notes were referenced for all components in allaspects of the PCB design.

5.4 System block diagram

The system can be simplified to a block diagram as shown in Figure 9 below. Thestepper motor moves with proportional control calculated with the feedback of thephoto-resistor sensors converted to positions. The output of the system is the finalcalculated position where the light source is detected to be the greatest.

Figure 9: Block diagram describing the system

Figure 10: Block diagram describing the system replaced with symbols

The proportional controller (Gc) and the system (G) can be cascaded as one blockGcG. Also, the sensor voltage feedback (H1) and the voltage to position conversion(H2) can be cascaded as one block H1H2. The reduced diagram is shown in Figure11 below.

Solar panel positioning using stepper motors 10

Page 11: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

Figure 11: Block diagram describing reduced negative feedback system

The negative feedback system can be reduced to find the closed-loop transferfunction of the system shown in Figure 12 below.

Figure 12: Block diagram describing the closed-loop transfer function of the system

Solar panel positioning using stepper motors 11

Page 12: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

5.5 System architecture

The system first begins by initializing the microprocessor ADC and TimerA module.Because we are sampling five photo-resistor sensors the ADC is configured in mul-tiple sample, single sequence mode. The MSP430G2553 will sample each sensorone by one and storing the ADC value in memory. The ADC will sample and holddata for 5 clock cycles of ADC10OSC which is approximately 5 x 5MHz. The DCOsystem clock is configured at 1MHz and TimerA0 and TimerA1 modules are divided.TimerA0 is divided to trigger at a 100Hz frequency. TimerA1 will trigger variably in therange of 60Hz to 4kHz frequency. A flowchart (UML Diagram) outlining the systemarchitecture, initializations, and states of the system is shown in Figure 13 below.

Figure 13: UML Diagram of the system architecture

Multiple control loops are designed to be triggered from the TimerA0 and TimerA1modules. Under the TimerA0 module, we check if the ADC should be sampled if thesample rate criterion is met. If the criterion is met, we trigger the ADC to sample thephoto-resistor sensors. Additionally, the TimerA0 module checks if we should performcalculations to convert sensor voltage to position if the sample rate criterion is met.If the criterion is met, we first check if there are updated sensor values to performcalculations on. If there are updated sensor values, we determine the sensor whichhas the greatest light value. We determine the stability of the system by checking ifthe sensor which has the greatest value is a neighbor of the previous greatest lightvalue. If the system is determined to be stable, we calculate the precise positions tomove the stepper motors for rotation and tilt so it faces the light source. The calcu-lated desired position is processed to determine the direction and amount of steps the

Solar panel positioning using stepper motors 12

Page 13: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

motor needs to move to reach that position. The mathematical theory behind thesecalculations are described in the next section 5.6.

The TimerA1 module is designed to pulse PWM signals to step the stepper motorto reach the desired position. When TimerA1 is triggered it checks if the current posi-tion of the motor is different from the desired position. If the stepper motor needs tomove it checks the direction of the motor, steps the motor, and increments or decre-ments the motor position variable if the direction is counter-clockwise or clockwise.

5.6 Mathematical design theory

Determining optimal and precise positions to rotate and tilt the solar panel requiresmathematical computations by the microprocessor. The mathematical computationsto determine the precise precision occurs in the control loop triggered by TimerA0when the sample rate criterion is satisfied.

When there are updated sensor values to perform calculations on and the systemis determined to be stable (these requirements are discussed in previous sections),we can begin the computations. First, we need to determine the sensor which hasthe greatest light value. Next, we need to find the sensor which has the greatest lightvalue neighboring the previous sensor. Now, the light source has to be some distancein between the two calculated sensors. The position of each of the two sensors areknown parameters. We can estimate the distance in between the two sensors by per-forming trigonometric calculations.

Figure 14: Example of a light source positioned near the sensor array (1)

Solar panel positioning using stepper motors 13

Page 14: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

In Figure 14 above, a light source is placed at a 45 degree angle to the sensor arrayso light is equally distributed on sensor 1 and sensor 2. For this example assume thesensor light values x are x(1) = 50, x(2) = 50, x(3) = 0, x(4) = 0. The sensor whichhas the greatest light value is x(1) and the sensor which has the greatest light valueand neighbors x(1) is x(2). The arc tangent of these two values are computed to findthe distance (steps) in between the sensors where the light source is.

y = P + tan−1(neighbor/sensor) ∗ (180/π) ∗ 2.13

y = 0 + tan−1(50/50) ∗ (180/π) ∗ 2.13

y = 0 + 0.7853 ∗ (180/π) ∗ 2.13

y = 45 ∗ 2.13

y = 95.85

In the equation above, P is the position (in steps) of the location of the sensor withthe greatest light value. neighbor is the light value of the maximum sensor neighboringthe sensor with the greatest light value. sensor is the light value of the sensor with thegreatest light value. The arc tangent of these two values are computed and convertedfrom radians to degrees. The degree is converted to steps by the constant multipli-cation conversion factor of 2.13. The final calculated position to move to is found byadding that value to the known position sensor. In this example, the position of sensoris at 0 steps, therefore the position for rotation is 95.85 + 0. After finding the positionof rotation for the panel, we must find the position of tilt for the panel because projectdemonstrates a two-axis implementation.

Figure 15: Example of a light source positioned near the sensor array (2)

Solar panel positioning using stepper motors 14

Page 15: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

Figure 15 above shows the same example of the light source placed near the sen-sor array. However, the perspective of the image was changed to a side-view to showhow we can utilize trigonometry to calculate the tilt position of the solar panel. Similarto before, the light source is placed at a 45 degree angle to the sensor of greatest lightvalue and the top [sensor 2] sensor. For this example assume the sensor light valuesx are x(1) = 50, x(2) = 50 where x(2) is the top sensor [sensor 2]. The arc tangentof these two values are computed to find the distance (steps in between the sensorswhere the light source is.

z = tan−1(sensor/top) ∗ (180/π) ∗ 2.13

z = tan−1(50/50) ∗ (180/π) ∗ 2.13

z = 0.7853 ∗ (180/π) ∗ 2.13

z = 45 ∗ 2.13

z = 95.85

Similar to before, the arc tangent of the two values are computed, converted toradians and converted to steps. Note that we do not need to add P position like be-fore because the tilt position is always between 0 and 90 degrees. Now we have thepositions in steps for rotation and tilt where the light source is located in relation to thesolar panel. We process these position values to determine the direction and amountof steps the stepper motor must take to reach the desired position.

The function setMotorPosition determines the direction and amount of steps themotor should move to reach the desired position. The equations for determining thedistance amount and direction are seen below.

x = R/2− |(|pi − pf | mod R)−R/2|

y =

0 if pi + x = pf

1 if pi − x = pf

1 if R− (x− pi) = pf

0 otherwise

R is the amount of steps for a full revolution, pi is the current position of the motor,pf is the desired position of the stepper motor, x is the amount of steps to reach thedesired position, y is the direction the motor needs to move [0 = counter-clockwise,1 = clockwise]. Because the stepper motors are bi-directional and does continuous360-degree rotation, the modulo operation is used to find the least distance to travel toreach the desired position. Using the step distance x we determine the step directiony using conditional statements. An example of this process is described in Figure 16below.

Solar panel positioning using stepper motors 15

Page 16: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

Figure 16: Example of a light source positioned near the positioning system

For the example displayed in Figure 16 above, the current position of the steppermotor pi = 575 and the desired position pf = 384. The amount of steps for a completerevolution R = 768. Using the equations discussed we can determine the amount ofsteps to reach the destination and the direction.

x = R/2− |(|pi − pf | mod R)−R/2|x = 768/2− |(|575− 384| mod 768)− 768/2|x = 384− |(191 mod 768)− 384|x = 384− |(191)− 384|x = 384− 193

x = 191

pi − x = pf

575− 191 = 384

y = 1

The step amount x is calculated to be 191 steps and the direction y is clockwise.The system must rotate 191 steps in the clockwise direction to be at the desired setposition. These calculated values are used in the TimerA1 control loop to move themotors to the correct positions as discussed in Section 4.3 and Section 5.5.

Solar panel positioning using stepper motors 16

Page 17: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

5.7 Motor stepping calculations

To correctly figure out how to move a stepper motor to any desired position we needto figure out how many degrees the motor moves per step. We know from the motordatasheet the step angle Θ = 7.5. This means for one full step the motor moves 7.5.This step angle is very large and if we performed a full step the system would be veryimprecise and the large steps may cause instability. Using the DRV8825 motor driverIC we can reduce the step amount as shown in Table 1 below.

Table 1: DRV8825 micro-stepping options

The 16 microsteps/step option is used because it allows precise movement and a rel-atively low steps per revolution. We enable this mode by pulling pin MODE2 HIGHand MODE1, MODE0 pins LOW. We can now calculate the new step angle Θf .

Θf = Θi ∗ (1/16)

Θf = (7.5) ∗ (1/16)

Θf = 0.46875

With this new step angle, the new steps per revolution is calculated by 360/Θf = 768.We also calculate the frequency of TimerA1 to result in specific RPM values of thestepper motor. For example, a 250Hz timer is triggered every 0.004s with a risingedge every 0.008s. Therefore, every 0.008s the stepper motor moves Θf or 0.46875degrees. We calculate the amount of steps the motor takes when running for oneminute by performing the conversion below.

0.46875

0.008s=

x

60x = 3515.625

The motor travels 3515.625 degrees every minute. We divide this by 360 degreesto obtain the rotations per minute (RPM) of 9.76RPM for the motor with this specific250Hz timer frequency.

Solar panel positioning using stepper motors 17

Page 18: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

5.8 Schematics of systems

The MSP430G2553 microprocessor connects the photo-resistor sensors and the mo-tor driver IC. Refer to the schematic (Figure 17). The photo-resistors are configuredas voltage-dividers with 1kΩ and the wiper of the divider is connected to ADC pins ofthe microprocessor seen in Table 2 below.

ADC Microprocessor ConnectionsPin SensorP1.0 (A0) SENSOR TOPP1.3 (A3) SENSOR XNEGP1.4 (A4) SENSOR XPOSP1.5 (A5) SENSOR YNEGP1.6 (A6) SENSOR YPOS

Table 2: Connections to the ADC of the MSP430G2553 microprocessor

There are 4 total connections from the MSP430G2553 to the DRV8825 motordrivers; 2 connections per motor driver. P2.2, P2.3 control the step (STEP) and direc-tion (DIR) of the first motor (rotation). P2.4, 2.5 control the step and direction of thesecond motor (tilt). P2.0 is used to control the LED light indicator. P1.1 and P1.2 areRX and TX ports for UART communication.

Figure 17: Schematic of the MSP430G2553 microprocessor connections

Solar panel positioning using stepper motors 18

Page 19: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

The DRV8825 motor driver ICs are only able to be powered by 12V. Therefore,the main power to the system is 12V to power the motors and a 3.3V linear regulatoris used to step-down the voltage for the MSP430G2553 microprocessor. There aresufficient bulk and bypass capacitors to the motor drivers in accordance to the TexasInstrument application notes. The STEP and DIR pins are connected to the micro-processor. A LOW signal on the DIR pin will move the motor clock-wise and a HIGHsignal counter-clock-wise. When the STEP pin receives a rising edge signal from themicroprocessor, the stepper motor will move (1/16) step. The MODE2 pin is pulledhigh for 1/16 stepping mode. The RST and SLEEP pins are also pulled high to keepthe system always active. The stepper motor we are using has a current rating at only0.4A so we must also design current limiting circuitry. We can specify the current limitfor the motor by the following equation below.

IFS(A) =VREF (A)

5×RSENSE(Ω)

The voltage reference VREF to pin AVREF, BVREF is 0.4V created by the voltagedivider from the output of the 3.3V regulator. A value of 0.2Ω for RSENSE is used.Therefore, the current limit of the motor IFS determined by the equation is set at 0.4A.The schematic of the motor driver IC system is seen in Figure 18 below.

Figure 18: Schematic of the DRV8825 motor driver IC connections

Solar panel positioning using stepper motors 19

Page 20: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

5.9 Additional software design

Because trigonometric operations are computationally intensive for the MSP430G2553microprocessor, many second-order design procedures were utilized to ensure themicroprocessor ran efficiently. All variables are optimized to utilize as little programmemory as possible. Unsigned 16-bit integers (uint16 t) are used for mathematicalcalculations instead of normal integers or floats. Other optimizations were made suchas ensuring all loops count down to zero instead of counting up to an integer whichrequires more clock-cycles on the processor.

Code was implemented to calibrate the system to the environment. Because thesystem is tested indoors there will always be ambient light in the environment fromceiling lights or lamps. There is code to subtract a predefined bias from the resultingvoltage of the ADC results. The constant bias value can be adjusted for various envi-ronments the system is placed.

To reduce computations by the processor many calculations are pre-defined inlook-up tables. For example, instead of calculating the timer capture/compare regis-ters for different motor speeds, the values are stored in a one-dimensional array.

1 const u i n t 1 6 t f requencyTable [MAX FREQ] =0 ,16000 ,8000 ,4000 ,2000 ,1000 ,500 ,250 ;

frequencyTable[0] will stop the motors, frequencyTable[1] will initialize a 62.5Hz timerand set the stepper motors to 2.44RPM, frequencyTable[2] will initialize a 125Hz timerand set the stepper motors to 4.88RPM, etc.

The code is designed to be modular, readable (commented), and easily upgrade-able to add support for new features. The code follows consistent design and camel-case naming conventions. The system utilizes a LED indicator light which can flashdepending on status of the system. Additionally, there is support for UART serial-communication with a PC for debugging and to read commands sent from a terminal.

6 Results and Conclusions

The goal of implementing a two-axis solar panel positioning system was successfullyaccomplished for this project. Control theory was realized in building this system byutilizing proportional control, determining stability, managing control loops and stabi-lizing sources of error. A physical system was 3D printed, a PCB was designed andmanufactured, and optimized software was written using Code Composer Studio forthe MSP430G2553. As seen in the project demonstration in lab, the system fulfills thedesign goals and specifications. The assembled system is seen in Figure 19 below.

Solar panel positioning using stepper motors 20

Page 21: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

Figure 19: Fully assembled and connected system

The system is able to accurately rotate and tilt a solar panel to the greatest lightsource. Figure 20 and Figure 21 below demonstrate the system rotating and tilting tothe greatest light source.

Figure 20: Light source at angle Figure 21: Light source on top

In Figure 20 the light source is pointed at a 45 degree angle to the sensor array similarto Figure 14. The system correctly rotates and tilts the panel to the correct positionfacing the light source. In Figure 21 the greatest light source is overwhelmingly great-est on the top sensor so the system tilts the panel to face up. The system will rotateand tilt the panel to follow the light source as it moves.

Solar panel positioning using stepper motors 21

Page 22: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

Through experimentation we discovered the values for motor speed, samplingrates, DC bias which cause the system to be stable.

Experimental ParametersParameter ValueADC Sampling Rate 0.01sADC Sample/Hold Rate 8 x ADC10OSCSensor to Position Calculation Rate 1.00sConstant Bias (unitless) 200Motor Speed 39 RPM

Table 3: Experiential results for parameters of a stable system

In conclusion, the final implemented system works well and meets the design goalsset forth. The system utilizes control theory by using proportional control and othermethods for ensuring stability of the system. The project includes a real-life applica-tion and solves a real-world problem. I learned how to completely realize a controlsystem from start to finish - incorporating a physical system with embedded softwaredesign and working with standards and constraints. The use of stepper motors in thisproject made the project much more difficult (opposed to a servo motor), however, italso made the learning experience of a control system more apparent.

Work Distribution The only member on this project was Stephen Glass. Thedesign, implementation, performance evaluation, and report was done by StephenGlass.

Solar panel positioning using stepper motors 22

Page 23: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

7 References

[1] Kaygusuz, K. (2012). Energy for sustainable development: A case of developingcountries. Renewable and Sustainable Energy Reviews, 16(2), pp.1116-1126.

[2] https //en.wikipedia.org/wiki/Solar tracker

[3] https //en.wikipedia.org/wiki/Proportional control

Resources used for design:

1. http //www.ti.com/lit/an/slaa785/slaa785.pdf

2. http //www.ti.com/lit/ds/symlink/drv8825.pdf

Solar panel positioning using stepper motors 23

Page 24: Solar panel positioning using stepper motorsis developed for the MSP430G2553 to convert photo-resistor sensor ADC values to a position value while maintaining system stability. Stepper

Stephen Glass ECE 09.321: Systems and Controls Section 2

8 Appendix

A ZIP file containing MSP430 code (Code/solarPanelCode.c), 3D models, DipTracedesign files for PCB and Schematics, and all the figures in this report can be down-loaded with the link below.[Removed]

A1: Schematic of the entire system including microprocessor, sensors, and motordriver IC

Solar panel positioning using stepper motors 24