Design of sun tracking system based on microcontroller

Everyone is welcome to like, collect, follow and comment. Due to limited space, only part of the core code is shown. For technical exchanges, please look for the contact information officially provided by CSDN below

Article directory

    • summary
  • 1. Main content of design
  • 2. Hardware circuit design
    • 2.1 Selection of tracking control scheme
    • 2.1.1 Selection of tracking system coordinate system
    • 2.2 Overall system design and related hardware introduction
  • 3. Software design
    • 3.1 System main program design
    • Schematic diagram
    • Source program listing
  • 4. Conclusion
  • 5. Article Table of Contents

Summary

According to the relative motion rules of the sun and the earth and the motion orbit of the sun relative to the earth in the equatorial coordinate system and the horizon coordinate system, and based on the application value, an open-loop tracking control strategy using a stepper motor as the driving mechanism is proposed, and A corresponding control system was designed. According to the requirements of the control system, this article selected the AT89C51RC microcontroller as the core component and completed the peripheral hardware circuit design and corresponding software design of the microcontroller. The article introduces the important components in the system hardware circuit and the functions they implement in detail, and designs the corresponding hardware interface circuit, which mainly includes the reset circuit, I2C serial communication circuit and stepper motor drive circuit, and details it in the form of a software flow chart. The software design ideas of this article are explained.
Keywords: solar thermal power generation; solar tracking; microcontroller; open-loop tracking

1. Main content of the design

Since the position of the sun relative to the concentrator is changing all the time, this requires the concentrator to constantly change its orientation and keep the sun on the main optical axis of the solar concentrator in real time, that is, it is always aligned with the sun to provide limited reception. area captures as much solar radiant energy as possible. To keep the sun always on the main optical axis of the concentrator, a tracking system is necessary. This paper will design and develop a tracking control system for solar thermal power generation.
The main contents of the paper design include hardware design and software design.
Hardware parts:
① Reset circuit.
② I2C communication circuit, including the connection of peripheral bus, keyboard display chip and calendar clock chip.
③ Stepper motor module circuit, including reverse driver and stepper motor driver connections.
④ Draw the overall circuit diagram of the system.
Software systems include:
① The overall system design flow chart and its procedures.
② I2C communication module software design, including I2C bus connection diagram, initialization flow chart, button processing flow chart and time adjustment flow chart and program.
③ Stepper motor software design, including calculation module flow chart and stepper motor module flow chart.

2. Hardware circuit design

2.1 Selection of tracking control scheme

2.1.1 Selection of tracking system coordinate system

In a solar thermal power generation system, the bracket must not only support the concentrator, but also support a multi-ton engine placed at the focus of the concentrator. If a polar coordinate system is used, although the tracking method is simple, the weight of the condenser does not pass through the polar axis, and the design of the polar support device is difficult. Therefore, this design does not use the polar coordinate system.
For larger systems, the horizon coordinate system is often used in engineering. A special advantage of using a horizon coordinate system is that the gravity plane is kept in the vertical plane through the collector. This minimizes gravity deviations on the collector surface and simplifies the engineering design of the collector and its supports to a minimum. limit, the torque on the collector’s shaft and bearings is also minimized. Therefore, the support structure of the collector using the horizon coordinate system is relatively simple.
2.1.2 Selection of tracking methods and tracking systems
Tracking control methods are divided into three types: closed-loop tracking, open-loop tracking and hybrid tracking control.
The main difference between closed-loop tracking and open-loop tracking control methods is the presence or absence of feedback information. Hybrid tracking control method is a tracking control method that combines closed-loop tracking and open-loop tracking, and is a hybrid tracking control method. The hybrid tracking method has the advantages of the closed-loop tracking method as well as the advantages of the open-loop method. If high-performance sensors are used for photoelectric tracking modules, the cost of the tracking system will undoubtedly be greatly increased, which is something we do not want to see in industrial production; if ordinary sensors are used, the tracking system will have the disadvantage of slow response. , poor accuracy, low stability, and closed-loop tracking cannot be applied to cloudy weather. Based on the local longitude and latitude, date and time, an open-loop control method is used, and the position of the collector at the next moment is obtained through mathematical calculation of the solar orbit. This allows the collector to be driven electrically to keep the sun always on the main optical axis of the collector. Track the sun in orbit, no matter the weather. As a result, there is also a disadvantage that as time goes by, the cumulative error of the system will have an increasing impact, and the tracking effect will decrease significantly.
Because the stepper motor only has periodic errors and no cumulative errors, when the stepper motor is not overloaded, its speed and stop position only depend on the frequency and number of pulses of the pulse signal and are not affected by load changes. Therefore, using a stepper motor as the actuator of the tracking system can effectively control the cumulative error of the system.
The control method of this paper adopts open-loop program control, which performs two-dimensional tracking of the solar altitude angle and azimuth angle respectively, and the actuator uses a stepper motor.

