*2.4. Embedded System*

The block diagram of the embedded system is shown in Figure 7. The heliostat orientation control is implemented in a dsPIC33EP256MU806 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 CAS60RS12A10SGG 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 grogram 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.

**Figure 7.** Block diagram of the embedded system.

**Figure 8.** Embedded system algorithm.

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.

The control algorithms are shown in Figures 9–11, for the PID controller and FLC with the CoG and Cos defuzzification methods, respectively.

**Figure 10.** Fuzzy logic controller algorithm with the center of gravity defuzzification method.

**Figure 11.** Fuzzy logic controller algorithm with the center of sums defuzzification method.

The PID controller uses the error value to obtain the control signal by using the control gains loaded from the database and Equation (7). A saturation block is used on the integral term to limit its value and obtain a faster response at changes in the error value.

The FLC algorithm obtains the value of the change of error by using the error value and a backward difference, in order to evaluate the input fuzzy sets. Afterwards, the rule base determines the output fuzzy set that corresponds to the values of the error and changes of error and combines it according to the defuzzification method in order to obtain the control signal. The CoG defuzzification method executes a loop for the number of samples that evaluates the output fuzzy sets. In each iteration of the loop, all the rules are evaluated by using another loop for the number of rules in order to obtain the maximum value of the evaluated output fuzzy sets in the sample value, as shown in Figure 5a. Finally, 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). The values of the centroid of the output fuzzy sets are calculated once at the beginning of the program and do not change.

The values of the error and integral term are saved in order to calculate the terms used in the next sample of the control algorithms. There is also a saturation block to limit the output signal of the control algorithms at the rated voltage value of the DC motors.
