DESIGN (E) 314 TECHNICAL REPORT Renewable Energy Power Flow Management System Author: Kanda T May 15, 2017 Student Number: 19362846 Plagiaatverklaring / Plagiarism Declaration 1. Plagiaat is die oorneem en gebruik van die idees, materiaal en ander intellektuele eiendom van ander persone asof dit jou eie werk is. Plagiarism is the use of ideas, material and other intellectual property of another’s work and to present is as my own. 2. Ek erken dat die pleeg van plagiaat ’n strafbare oortreding is aangesien dit ’n vorm van diefstal is. I agree that plagiarism is a punishable offence because it constitutes theft. 3. Ek verstaan ook dat direkte vertalings plagiaat is. I also understand that direct translations are plagiarism. 4. Dienooreenkomstig is alle aanhalings en bydraes vanuit enige bron (ingesluit die internet) volledig verwys (erken). Ek erken dat die woordelikse aanhaal van teks sonder aanhalingstekens (selfs al word die bron volledig erken) plagiaat is. Accordingly all quotations and contributions from any source whatsoever (including the internet) have been cited fully. I understand that the reproduction of text without quotation marks (even when the source is cited) is plagiarism. 5. Ek verklaar dat die werk in hierdie skryfstuk vervat, behalwe waar anders aangedui, my eie oorspronklike werk is en dat ek dit nie vantevore in die geheel of gedeeltelik ingehandig het vir bepunting in hierdie module/werkstuk of ’n ander module/werkstuk nie. I declare that the work contained in this assignment, except where otherwise stated, is my original work and that I have not previously (in its entirety or in part) submitted it for grading in this module/assignment or another module/assignment. 19362846 Handtekening / Signature T Kanda Studentenommer / Student number 15/05/2017 Voorletters en van / Initials and surname Datum / Date 1 Summary The report discusses a renewable energy power flow management system. This system has the solar panel as the source of renewable energy. The solar panel can is either connected to the load resistor or a motor. The details of the hardware design and implementation is discussed for each hardware element. Descriptions of the main components are described with the help of circuit diagrams. These components include LCD, RL78/G13 microprocessor and temperature sense to mention a few. Software design and implementation is also discussed. All of the user-level software functions involved in implementing the operations are listed with brief descriptions. The main project file layout, as well as the flow of control of the main program, is presented The LCD is used to give a good interface between the user and the system and The RL78 microcontroller provides a good integration work space for all data and decisions made by the system. 2 Table of Contents 1 Introduction 5 2 System description 5 2.1 Main PCB System......................................................................................................................................................... 6 2.1.1 RL78/ G13 Microcontroller........................................................................................................................... 7 2.1.2 Power Supply ...................................................................................................................................................... 8 2.1.3 UART communications ................................................................................................................................. 8 2.1.4 Liquid Crystal Display....................................................................................................................................... 9 2.1.5 Temperature Sensor ..................................................................................................................................... 10 2.1.6 Switches ............................................................................................................................................................. 10 2.1.7 TLC081CP Operational Amplifier ............................................................................................................ 11 2.1.8 Push-buttons .................................................................................................................................................... 12 2.1.9 Electrically Erasable Programmable Read-Only Memory (EEPROM)...................................... 12 2.1.10 Operating modes ................................................................................................................................... 13 3 Chapter 3: Hardware design and implantation……………………………………………………………………………12 3.1 Power Supply………………………………………………………………………………………………………………..12 3.2 UART Communication……………………………………………………………………………………………………12 3.3 LCD……………………………………………………………………………………………………………………………….13 3.4 Temperature Sensor……………………………………………………………………………………………………...13 3.5 Current and Voltage Sensing…………………………………………………………………………………………..14 3.6 Switches………………………………………………………………………………………………………………………..15 3.7 Push Buttons…………………………………………………………………………………………………………………15 3.8 EEPROM………………………………………………………………………………………………………………………..16 4 Software Design ……………………………………………………………………………………………………………………….16 4.1 Main.C Functions……………………………………………………………………………………………………………16 4.2 User.c Functons………………………………………………………………………………………………………………17 4.3 Lcd.c Functions ……………………………………………………………………………………………………………...19 4.4 Project File layout…………………………………………………………………………………………………………...19 4.5 Flow Diagram of Main program control…………………………………………………………………………….21 4.6 Pheripheral setup and calibaration…………………………………………………………………………………...21 4.6.1 ADC………………………………………………………………………………………………………………………..21 4.6.2 Serial ….………………………………………………………………………………………………………………….22 4.6.3 Timers……………………………………………………………………………………………………………………22 4.6.4 Real-time Clock ……………………………………………………………………………………………………...23 4.6.5 Ports………………………………………………………………………………………………………………………23 5 Chapter 5: Measurements and Results 24 5.1 Power Supply………………………………………………………………………………………………………………….23 5.2 Push buttons…………………………………………………………………………………………………………………..24 5.3 Current and Voltage sensing……………………………………………………………………………………………24 5.4 Software program………………………………………………………………………………………………………….24 6 Conclusion………………………………………………………………………………………………………………………………25 References……………………………………………………………………………………………………………………………..25 Appendices 27 3 List of Abbreviations A/D Analogue to digital ADC Analogue to Digital Converter ASCII American Standard Code for Information Interchange BCD Binary Coded Decimal DC Direct Current I/O Input and Output LCD Liquid Crystal Display PC Personal Computer PCB Printed Circuit Board RAM Random Access Memory RTC Real Time Clock UART Universal Asynchronous Receiver/Transmitter USB Universal Serial Bus TxD Transmit Data 4 RxD Receive Data 1 Introduction An electronic renewable energy system monitor that can log power generated from both a miniature solar panel .This system manages to control the power flow among the load resistor and the motor. The RL78/G13 microprocessor was used to implement the system. The system uses the commands which are received through the USB cable from a control on a PC or from the buttons on the PCB. For the system there are two modes of operation. These modes are Normal mode and Test mode. The system runs automatically in the normal mode whilst in the test mode it waits for the PC to execute tasks .In the normal mode the load resistor is connected to the solar and when the temperature of the load resistor is high the solar automatically connects to the motor load to dump energy. In the normal mode, push buttons are used to switch between different loads. The hardware and software details are provided in the report. In addition to that, measurements from the system are given. Lastly a conclusion discussing how successful the project was is given. 2 System description This section of the report gives a detailed description on how the renewable energy monitor system is made of. The block diagram below and circuit diagrams is used to describe the operation of the whole system. It also explains how the system functions is related to the different hardware components used. For the renewable energy monitor system, the hardware components discussed are: the FT230XS UART, RL78/G13 microcontroller, LM7805 voltage regulator, Temperature sensor, PC1601-LCD, Push Buttons and the EPROM. The two operating modes of the system namely Test Mode and Normal mode are is also discussed in this section. Figure 1 shows the System Block Diagram. 5 Figure1: System Block Diagram The system blocks are shown in Error! Reference source not found., with the major components listed in Table 1. Table 1: Main components Voltage range Component RL78/G13 Stick FX230XS UART LCD Module EEPROM Temperature Sensor Voltage Regulator Push Buttons 2.1 Operating Voltage 2.0 V-5.5 V 3.3 V 5V 4.5V-5.5V 3V-5.5V 4.8V-5.2V 3V-5.5V Main PCB System The PCB has subsystems that work and coordinate with each other. The RL78/G14 acts as the main component of the system consisting of input and output devices. Figure 2 show the PCB System with hardware components 6 Figure 2: Main PCB System with hardware components 2.1.1 RL78/ G13 Microcontroller The RL78/G13 processor from Renesas was used as the microcontroller of the system .As the main brain of the system the RL78/G13 processor has the inputs and outputs components connected to it.Renesas is currently the volume leader and the RL78/G13 processor is chosen for this type of application because it is a fast complex instruction-set 16 bit with modern lowpower feature and good support. This processor also incorporates a R5F100LE processor (64pin with 64kB ROM Flash (program), 4kB Data Flash, 4kB RAM) and a hardware debugger tool. It is very conveniently available in a low-cost promotion board with most of the I/O pins exposed in two 30-pin header pins, thus also meeting the idea of a lower-pin count with optimal amount of memory production hence suitable for the project. When mounted on the PCB, the microcontroller chip uses 5V provided by the power supply. The controller uses an external micro USB connected to the PC to program the device and for the debug purposes. The 7 Figure 3: RL78/G13 Microcontroller Rails and Peripherals 2.1.2 Power Supply The RL78/G13 microcontroller require a constant 5V supply. Thea LM7805 linear voltage regulator is used to provide the constant voltage and to tolerate large peaks. The regulator and all the regulated circuitry are protected from the reverse power connection by an extra 1N4007 protection diode which is in the power supply channel system. A 100Nf capacitor was connected at the output for improved stability and transient response and also a 10Nf capacitor was connected at the input to decrease the impedance from the source The power supply will also provide a stable regulated +5V to the LCD display. The LM7805 regulator will output a typical of +5V from an Input voltage of +7V to +20V and the output minimum and maximum voltage being +4.8V and +5.2V respectively. Despite ensuring operation for the system the voltage regulator acts as a safety mechanism since excess voltages can blow up the components .It outputs a current of 5Ma which is very safe for other components in the system. Figure 4: Power supply and the Voltage regulator LM7805 to the system. 2.1.3 UART communications 8 Communication between the electronic renewable energy system monitor and the PC is needed. The UART interface is added so debugging can still be done while communications to PC uses separate UART port. The selected device for UART interface is the FTDI FT230XS IC. It provides full UART functionality access from a PC USB port. Since the USB is not always at the ground, large resistor values (1Mega ohm) are used to remove static voltage and small capacitors (47pF) are used to filter out noise signals in transmission and reception processes. 100Nf capacitors are also used to stabilize the voltage for continuously changing signals The UART communication is based on asynchronous bi-directional communication at moderate speeds of 110 – 115200 baud. Since we operate over very short distances to the USB translator, The UART port is set to 34800 baud in this design. The FTDI FT230XS has an integrated level of +3.3V, however its logic inputs are 5V compatible hence the RxD input will not be affected at 5V. Since VOH maximum for the FTDI FT230XS does not comply with the R5F100LE VIH minimum in normal mode the TTL option for the RxD channel was chosen for this project. Figure 5: shows the USB to UART translator. Modified version of diagram in Practical 2 2.1.4 Liquid Crystal Display The LCD screen acts as a device for displaying input signals as characters on a screen and this provides a reliable interface between the user and the system. The LCD is used for displaying switch states, real time date and any other messages which should be displayed. A low cost 8 character x 2 line type display PC1601A LCD module with a choice of a 4-bit nibble or 8-bit byte-orientated parallel interface is used. The LCD module is connected to the microcontroller using 4 data lines DB4-DB7 whereas lines DB0-DB3 are grounded. It contains three control bits Register Enable (E), Read-Not-Write (R/W) and Select (RS. In the setup, the LCD is initially initialized to the 4-bit mode operation. Writing on the LCD occurs when both RS and R/W equal 0. Reading from microcontroller occurs when R/W and RS equal 1.For both commands Enable must be equal to 1. For the LCD contrast a potential divider was used. Beside its low cost the LCD’s operating voltage ranges from 2.7 to 5 V and this makes it suitable for the project system. 9 Figure 6: LCD Circuit diagram. Modified version of diagram in Practical 2 2.1.5 Temperature Sensor The LMT01-Q1 is a high-accuracy 2 pin temperature sensor provides a digital output in the form of a pulse count that is transmitted by a train of current pulses. When it is powered up it will transmit a very low current for less than 54ms while the part executes a temperature to digital conversion. The temperature sensor is attached to the load resistor so as to measure the temperature of the load resistor. This is done so as to ensure that the temperature of the load resistor stay in the required region. The temperature sensor then transmit a series of pulses equivalent to the pulse count at a given temperature. The total time for temperature to digital conversion and the pulse train time interval is 104ms.The pulse train keeps on repeating itself if power is applied periodically .The temperate sensor will output at minimum 1 pulse and a theoretical maximum of 4905 pulses. Each pulse has a weight of 0.0625β°C with 1 pulse corresponding to a temperature less than -50β°C. Figure 4 shows how the pulse diagram and how the temperature sensor is connected to the microcontroller. . Figure 7: Pulse diagram and LMT01-Q1 2-pin Temp sensor. 2.1.6 Switches The only required source of power in this project was the solar panel as per the project specification requirements. This source of power either drives the load resister as a primary load or switches on the drive to the motor just as the load the load resistor becomes too hot. For this power flow management to be fluent 3 digital switches were implemented by using 3 10 2N700 MOSFETs and a 2 HRS1KH-S Relays.This MOSFET, which has a rated current of 200mA was used because it has fast switching times, improved inductive ruggedness, lower input capacitance, extended safe operating area and improved high temperature reliability. The relay driver was also used since it can handle the 5V supplied to the boards for electromagnetic switching. Electrical isolation is also provided by the fly-back diode which is in the relay circuit. MOFSET switches were used to supply a driving current to the relay thereby enabling the microcontroller to connect the solar panel to the motor or load resistor. The MOSFET was not used as a direct short circuit switch as they are easily blown off if too much current flows through. Figure 8a: MOSFET 2N700 Figure 8b: HRS1KH Relay driver circuit 2.1.7 TLC081CP Operational Amplifier Current sensing circuits to measure the solar panel short circuit current, and current supplied from the solar panel to the loads were build using the TLC081CP Operational Amplifier. The low side current sensing was used to measure current flowing to the ground through small sense resistor (RSENSE). The low-side current sense circuit in figure 6 is used because voltage drop is easy to measure since it is with respect to ground. To implement this, voltage (VSENSE ) drop across the current sense resistor is measured and then Ohms law(VSENSE = ISENSE RSENSE) is used to calculate ISENSE. VSENSE is then amplified to an analogue VADC value by making use of Rf the gain of the amplifier according to the amplifier equation Vadc = Vsense ∗ (1 + R2), whereby RF is the feedback resistor and R2 . The voltage is amplified so as to provide a signal with suitable range for the RL78 analog-to-digital converter ADC. The supply voltage and current required by the op amp is 4.5V and 57mA therefore making it is suitable for the project. 11 TLC0 81CP R L78/ G13 Figure 9: TLC081CP Operational Amplifier. Modified version in Lecture 6. 2.1.8 Push-buttons The push buttons were added to the system for user interaction with the microcontroller. The buttons inputs to the microcontroller have the pull resistors and when pressed they connect to the ground. The user control comprises of 4 buttons with different functionalities depending in the type of mode you will be in Test mode or Normal mode.When the system is running in Test mode the buttons are used to switch the states and when in the Normal mode the buttons are used to adjust date, time and to test the solar panel. The figure below shows the buttons added to the system. Figure 10: Push Buttons 2.1.9 Electrically Erasable Programmable Read-Only Memory (EEPROM) The system monitor must be able to log information about the power generated prior to the project specification. To implement this an external storage for log data, a 64kbit (8192 x 8bit) 25LC640 8-pin DIP microchip, was connected to the RL78. . The microchip has a 3-wire interface with SI, SO and SCK being the interfaces signals. SCK is used as a clock input at 1MHz, SI is used as separate data in line and SO is used as separate data out line. The operating voltage of the microchip is 4.5-5.5V and also it uses low-power CMOS technology thus making 12 it suitable for the project .It has a write current of 3mA and a read current of 500µA both which are within the board limits hence making it suitable for the project. The RL78 only controlled the not CS pin to enable/disable the microchip. The voltage and temperature measurement, current switch state, current date/time, load current measurement and calibrated temperature values are logged onto the EEPROM every second. This is possible since the microchip has 5ms max write cycle time. This logged information can be taken from the EEPROM via the UART to the PC. Figure 11: 25LC640 8-pin DIP microchip 2.1.10 Operating modes Two operating modes namely normal mode and test mode were used for the system. The system runs a certain task automatically in normal mode and this is the start-up mode of the system. In this mode the controller execute a programmable schedule as well as a logic on which state to execute. A certain range of temperature is calibrated so at to control the load temperature. This temperature is sampled at certain intervals of time by the RL78.Either the load resistor or the motor load is driven by the solar depending on the temperature. The sequence goes this way, while the temperature reaches a specified maximum value the controller independently switches the solar panel to drive the only the motor thereby allowing the load resistor to cool. When the temperature reaches a minimum value the microcontroller switches the solar panel to drive the load resistor. The voltage and temperature measurement, current switch state, current date/time, load current measurement and calibrated temperature values are logged onto the EEPROM ever second. In this normal mode, push buttons are also used to perform solar panel test and the setting of the real time clock. For the second mode, Test mode, the system waits for certain commands from the PC so as to execute certain tasks such as reading and writing from the EEPROM. In this mode buttons are used to go through different switch states. Each time the new state switch is displayed on the LCD. 3 Chapter 3: Hardware design and implantation In the design of the system, many design choices had to be made. This was done so that all hardware components meet their perspective tasks. This chapter explains the choices of the components used in the entire system together with their calculated values. It also gives a 13 detailed description of the of the system design with motivation on the design choices and assumptions made. 3.1 Power supply A suitable power supply was designed to provide an output of +5V for the microcontroller and display (LCD). From the datasheets: LM7805 Input voltage Vin (min) = 7 V 1N4007 Forward voltage Vd1 (max) ≈ 0.8 V Since the LM7805 requires at least 7V and the forward voltage is 0.8V.The total voltage for needed for the input is now 7.8V.It is know that standard batteries have 6V, 9V AND 12V output voltage. So as not to drain the supply voltage I chose my input voltage to be ≥9.8V.Considering the worst case scenario I designed for an input voltage range of 12 ≤Vinput≥ 10v at a current of 0.24A at max. From the datasheet of the LM7805 voltage regulator C3 = 100nF, C2 = 10Nf.The output capacitance improve stability and the input capacitance helps to reduce the source impedance. Figure 12: Power supply circuit 3.2 UART communications The UART TxD and RxD lines provides the channel of data transmission to and from the microcontroller. They are connected to the ports P04 and p03 and current flow through this ports. The maximum current that flows through the ports is 20mA as from the RL78 data sheet. To avoid any excess dead parasitic current I designed for resistors which I connected between the TxD and RxD ports of the FT230XS UART and the RL78 G13 microcontroller. 14 Figure 12: Representative circuit diagram of connection between FT230X and R5F104LE Since the input voltage is 5V and the max current is 20mA. Applying Ohms law the ππ·π· 5 minimum resistance is: Rmin = πΌπππ₯ = 0.02 = 250β¦ R1 and R2 was chosen to be 1000β¦ to make sure that a maximum current of 5mA, which is extremely below 20mA, can flow through. 3.3 Liquid Crystal Display (LCD) For the LCD contrast, a resistor is used in the LCD potential divider to limit the amount of current. The resistors R1 and R2 in the schematic diagram below affect the contrast of the LCD.R1 was set to 18kβ¦.Since this 2 resistors form a potentiometer, I adjusted R2 until I observed a satisfactory contrast on the LCD.A 800β¦ Figure 13: Section of LCD circuit 3.4 Temperature sensor In the RL78 datasheet using the TTL Vin max is 0.8V and Vmin is 2.2V,and also from the LMT01 datasheet the values for the typical temperature sensor I(Low) is 34µA and the value for I(inmax 0)is 125 µA. From Ohms law (V = IR): The approximate minimum value of the resistor to be used to convert pulses from the temperature sense can be calculated. πππ Rminimum = πΌππππ€ = 0.8V/34µA = 17600β¦ 15 Rmaximum = ππβππβ πΌπβππβ = 2.2V/125µA = 23500β¦ I then chose a resistor value of 22k β¦ which is in between the range 17 000 < R < 23 500 The resistor value also met the condition of Vn > 3V, since 125µA*22k β¦= 2.75v 3.5 Current and voltage sensing Rsense, the current sense resistor, was designed to have a low resistance value as possible so the current through this resistor be almost equal to the current which has to be measured. A design constraint that the power rating of 0.25W of the resistors available should be not exceeded. Since Pmax= Imax2Rmax 0.25 Rmax = 0.25 = 1β¦ Since the 1β¦ resistors had high variability of +0.5 β¦. Or -0.5 β¦ when measured in the lab, I did choose to connect 1.2 β¦ resistors in parallel to yield an equivalent resistance of 0.6 β¦ This low resistor value ensured that a lower current flows through each resistor hence not exceeding its maximum wattage required. Gain: For Motor Op Amp: This maximum measured value for the motor current 560mA . Vsense = 0.56 x 0.6 = 0.336V For worst case scenario for Vadc = 5.2V and π π Vadc = Vsense x (1 + π 2) I calculated π π π 2 as shown below π π Vadc = Vsense x (1 + π 2) 5 = 0.336 x (1 + π π π 2 π π π 2 ) =14 I then chose Rf = 14kβ¦ and R2 = 1kβ¦ My design held since for both the op amps saturation did not occur during measurements. Gain: Load Resistor op amp: This maximum measured value for load resistor current was found to be 0.45A. I used a Rsense = 0.6β¦ Vsense = 0.45 x 0.6 16 = 0.27V For worst case scenario Vadc = 5.2 V and π π Vadc = Vsense x (1 + π 2) π π π 2 was calculated as shown below π π Vadc = Vsense x (1 + π 2) 5 π π π 2 π π = 0.27(1 + π 2 ) = 18.5 I then went on to choose Rf = 20kβ¦ and R2 = 1kβ¦ 3.6 Switches Figure 13b: MOSFET switch Vgate = 2.2V From the MOSFET data sheet. Using nodal analysis at the gate node (Vgate – Vinput)/ Rin + Vg/Rgs =0 (2.2-5) /Rin + 2.2/Rgs = 0 2.2/Rgs = 2.8/Rin Rin = 1.272Rgs Resistor values chosen Rin = 13kβ¦ Rgs = 1kβ¦ Used in all the 3 circuits to ensure switching. 17 3.7 Push Buttons As shown in the figure below, I designed for pull up resistors. When the button is pressed, the input is made low thefore Vin<Vmax, and the button is not pressed, the input pin is made high there Vin >Vmin. From the RL78 datasheet R3 is 100k β¦ Figure 14: Schematic circuit for Push buttons 3.8 EEPROM A designed for a decoupling capacitor, small 10nF, between Vcc and ground near the EEPROM to make sure that all the high frequency noise from the power supply is filtered off and won’t affect the stored information in the EEPROM. 4 Software Design 4.1 Main.C Functions void main (void) This function implements the main function. The initializing function, R_MAIN_UserInit(), is called in the main. This is followed by an infinite while loop which calls the functions responsible for the reaction of the flags of the UART which in-turn stimulates the communication of our system with the PC. It also calls functions which start the timers for a number of channels and also functions which setup certain flags for other different commands. The functions serviceUart(),SCROLLONGTEXT(lcd_bufter),initLcd(), writeString(show),R_TAU0_Channel1_Stop() and R_TAU0_Channel1_Start() are also called in the infinite while loop. 18 void main(void) { R_MAIN_UserInit (); /* Start user code. Do not edit comment generated here */ R_TAU0_Create (); R_TAU0_Channel2_Start (); //Create and initialize the UART States_C=0; State_N = 11; int tcout=0; R_UART1_Create (); R_UART1_Start (); R_RTC_Creat e(); R_RTC_Start (); R_IT_Create (); R_IT_Start (); uart1Status = R_UART1_Receive (&uart1RxBuf[0], 1); initLcd(); } while (1U) { In the main function this is where the Test mode or the Normal mode are executed. This modes are executed when their flags are set to high. The software for activating the buttons is also in the while loop of main function void R_MAIN_UserInit(void) This function calls the timer initializing function, real time clock, and the LCD initialize and communication channels. void UartSend(void) The function writes out information from the UART0.The function wait for the lag to be set high and this happens after all information is send from the UART then is can continue 4.2 User.c Functions void serviceUart (void) This function is continuously called in the while loop which is in the void main (void) function. It stores the data in the command of the UART0 after receiving it. The function executes through only if there are available bytes from the UART. A This bytes are then loaded to an array. void UartSend(void) The function writes out information from the UART0 . The function wait for the flag to be set high, thus after all the information is send from the UART then it can continue. void INSTRUCT(void) 19 This function uses a switch statement to implement the state machine. The switch statement switches the menu to the Test mode as well as the Normal mode depending on the commands from the user.The different cases with different functions are case '0' : go to normal mode case '1' : go to test mode case '2' : load the LCD with certain characters case '3' : load the student number case 'D' : display message loaded into the LCD case 'E': display measured values of voltage or current case 'I': show the temperature case 'C': return the present time case 'N': temperature turn on or off default: invalid command or does not exist. void Mode toNormal(void) This functions sets the normal mode flag to 1 and puts the system in the normal mode by transmitting (0x00) to the PC. void Mode toTest(void) This functions sets the test mode flag to 1 and puts the system in the test mode by transmitting (0x10) to the PC. void INVALID_PARAM(void) This function transmit an invalid message back to the PC when an invalid character is transmitted to the system void WELCOME_TEXT(void) This function sends a welcoming message to the PC when the system is powered up void SOLAR_toSWITCH(void) This function uses a switch statement to set the switch states. Depending on which state the system is in, the solar connects either to the load resistor or to the motor. If the solar is not connected to any of this it is short circuited. This is all implemented in the SOLAR toSWITCH function by setting the flags of the motor and load resistor. The function short circuits the solar panel by assigning the port 43 of the RL78 to 1.It also connects the solar panel to the motor by assigning the RL78 port 42 to 1 whilst port 41 and port 43 are assigned to zero. The solar panel is connected to the load resistor by assigning the port 41 to 1 whilst pots 42 and 43 are assigned to 0. All switches are opened by assigning all the 3 ports of the RL78 to 0. void R_ADC_Get_Result(uint8_t * const storeAdc) This function shift the conversion result, ADCR, to the right by 6 (*buffer = (uint16_t) (ADCR >> 6U) and write this value address of the variable which is sent to it. It then gets the digital output value after the ADC conversion. void Measure(void) This function first calls the functions R_ADC_Create () and R_ADC_Start () which initializes and start the AD convetor. It then calls the function R_ADC_Get_Result_8bit(&measuredvalue) which returns the higher 8 bits conversion result of the measured value and writes it in the address of measured value. The function is called a multiple number of times and it returns different values which are then averaged to get an accurate value. 20 void TEMP_GOT(void) This function gets the value of the pulses of the temperature sensor and then converts this pulse to a decimal value of the temperature in degree Celsius. In this function the 2 channels, R_TAU0_Channel1_Start()and R_TAU0_Channel1_Start(), are started. This pulse counted are store in variable KAY. This pulses are then used to calculate the temperature value in degree ππΆ Celsius according to the formula in LMT01-Q1 data sheet, Temp = (4096 × 256) − 50β , where PC is the pulse count and Temp is the temperature reading. void TEMPOF_ON(void) This function sends the measured valued of the temperature to the UART. uint8_t DECIMALToBCD(uint8_t DECvalue) This function is used to change the decimal value sent to it to a BCD value. It’s done by left shifting the decimal value by 4 and then bitwise OR the result with the units value of the decimal value: BCDValue = ((DECvalue/10)<<4) | (DECvalue%10) uint8_t bcdToDecimal (uint8_t BCDvalue) This function is used to change BCD value sent to it to an integer value. It’s done by right shifting the upper nibble value of the BCD value by 4 and then adding the result with the lower nibble value of the BCD value: DECvalue= (upperNibble >> 4) + lowerNibble. void PrintMeasure(void) This function calls the function Measure().It gets the measured values of voltage, solar current and load current. It the sends this values to microcontroller and then stored in certain registers. void returnTimem (rtc_counter_value_t current time) This function receives a struct containing bytes received from the PC .It then checks if the last 5 bytes shows a valid time and date. If the bytes are valid, the specified time is then converted to BCD format and then get set to the RTC using the generated R_RTC_Set_CounterValue() function. void Auto_Switch(void) This function checks if the temperature is low or high. If the temperature is high it automatically switches on the motor by connecting the solar panel to the motor and if the temperature is low it automatically connects the solar panel to load resistor. 4.3 Lcd.c Functions void writeByteLcd(uint8_t reg,uint8_t value) This function writes 2 nibbles to the LCD. reg (BOOL) 0 = register, 1 = data value(BYTE) -first the upper 4 bits then 4 lower bits void writeNibbleLcd(uint8_t reg,uint8_t nibble) This function writes a nibble to the LCD. reg (BOOL) 0 = register, 1 = data nibble(BYTE) -first the upper 4 bits then 4 lower bits void initLcd(void) 21 This function initializes the LCD. It also calls a function CLEARLCD which clears the LCD screen. void delayNoInt(uint16 t delay) void startTMR0(int delay) These 2 functions are from the lecture slides. They are used to implement a delay in microseconds. The first function uses this timer to cause delay in operations and the second function starts the timer. void DisplaySTRING(uint8_*TkAY) This function displays an array of characters on the LCD. If the characters become greater than 16 the function RIGHTSHIFT(Tkay) is called. This function shifts the characters on the LCD to the right at a rate of 500ms and displays them. This implements scrolling. 4.4 Project File Layout Globvalues.c iodefine_ext.h iodefine.h r_cg_cgc.h r_cg_intc_user.c r_cg_intc.c r_cg_intc.h r_cg_interrupt_handlers.h r_cg_macrodriver.h r_cg_pclbuz_user.c lcd.c lcd.h r_cg_adc_user.c r_cg_adc.c r_cg_adc.h r_cg_cgc_user.c r_cg_cgc.c r_cg_port_user.c r_cg_serial_user.c r_cg_serial.c r_cg_serial.h r_cg_timer_user.c r_cg_timer.c user.c user.h r_cg_timer.h r_cg_port.c r_cg_port.h r_cg_rtc_user.c r_cg_rtc.c r_cg_rtc.h r_cg_userdefine.h r_cg_vector_table.c r_hardware_setup.c 22 r_main.c r_reset_program.asm 4.5 Flow Diagram of Main program control 23 4.6 Peripheral setup and calibration The RL78 set up peripherals for successful implementation of the project are as follows. 4.6.1 ADC The reference voltage of the A/D convertor was set to Vcc = 5V while the minimum reference was 0V.Its resolution was set to 8bits.The ADC will only get changed by the software since the software trigger mode was selected.3 inputs which are analog were selected and all of them being continuous select mode. For the conversions the following formula was used. π·ππππ‘ππ πππ = π΄πππππ πππ × πππ 28 4.6.2 Serial Channel 0 and channel 2 were used.CS100 was selected for channel 1 whilist for channel 2 UART1 was selected. This channels were both set to Transmit and Receive. For the UART1 it was set to receive data of 8bits long with no parity bit. The baudrate was set to 38400bps. This was the specification of the design. For the CS100 the baudrate was to be 100kbps and the internal clock was set to clock mode. 4.6.3 Timers Two timers’ namely External timer and Interval timer were set up. The project protocol specification required the system to be respond quickly. For channel 0, the interval timer was set to run for 20ms.This means that an interrupt is generated after every 20ms.This interval timer was used for the LCD scrolling. As per project specification the LCD was supposed to scroll at a rate of 500ms per character. External event counter was set to operate at 16 bits and max frequency of 500MHZ. The external event counter was set to start at a count value of 4094. After a falling edge is detected this count value decrements and is stored in the TCR01 register. A count value of 4094 was chosen since the maximum number of pulses generated by the temperature sensor is 4095.The temperature sensor used the interval timer as well as the external counter. 4.6.4 Real-time Clock An interrupt for the real time clock was set to generate every second .The real time clock was set up to be used in the 24 hour system. 4.6.5 Ports All the inputs and outputs pins used on the RL78 stick where selected on the ports peripherals and then generated. 5 Chapter 5: Measurements and Results In order to assess the accuracy of the completed systems, measurements were taken from the system and this were listed below. The system is fully operational with the exception of the EEPROM. 24 5.1 Power Supply Input voltage(v) Output Voltage(v) 7 10 12 26 5.2 5.2 5.3 6.3 Table 2: Power supply Figure 15: Power supply output The measured values for the power supply shows that a constant supply of 5.2V to the system is maintained. The voltage regulator only outputs a constant voltage of 5.2V when an input voltage of 7V to 20V is supplied from a DC source 5.2 Push buttons Figure 16: Lcd Voltage Voltage for Push buttons = 5.4V when pressed and aprox 0V when not pressed. 5.3 Current and voltage sensing Current from the load = 0.45 Amp Current from the Motor = 0.56 Amp 5.4 Software program The program software use the memory shown in figure 17 25 Figure 17: Memory used 6 Conclusions The goal of the design was to create an electronic renewable energy monitor that can log power generated from miniature solar panel. The final system was fully operational (excluding the EEPROM).This was because of failing to implement the software for EEPROM. The user can however be able to navigate through the menu using the push buttons. The system can control the amount of power through the load resistor by sensing the temperature of the load resistor at a time interval. The system will automatically connects to the motor when the wattage of the load resistor is being exceeded (temperature becomes too high). The communication through the USB responded correctly to the commands requested by the user. The system also displays relevant information to the user as per speciation for the project. However the gains of 20(for load) and 14(for motor) which were used to amplify the voltage and current values of the solar panel, load and motor needs to be improved since, at the end, the system failed to produce the ADC values in the required range as per protocol specification. References [1] J. M. Alexander G.Dean, Creating Fast, Responsive and Energy-Efficient Embedded Systems using the Renesas RL78 Mirocontroller, Weston: Micrium Press, 2012. [2] Renesas, "RL78/G14 Datasheet - Renesas Electronics," 05 January 2015. [Online]. Available: http://documentation.renesas.com/doc/products/mpumcu/doc/rl78/r01ds0053ej03 20_rl78g13.pdf. [Accessed 14 May 2017]. [3] LMT01-Q1 0.5°C Accurate 2-Pin Digital Output Temperature Sensor with Pulse Count Interface, LMT01-Q1 datasheet, Texas Instruments, Nov. 2017, [4] FT230X USB to Basic UART IC, FT230X Datasheet, Future Technology Devices International Ltd, 2016. [5] HITACHI, "HITACHI, Ltd Semiconductor and Integrated Circuits," 1998. [Online]. Available: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf. [Accessed 8 May 2017]. 26 [6] A. Barnard and L. Visagie , "Design (E) 314 Lectures," Stellenbosch, 2017. [7] "Diodes Incorporated 1N4001," [Online]. Available: www.diodes.com/_files/datasheets/ds28002.pdf. [Accessed 11 May 2016]. [8] R. MCU, "RL78/G13," 2013. [Online]. Available: http://www.renesas.eu/products/mpumcu/rl78/rl78g1x/rl78g12/app_notes.jsp. [Accessed 12 May 2017]. Appendices Appendix A Complete Schematic 27 Appendix B Technical specification Power Supply: Main PCB: 9-12V, 0.18 -0.36mA External Connections Solar panel USB cable DC power supply 28 LCD display Screen width: 16 characters Strings longer than 16 characters scroll to the left at a rate of 500ms character/s until complete Appendix C Circuit Diagrams and Tables RL78 Pins Used and their Configuration Project function RL78 R5F100LE - 64 pin device RPB UART Function UART2 RX UART2 TX Port P13 P14 Type IN OUT Pin 43 42 FT230XS UART UART1 RX P03 IN, TTL 61 J2-8 UART1 TX P02 OUT 62 J2-7 D0/4 P74 OUT, (IN) 25 J1-25 D1/5 P75 OUT, (IN) 24 J1-24 D2/6 D3/7 E R/W RS P76 P77 P72 P71 P70 OUT, (IN) OUT, (IN) OUT OUT OUT 23 22 27 28 29 J1-23 J1-22 J1-27 J1-28 J1-29 Enable P41 OUT 4 J2-23 Voltage P20 IN/ANA 56 J2-11 Current P21 IN/ANA 55 J2-12 Motor(2nd Load) Enable P42 OUT 3 J2-22 Short circuit Voltage Current Enable P22 P23 P43 IN/ANA IN/ANA OUT 54 53 2 J2-13 J2-14 J2-21 LCD Solar 29 PCB Pin J1, J2 J1-6 J1-7 Power supply Microcontroller module Lcd Interface 30 Temperature sensor Current and Voltage sensing Push Buttons 31 EEPROM Voltage Regulator 32