2.2 Overall system design and related hardware introduction

The system diagram is shown in Figure 2-l. The microcontroller is the core of the control system. The keyboard display chip manages the keyboard and display as a driver for keyboard command input and related data display. The calendar clock chip provides an accurate clock for the system as a time standard. ;The stepper motor driver indirectly controls the stepper motor. Relevant hardware interface circuits mainly include reset circuits, I2C communication circuits and stepper motor module circuits. This article will explain the selected microcontroller and main hardware circuits.

Figure 2-1 System diagram
Considering the functional requirements of this system for the microcontroller, this article selects the AT89C51RC microcontroller from ATMEL Corporation of the United States. This microcontroller has the following characteristics:
AT89C51RC is a new type of microcontroller developed on the basis of AT89C52. Its main features are:
●The chip contains 32KB of Flash program memory, and the erase and write cycle is 1000 times;
●On-chip data memory contains 512 bytes of RAM;
●With programmable 32-line I/O port (P0, P1, P2 and P3);
●Has 3 programmable timers TO, T1 and T2;
●The interrupt system is an interrupt structure with 8 interrupt sources, 6 interrupt vectors, and 2-level interrupt priority;
●Has a full-duplex UART serial port;
●Low power consumption working modes are idle mode and power-down mode;
●Has dual data pointers DPTR0 and DPTRl;
●With 3-level program lock bit;
●With hardware watchdog timer WDT;
●AT89C5 1 RC working power supply is 4.0-5.5V;
●The maximum operating frequency of AT89C5lRC is 33MHz;
●With power-off flag POF.
The pin arrangement of the AT89C51RC microcontroller PDIP package is shown in Figure 2-2.

Figure 2-2 AT89C51RC pin diagram

3. Software design

3.1 System main program design

The main program flow of this control system software design is shown in Figure 3-1, which is mainly divided into I2C serial communication module, angle calculation module and stepper motor module.

Figure 3-1 Main program flow chart

Schematic diagram

Source program list

Appendix 2 Source Program List
Main program:
#include "reg52.h"
#include "VI2C_C5 I.H" //Include VI2C package
#include "zlg7290.h"
#include "fgangel.h"
#include "motorun.h"
#include "manregstep.h"
#include<math.h>
#define PCF8563 0xA2
#define WRADDR 0x00
#define RDADDR 0x02
#define settime l
#define setdata 2
#define setlongitude 3
#define tran 4
#define up 5
#define down 6
#define left 7
#define OK 8
#define uint unsigned int
#define uchar unsigned char
sbit KEY_ INT=P3^2;
sbit RST=P1^2;
unsigned char disp_buf[8]={<!-- -->0,0,0,0,0,0,0,0};
unsigned char KEY;
float *fg;
bit switch date=0;
bit longtpn;
struct longitude
{<!-- -->
uint longtitudehour;,
uchar longtitudemin;
uchar longtitudesec;
};
 struct time
{<!-- -->
uchar hour;
uchar min;
uchar see;
}idata lconvtime;
struct longitude idata Lloc={<!-- -->116, 28, 0};
unsigned char loncontime(struct longitude idata*Lstal,struct longitude idata*LLloc);
··································
if(KEY==setdata) //is setdam?
{<!-- -->
IRcvStr(PCF8563, RDADDR, rd, Ox7); //Read the current hour, minute and second
display_date(rd + 3);
disp butl2]2disp_buf[2] &0x7f;
disp_butf[4]=disp_butl4] & amp;0x7f;
while(1)
{<!-- -->
disp_buf[i]=disp_buf[i]10x40; //E1 digit flashes first
ZLG7290_SendBuf(&disp_butl0], i + 1);
if(KEY_INT-==0)
{<!-- -->
KEY=ZLG7290_GetKey0;
if(KEY==up)//Add l
{<!-- -->
disp_buf[i]=disp_butIi] + 1;
if((disp_buf[i] & amp;OxOf)= 10)
{<!-- -->
disp_butIi]2disp_butli] &0x40;
}
}
if(KEY==down)
{<!-- -->
disp_buf[i]=disp_buf[i]-l;
if((disp_buf[i] & amp;OxOf)==OxOF)
{<!-- -->
disp_butIi]=0x49;
}
}
If(KEY'==left)
{<!-- -->
disp_buf[i]=disp__buf[i] & amp;0XBF; //stop flash
i=i + l;
if(i>5)
{<!-- -->
ZLG7290_sendBuf( & amp;disp_buf[0],8);
i=0;
}
}
if(KEY==ok)//confirm
{<!-- -->
disp_butli]=disp_butf[i] & amp;0XBF; //stop flash
ZLG7290_SendBuf( & amp;disp_buf[i],1);
tdl[0]=disp_buf[1]*1 6 + (disp_butl0] & amp;0XOF);
tdl[1]=dispbuf[3]*16 + disp_butl2];
tdl[2]=disp_buf[5]*16 + disp_buf[4];
ISendStr(PCF8563,WRADDR + 5,tdl,0x1);
ISendStr(PCF8563,WRADDR + 7, &tdl[1],ox2);
 i=0:
