## 2 Heliostat Orientation Control
### Embedded System  
The block diagram of the embedded system is shown in Figure 7. The heliostat orientation control is implemented in a dsPIC33 EP256 MU806 MCU running with a clock frequency of 48 MHz. The current date and time values are given by a real-time clock (RTC) model DS1307 with I2C (Inter-Integrated Circuit) serial interface protocol. Two H-Bridge motor drivers built with four bipolar junction transistors (tip135 and tip136) are connected to the embedded system in order to change the direction of rotation of the DC motors by using an external power supply and two control signals from the MCU for each DC motor, whereas the feedback signal of the controller is given by two single-turn absolute rotary encoders model CAS60 RS12A10 SGG with synchronous serial interface (SSI) protocol and 12 bits of resolution (4096 pulses per revolution). Both rotary encoders are connected to the axes of the heliostat in order to obtain the real position of the heliostat. The system also contains an alphanumeric LCD Display to visualize the initial controller parameters, an analog thumb joystick for the manual heliostat control, a UART block to send data to a computer to perform graphical analysis, and a programming port ICSP (In-Circuit Serial Programming). The algorithm of the embedded system was designed and developed by using CCS C Compiler software and is shown in Figure 8. All fixed values are read from a database at the start of the program. These values include the geographical position of the heliostat, distance to the target, local weather record, configuration data of the microcontroller peripherals, and parameters and program functions of the control algorithms. Afterwards, the program runs an infinite loop and waits for a start command to move the heliostat to the desired position. The program uses four 16-bit timers to generate software interrupts at fixed intervals of time in order to operate different components of the system. Timer1 generates a 200 kHz frequency square signal in order to communicate the MCU with the rotary encoders through the SSI protocol, timer2 establishes the period of the PWM signal which controls the speed and position of the DC motors by using the motor drivers, timer3 performs a software interrupt every 10 ms for the sampling time of the control algorithms, and timer4 performs a software interrupt every second in order to send the data to the UART block and read the time and date values from the RTC. Once the start command is received, the program reads the date and time values from the RTC to compute the position of the sun by using the solar position algorithm. Afterwards, the program calculates the desired position of the heliostat to determine the reference values of the control algorithm. Finally, the program calculates the value of the error between the reference values and the position of the heliostat axes which is given by the rotary encoders and determines the control signal of each DC motor by using a program function that takes the error value and returns the values of the voltage that must be supplied to each DC motor. The voltage values are converted into duty cycle values of the PWM signals, which are supplied to the motor drivers in order to move the heliostat to the desired position by adjusting the angular position of each DC motor. The position of the sun is calculated every second when the value of the RTU changes. However, the reference values of the control algorithm can be set in a fixed period without producing a significant error in the incidence of solar irradiance in the target. Therefore, the desired position of the heliostat is calculated every minute. Figure 8: Embedded system algorithm. Figure 7: Block diagram of the embedded system. all resulting values are added to obtain the output value by using Equation (8). The CoS defuzzification method only executes one loop, calculating the output value by using values of the scaled area and the centroid of each output fuzzy set, as indicated in Equation (9).