break;
}
}
}
}
···································
if(KEY=setlongitude)//is longitude?
{<!-- -->
display_longimde(Lloc);
while(1)
{<!-- -->
disp_buf[i]=disp buif[i] 0x40; //second flash first
ZLG7290_ SendBuf( & amp;disp_buf[0],i + 1);
if(KEY_INT==0)
{<!-- -->
KEY=ZLG7290_ GetKeY0;
if(KEY==up)//Add l
{<!-- -->
disp_buf[i]=disp_butli] + l;
if((disp_buf[i] & amp;0x0f)==10)
{<!-- -->
disp bur[i]=disp_buf[i] &0x40;
}
}
if(KEY= down)
{<!-- -->
disp_bul[i]=disp butli]-l;
if((disp_buflil & amp;OxOf)==OxOF)
{<!-- -->
disp_buf[i]=0x49;
}
}
if(KEY=left)
{<!-- -->
disp_but[i]=disp_buf[i] & amp;0XBF; //stop flash
i=i + l;
if(i>6)
{<!-- -->
ZLG7290_SendBuf( & amp;disp_buf[0],8);
i=0:
}
}
if(KEY=ok)//Confirm
{<!-- -->
Disp_buf[i]=disp_buf[i] & amp;0XBF; //Stop flash
Lloc. Iongtitudesec=disp_butf[l]*10 + disp_buf[0];
Lloc. 1ongtitudemin=disp_butf[3]*10 + disp_buf[2];
Lloc. longtitudehour=disp_buf[6]*100 + disp_buf[5]*10 + disp_buf[4];
 i=0:
break;
}
}
}
}
//Set latitude
···································
if(KEY=etlatitude)//is set latimde?
{<!-- -->
display_latitude(1atitude);
while(1)
{<!-- -->
disp_buf[i]=disp_buf[i] 0x40; //second flash first
ZLG7290_SendBuf( & amp;disp_butl0],i + 1);
If(KEY_INT==0)
{<!-- -->
KEY =ZLG7290_GetKeY0;
if(KEY==up)//Add l
{<!-- -->
disp_butf[i]=disp_buf[i] + l;
if((disp_buf[i] & amp;0xof)=l0)
{<!-- -->
disp_buf[i]=disp_buf[i] &0x40;
}
}
if(KEY==down)
{<!-- -->
disp_buf[i]=disp_butf[i] + 1;
if((disp_buf[i] & amp;OxOf)=20x0F)
{<!-- -->
disp_buf[i]=0x49;
}
}
If(KEY=left)
{<!-- -->
disp_buf[i]=disp_buf[i] &OXBF; //stop flash
i=i + l;
if(i>5)
{<!-- -->
ZLG7290_SendBuf( & amp;disp_buf[0],8);
i=O;
}
}
If(KEY==6)//Confirm
{<!-- -->
disp_buf[i]=disp_butIi] & amp;0XBF; //stop flash
latitude[2]=disp_buf[1]*10 + disp_buf[0];
latitude[1]=disp_butl3]*10 + disp_but[2];
latitude[0]=disp_buf[5]*10 + disp_butl4];
i=0;
break;
}
}
}
}
·Time adjustment subroutine
···································
if(KEY= =settime) //is settime?
{<!-- -->
IRcvStr(PCF8563,RDADDR,rd,0x3); //Read the current hour, minute and second
display_timeset(rd);
while(1)
{<!-- -->
disp_buf[i]=disp_buf[i]0x40; //Seconds flash first
ZLG7290_SendBuf(&disp_butl0], i + 1);
 if(KEY_INT= =0)
{<!-- -->
KEY=ZLG7290_GetKeY();
If(KEY= =up)//Add 1
{<!-- -->
disp_buf[i]=disp_butf[i] + 1;
if((disp_but[i] & amp;0x0f)= = 10)
{<!-- -->
disp_buf[i]=disp_buf[i] &0x40;
}
}
If(KEY= =down)
{<!-- -->
disp_buf[i]=disp_butIi]-1;
if((disp_buf[i] &0x0f)= =0x0F)
{<!-- -->
disp_bufIi]=0x49;
}
}
If(KEY==left)
{<!-- -->
disp_buf[i]=disp_buf[i] & amp;0XBF; //stop flash
i=i + l:
if(i>7)
{<!-- -->
ZLG7290_SendBuf( & amp;disp_buf[0],8);
i=0;
}
}
if(KEY==ok)//confirm
{<!-- -->
disp_buf[i]=disp_buf[i] & amp;0XBF; //stop flash
ZLG7290_SendBuf( & amp;disp_buf[i], 1);
 tdl[0]=disp_buf[1]*16 + (disp_butl0] & amp;0XOF);
tdl[1]=disp_butf[4]*16 + disp_buf[3];
tdl[2]=disp_buf[7]*16 + disp_buf[6];
ISendStr(PCF8563, WRADDR + 2, td l, 0x3);
i=0;
break;
}
}
}
}
}


















  

 



4. Conclusion

This design developed a hardware control circuit with AT89C51RC as the core. The hardware interface circuit mainly includes a reset circuit, an I2C serial communication circuit and a stepper motor drive circuit. At the same time, the software part is designed, and the control composed of the above software and hardware is The system realizes two-dimensional tracking of the sun in the horizon coordinate system.
Some prospects for the research direction of this topic:
1. Although using a stepper motor to drive the condenser to rotate can effectively control the cumulative error, it also has problems such as high power consumption and easy loss of steps when the load increases (such as in windy weather). The tracking method that uses DC motors as power machinery and eliminates system cumulative errors through a combination of open-loop and closed-loop control methods is more promising. However, the cost of photoelectric sensors with fast response speed and high accuracy is high, and the cost control of the tracking system relies on low cost. , Research and development of high-performance photoelectric sensors.
2. Considering the harsh actual application environment of solar tracking control systems (mostly desert areas), it is imperative to improve the anti-interference performance of the control circuit. With the development of electronic technology, improving the performance of components and chips and the modularity of system components are the general trends in the development of the control field.

5. Article directory

Table of contents
Summary I
Abstract II
1 Introduction 1
1.1 Background and significance of the topic 1
1.1.1 Solar thermal power generation technology is the most promising renewable energy power generation method 1
1.1.2 Prospects of several major solar thermal power generation methods 2
1.2 my country’s solar energy resources 3
1.3 Current situation at home and abroad 4
1.4 Main contents of the design of this paper 5
2 Design of system hardware 6
2.1 Selection of tracking control scheme 6
2.1.1 Selection of tracking system coordinate system 6
2.1.2 Selection of tracking methods and tracking systems 6
2.2 Overall system design and related hardware introduction 7
2.2.1 Hardware design of reset circuit 9
2.2.2 I2C communication module 10
2.2.3 Stepper motor module 14
2.3 Summary of this chapter 15
3 Software Design 17
3.1 Introduction to I2C serial communication and its software design 19
3.1.1 I2C bus design 19
3.2.2 Design of I2C bus connection devices 21
3.2 Software design of stepper motor module 27
3.3 Summary of this chapter 27
4 Conclusion 30
Reference 31
Acknowledgments 32
Appendix 33
Appendix 1: Schematic 33
Appendix 2: Procedure 34