abstract - emucapstone.weebly.com€¦ · web viewabstract
TRANSCRIPT
ABSTRACT
Solar energy is a clean source of energy and available in most part of the world in abundance.
This energy however requires certain device to convert it into utilizable electrical or thermal
energy. One of these devices is the photovoltaic which converts light energy in to electrical
energy nevertheless, to do so efficiently it requires a proper tracking system which will permit it
to position itself in order to obtain the maximum possible amount of energy. In this project we
designed a microcontroller based dual axis solar tracking system, furthermore a feasibility
analysis was done to compare it with a standalone photovoltaic; result showed that by using a
dual axis tracking system over a standalone, a savings to investment ratio of 4.8 could be
achieve.
1
ACKNOWLEDGEMENTS
Firstly we would like to acknowledge the help and handful contribution of our project
supervisor Prof. Dr. Ugur Atikol who suggested this idea for a capstone team project. We would
also like to thank Assoc. Prof. Dr. Hasan Demirel from the electrical engineering who supervised
our electrical and electronic progress. Also we would like to show our gratitude to Usman
Mustafa who was of a great help when it came to the electronic circuitry. Lastly we would like to
thank Zafer Mulla, without who helped us a lot in the machining and manufacturing process.
2
Table of Contents
ABSTRACT................................................................................................................................................1
ACKNOWLEDGEMENTS.........................................................................................................................2
Table of figures............................................................................................................................................5
List of tables................................................................................................................................................6
CHAPTER 1................................................................................................................................................7
Introduction.............................................................................................................................................7
CHAPTER 2................................................................................................................................................9
RESEARCH AND DEVELOPMENT.....................................................................................................9
2.1 Photovoltaic...................................................................................................................................9
2.2 Tracking Systems...........................................................................................................................9
CHAPTER 3..............................................................................................................................................14
SOLAR TRACKING SYSTEM APPARATUS DESIGN.....................................................................14
3.1 MECHANICAL COMPONENTS DESIGN................................................................................14
3.1.1 Structural design.......................................................................................................................14
3.1.2 Motors selection.......................................................................................................................16
3.2 Electronic circuitry design...........................................................................................................18
CHAPTER 4..............................................................................................................................................21
MANUFACTURING PROCESS..........................................................................................................21
4.1 Mechanical processes and assembly............................................................................................22
4.2 Electronic circuitry arrangement..................................................................................................23
The electronic circuit arrangement can be understood from Figure 9 which provides a block diagram of the project, while Figure 10 provides a complete hardware schematic of the project....................23
CHAPTER 5..............................................................................................................................................24
EXPERIMENTAL RESULTS AND DISCUSSION.............................................................................24
CHAPTER 6..............................................................................................................................................25
ECONOMIC ANALYSIS.....................................................................................................................25
5.1 Project’s cost...............................................................................................................................25
5.2 Feasibility analysis.......................................................................................................................26
3
CHAPTER 6..............................................................................................................................................27
ETHICAL CONSIDERATION AND CONCLUSION.........................................................................27
6.1 Ethical Consideration...................................................................................................................27
6.2 Conclusion...................................................................................................................................27
References.................................................................................................................................................29
APPENDIX 1............................................................................................................................................30
ENGINEERING DRAWINGS..............................................................................................................30
APPENDIX 2............................................................................................................................................31
MOTOR DATA SHEET.......................................................................................................................31
APPENDIX 3............................................................................................................................................32
MATERIAL TEST................................................................................................................................32
APPENDIX 4............................................................................................................................................33
PROGRAM CODE...............................................................................................................................33
4
Table of figuresFigure 1 PV modules..................................................................................................................................11Figure 2The vertical rotating axis and fixed slope functional diagram, where ẞ is the panel surface slope angle.[9]....................................................................................................................................................13Figure 3 Functional diagram of the inclined rotating axis, ẞ’ is the rotating axis slope angle and ẞ is the instantaneous panel surface slope angle. [9]............................................................................................13Figure 4Two axes sun tracking system’s functional diagram.[9]................................................................14Figure 5 Structural Apparatus....................................................................................................................15Figure 6 Schematic of the control system..................................................................................................18Figure 7 Schematic of the controller.........................................................................................................20Figure 8 Flow Chart....................................................................................................................................21Figure 9 – Hardware Block Diagram..........................................................................................................24Figure 10 – Hardware Schematic Diagram.................................................................................................24
5
List of tables
Table 1 Shaft dimensions...........................................................................................................................16Table 2 price of various components.........................................................................................................25
6
CHAPTER 1
Introduction
North Cyprus (NC) is an island located in the Mediterranean Sea with coordinates 35.0000 o
N, 33.0000o E. It is characterized by its high incident annual solar radiation and high touristic
activities, especially during the summer period. These high summer activities lead to a sharp
increase in the demand of energy, which is mainly provided by the national electricity grit which
makes use of combustion of fuel oil no 6 to generate electricity. Fuel oil no 6 is a very heavy
pollutant which has been banned in many advanced countries nevertheless, NC can afford to use
a better grade oil since their economy does not permits it to, as a result the unit price of
electricity in NC is considered to be one of the highest if not the highest in Europe.
The question of “what can we do to solve this problem?” then arises. The island has been
blessed with a high annual solar availability, having more than 11 sunny months. By using this
solar energy for either domestic and/or industrial purposes, we will be able to kill 2 birds with
one stone; meaning that the load on the national electricity grit will be alleviated and the
environmental pollution will be reduced.
Many technologies exist which uses solar energy as primary energy to produce electricity,
out of these technologies the photovoltaic is by far the most popular; thanks to its popularity it is
becoming more and more feasible (reaching economy of scale) and its application in both the
industrial and domestic sectors has a bright future. However to get maximum energy from the
7
sun using these devices a proper tracking system is required which will enable the panel to be at
the best possible angle at all times throughout the year.
The purpose of this project is to design a dual axis solar tracking system which can be used for
either domestic or experimental purpose. The system will be sensor based and thus will be able
to face the sun at an angle perpendicular to the sun rays throughout the year.
8
CHAPTER 2
RESEARCH AND DEVELOPMENT
Solar energy usage’s popularity has rapidly grown over the past 3 decades, both for industrial
and domestic usage such as power generation using solar thermal systems or photovoltaic(PV),
domestic hot water production using solar collectors, solar energy for water desalination etc.
The literature contains many studies regarding the use of solar energy for electricity or heat
generation [1-7]. However the performances of these systems strongly depend on the amount of
solar energy collected, hence the need for developing a proper tracking system. In this project a
particular attention will be given to tracking systems with respect to PV.
2.1 PhotovoltaicProducing power through PV (fig 1) is a method in which solar radiation is converted into direct
current through the use of semiconductors. The birth of modern PV nowadays goes back as far as
when D. Chapin, C. Fuller, and G. Pearson at Bell Labs demonstrated solar cells based on p–n
junctions in single Si crystals with efficiencies of 5–6%[8]. At the present time a record
efficiency of up to 44.7% conversion of solar energy into electricity was set by the Fraunhofer
Institute for Solar Energy Systems ISE, Soitec, CEA-Leti and the Helmholtz Center Berlin [9].
Also due to the fact that its popularity has increased a lot during the past year, the price of a
standard PV module fell up to 0.669 $/watt in 2013, making it a suitable and feasible solution for
both domestic and industrial power generation.
9
2.2 Tracking SystemsThe presence of a solar tracker is not essential for the PV’s functioning, but rather important in
terms of amount of collected energy. Generally, solar trackers have some or all of the following
characteristics[8]:
Single column structure or of parallel console type.
One or two moving motors.
Light sensing device.
Autonomous or auxiliary energy supply.
Light following or moving according to the calendar.
Continuous or step-wise movement.
Tracking all year or all year except winter.
Orientation adjustment with/without the tilt angle adjustment.
Generally, solar trackers can be classified into 2 broad categories which are Passive (mechanical)
trackers and Active (Electrical trackers).
Figure 1 PV modules
2.2.1a Passive TrackersThey are based on thermal expansion of matter (usually Freon) or on shaped memory alloys.
Usually composed of couples of actuators working against each other and balanced by equal
10
illumination. Passive solar trackers are less complex than active ones, but on the other hand they
have a lower efficiency and stop working at lower temperatures. Although many tests have
shown that passive trackers are comparable to active ones, they are still to be accepted widely by
consumers.
2.2.1b Active TrackersMajor active trackers can be categorized as microprocessor and electro-optical sensor based, PC
controlled date and time based, auxiliary bifacial solar cell based and a combination of these
three systems. Electro-optical solar trackers are usually composed of at least one pair of anti-
parallel connected photo-resistors or PV solar cells which are, by equal intensity of illumination
of both elements, electrically balanced so that there is either no or negligible control signal on a
driving motor. In auxiliary bifacial solar cell, the bifacial solar cell senses and drives the system
to the desired position and in PC controlled date and time based; a PC calculates the sun
positions with respect to date and time with algorithms and create signals for the system
control[8]. Furthermore the motion of the tracker can be based on a sensor setup which instructs
the controller on the direction to follow.
Tracking systems can also be categorized based on the number of axis of rotation it has such
as; one axis tracker and Dual axis tracker systems, as the name implies the first type only tracks
in one direction (vertical) while the later tracks in two direction (vertical and horizontal).
2.2.2a. One axis tracking systemThere are many existing configurations of one axis tracking systems, however two of them are
widely use in industrial applications which are described as follows;
I) Vertical rotating axis
In this configuration the panel is mounted on a vertical rotating axis while its surface is inclined
according to a fix slope and sun tracking is done from east to west as shown in fig 2
11
II) Inclined rotating axis
This mechanism tracks the sun with an inclined rotating axis in which the panel surface is always
parallel to the rotating axis. Fig 3 describes the motion of this type of tracking.
Figure 2The vertical rotating axis and fixed slope functional diagram, where ẞ is the panel surface slope angle.[9]
Figure 3 Functional diagram of the inclined rotating axis, ẞ’ is the rotating axis slope angle and ẞ is the instantaneous panel surface slope angle. [9]
12
2.2.2b Two axis tracking systemIt basically has one configuration which involves to motions, which are the tilt and rotation as
shown in fig 4. The surface orientation is adjusted such that the sun is always at normal
incidence to maximize the solar beam radiation
Figure 4Two axes sun tracking system’s functional diagram.[9]
For this project the dual axis system was selected over the one axis for the following reasons;
The employment of sun tracker mechanisms contributes to considerably increasing the
photovoltaic systems performance.
Using the two-axis sun tracker system enables the PV panel collect and produce higher
amounts of electrical energy as compared to the single inclined and vertical rotating axis
sun tracker .
However, the two-axis sun tracking system presents a small additional amount of electrical
energy with respect to that produced by the different single-axis sun tracking systems. The use of
the two-axis system cannot be justified unless the amount of produced electrical energy
13
compensates for the additional equipment, related energy consumption, maintenance and
corresponding additional structure elements costs.[9]
CHAPTER 3
SOLAR TRACKING SYSTEM APPARATUS DESIGN
The system is composed of two main parts which are the mechanical and electronic control parts.
The first part consists of the structural supports and arrangements, while the second deals with
the microprocessor used for the motors’ control.
3.1 MECHANICAL COMPONENTS DESIGNThe mechanical design was based on a design suggested by [8], with some little modifications to
reduce the amount of mechanical parts and cost of the project. Fig 5 shows the final mechanical
assembly of the system. For the detail drawing of each component, you may refer to Appendix 1.
14
Figure 5 Structural Apparatus
3.1.1 Structural designThe structural components consist of 3 main parts which are the rotating shaft, the tilt shaft and,
the base for structural support. Furthermore A minimum safety factor of 4 was used since it was
a premiere for us doing such a design which involved high uncertainty.
3.1.1.1 Rotating shaftTo design the shaft a steel alloy was first tested to obtain the yield and ultimate strength of the
material (Appendix 2) then, the shaft was design using the maximum shear stress theory (1)
τ max<τ d=0.5 S y /N ……. (1)
Where τ max is the maximum shear stress, τ d is the designed stress, Sy is the material’s yield
strength and N is the safety factor.
Afterwards the diameter was gotten from equation (2).
15
τ d=FA ……. (2)
Where F is the force and A is the cross sectional area; by making A the subject of the equation
the diameter can be deduced easily. However the shaft will carry some torsional stress so testing
it under torsion was important. Equation (3) was used to test if our structure will fail under
torsion; we found that the torsional stress exceeded our design stress so a redesign based on
torsional load was done and a new diameter was obtained, which satisfied all the stresses
requirements.
τ max=Tc /J …… (3)
Where T is the torque to which the bar is subjected to, c is the radius of the shaft to its outer
surface and J is the polar moment of inertia.
An arbitrary length of 440mm was used (due to the size of the panel), and tested using Euler’s
formula to make sure our structure will not buckle the structure will not buckle.
It should be noted that these are the minimum required diameters for the structure to be safe;
however a larger diameter was used due to the material sizes available on the market. Table 3.1
shows the final dimensions of each shaft.
Table 1 Shaft dimensions
SHAFT MATERIAL LENGTH(mm) INTERNAL
DIAMETER
(mm)
EXTERNAL
DIAMETER (mm)
Rotating Steel 1040 440 12 18
Tilt Steel 1040 64 12 18
16
3.1.1.2 Base supportThe base (Appendix 1) was basically designed to carry the whole structure. It consist of 2 hollow
long square bars which serves as legs and a platform to hold the rotational motion motor and the
drivers. Equation (2) was used to design each of the legs such that they will be able to support
the structure and provide enough inertia to prevent the structure from moving when the motor
rotates. The platform was design aesthetically in such a manner that we could fit in the rotational
axis motor, drivers and the control circuits.
3.1.2 Motors selectionThe two motors used for this project are all DC stepper motors. They were use because they have
the advantage of been capable of producing high holding torques. However the rotating angle
should be as small as possible for better accuracy, for this purpose motors having 1.8o rotation
were used.
For the tilt axis the maximum torque occurs when the panel is tilted through 90 0 with respect to
the direction of the sky, the torque at that point is given by equation (4).
T=F × L …… (4)
Where F = (weight of the panel + its fixing structure + weight of tilt shaft) × (g).
L is the effective length of the shaft given by Lcosθ where, θ is the angle between the shaft and
the horizontal.
For the tilt motor;
At maximum torque θ = 0 and L = 0.064m, and F = 28N at this point the motors carry the highest
torque which is equal to 0.064(28) = 1.792 N-m.
Thus a motor which provides at least 1.8 N-m of holding torque was required, however due to
the high uncertainty of the design stage especially in estimating theoretically the weight of the
17
structure the tilt motor will carry, we used a motor listed next to the one we required in from the
online catalogue which was a 4.5 N-m rated stepper motor.
The rotating motor was selected based on two criteria;
The torque required to rotate the structure and;
The holding torque required to stop the entire structure; since when whole body moves a
significant force is required to counteract the body’s inertia.
A motor of 8.5 N-m holding torque was used for this purpose. The motor data sheet can be found
in Appendix 3.
3.2 Electronic circuitry design
3.2.1 COMPONENTS AND DESCRIPTIONOF THE CONTROL SYSTEM
18
MicrocontrollerPIC18F2550
5V
LDRs 4’’(Input)
(Output)
Motor Driver 1 Motor Driver 2
Motor2
Motor1
12V12V
Battery+12V
Figure 6 Schematic of the control system.
POWER SUPPLY: A battery of 12 volts and power of 6Watt was used to the
stepper motors
MICROCONTROLLER: The Microcontroller which was used here is
PIC18f2550.
LDR SENSOR MODULE: Was used as the main input section..
MOTOR DRIVER: Here 4x2N445 power transistors were used as drivers for the
stepper motor.
INDICATION: Simple LEDs were used for this purpose. The red LED indicates
the power supply. The green LED glows when total calculation is being carried
on by the MCU. After calculation is over, when the system stabilized in the
direction of the Sun, the green LED glows.
Figure 7 Schematic of the controller
19
The Microcontroller (PIC18f2550) has been used as the brain of the project. The way the various
connections were set up are shown in the above figure 6, four separate 2N445 transistors were
used for the stepper motor’s driver. Motor driver circuit can also be made using ULN series IC
instead the Darlington array
The algorithm of this solar tracking system is very simple and based on ‘scan and go’ (Appendix
4). At first all the values of light intensity are scanned at each point of the upper hemisphere
where the sun actually lies. While scanning, the panel will be facing the sun and direct sunrays
will fall incident on the LDR sensor which is connected to the panel .The resistance of LDR will
be changed according to the light intensities, so the voltage drop across the LDR will also be
changed. This voltage drop will be fed to an ADC, and hence a corresponding value is stored in
the MCU memory. After scanning it will check the intensity values and decide which one is the
maximum, and hence the corresponding position will be assumed by the panel, which will then
move. Fig 7 shows the flow chart of the control system.
20
Start
Collect the solar intensity values from all directions
Calculate the maximum intensity and analyses the
location
Go to the location
Check the variable
Reset all the variables
Figure 8 Flow Chart
CHAPTER 4
MANUFACTURING PROCESS
At the onset of design some basic requirements were identified in order to provide a viable, easy
to manufacture, easy to use and lasting structure. These requirements imposed on our design
required the system to be;
Able to resist corrosion under normal environmental conditions; this was done by
covering the structure with antirust paint.
The structure should have an appreciable inertia so it will be able to resist the autumn
wind load; this was achieved by manufacturing the structure such that its gravity center
could be as low as possible. In this case the base structure is the main contributor to the
body’s lowered point of gravity.
21
Function automatically; the system’s motion is governed by a sensor driven circuit and it
can thus move towards any direction where the light is most abundant.
Track the sun at all the daily sun’s positions; the system has two degree of freedoms the
rotating and tilting axis. The system will be able to move in all r and θ directions with the
exception of the direction along the rotating shaft, where the sun obviously will never be.
Autonomous; part of the energy collected from the installed PV can recharge the batteries
used so that the system is always working with minimum human attention.
The following sections will describe the detail manufacturing steps we took while building the
structure.
4.1 Mechanical processes and assemblyTo start with a platform which would serve as the interface between the PV panel and the rest of
the structure was manufactured by cutting some thin metal plates which were welded together; so
as to have a rigid but light as possible structure. This structure was then attached to the panel
with the help of 4 bolts and nuts.
Afterwards, two hollow cylindrical bars were cut to the designed lengths, one which would later
as the rotating shaft and the other as the tilt shaft. For both shafts keys and keyways were made
so as to be able to insert and lock the motors. Furthermore a supporting case for the tilt motor
was manufactured by creating a hole into a flat metal plate using the turning machine; this case
was later welded to the other end of the rotating shaft. The connection between the case and the
tilt motor was achieved by the use of bolts and nuts strong enough to support the static shear
stress due to the weight of the motor. A similar procedure was done for the rotating motor’s case
with the difference that the case was attached to the base under which the motor resides. The
22
smaller shaft was then welded unto the panels supporting structure into which the tilt motor will
be inserted. Lastly the base was completed by welding two hollow square steel ducts which
would serve as legs, perpendicularly to two steel bars which will be use to carry the electronic
components.
4.2 Electronic circuitry arrangement
The electronic circuit arrangement can be understood from Figure 9 which provides a block
diagram of the project, while Figure 10 provides a complete hardware schematic of the project.
Figure 9 – Hardware Block Diagram
23
Figure 10 – Hardware Schematic Diagram
The program used to control the motors written in C++ language may be found in appendix 4.
CHAPTER 5
EXPERIMENTAL RESULTS AND DISCUSSION
To test if our structure will run automatically and will be able to track the sun properly, the
structure was placed into a dark room and with the aid of a lamp torch; the panel was able to
follow the light effectively, covering more than a hemispherical range of angles, which is more
than enough for the structure to track the sun properly. Thus the tracking efficiency will be
dependent only on the sensors efficiency and the system will be able to reach more than 98%
tracking efficiency. It should be noted that the term tracking efficiency in this case just refers to
the degree precision with which the panel is positioned perpendicular to the sun’s incident light.
The systems productivity will be also dependent on the panel’s size and efficiency and the motor
consumption. For the system designed in this work a panel of size up to 1.1m2 (10kW rated) can
24
be used, if the system is coupled with a gear mechanism to provide the holding torque. This will
allow the system to be used at full power with optimum economical conditions.
CHAPTER 6
ECONOMIC ANALYSIS
Economic analyses are important to investigate the feasibility of a project. This might be done by
weighing the cost against the benefits of the project; however a proper economic analysis
requires a large range of data on the system’s productivity to have a proper estimate of the
project’s viability. Since in this project enough data was not recorded to give a proper and
reliable estimate, a comparison between a standalone PV and our two axis tracking system will
be carried out to give an estimate of the feasibility of our project in terms of percentages.
5.1 Project’s costTable 5.1 gives the cost of the various components used in the project and totalizes the results at
the end.
25
Table 2 price of various components
Components Price/TL
2 stepper motors 364
Structural steel components 100
Nut and bolts 6
Power transistors and other circuit components 150
PV panel 100
Total = 720
5.2 Feasibility analysis Comparing the dual axis tracking system with the standalone PV based on an optimal size
panel of 10kW over a period of 10 years the savings to investment ratio (SIR) was found to be
4.8 based on the price of electricity equal to 0.65 TL/kWh in Cyprus.
These results shows how beneficial a dual axis tracking system will be over a standalone
PV, this is due to the fact that by using a dual axis tracking system, about 57% more energy can
be obtained.
26
CHAPTER 6
ETHICAL CONSIDERATION AND CONCLUSION
6.1 Ethical ConsiderationWhile carrying out the project ethical standards based on the professional engineering code of
ethics were followed. Primary concerns such as holding paramount the health and safety of the
workers (us) and the surrounding people, avoiding plagiarism, been honest, avoiding cooking of
values and taking responsibility for each and every action we carried out were strictly followed
by the team. Also proper care was taken so as not to damage the equipments we were kindly
allowed to use. This resulted into the successful completion of the project without any teammate
or bystander getting harm or injured in the process.
6.2 Conclusion
27
In this report we talked about the design of a microcontroller based dual axis solar tracking
system, and the steps in manufacturing the various structural components and electronic
circuitry. Furthermore an analysis has been performed to size the panel, so the system would
work at an optimal performance and will be feasible. Also a feasibility analysis which consists of
comparing a standalone PV and a dual axis tracking system was done to show to show how
advantageous a tracking system would be.
This project might be a good option to produce energy for a domestic purpose in NC since
the electricity is so expensive. Furthermore considering the heavy polluting fuel oil n0 6 used by
the national electricity company, using a PV cell to produce electricity at home will be a
contribution to the environmental sustainability.
Cyprus has a lot of solar energy which can be exploited and used to cover that gap of energy
the country can’t fill, however to do so people must be more and more aware of their
environment and these existing technologies, these is why we will recommend more and more
projects to be done in this field so that more investors will be attract to it.
28
References.
1. Bakos, G.C. and C. Tsechelidou, Solar aided power generation of a 300 MW lignite fired power plant combined with line-focus parabolic trough collectors field. Renewable Energy, 2013. 60: p. 540 547.2. Eglinton, T., et al., Potential Applications of Concentrated Solar Thermal Technologies
in the Australian Minerals Processing and Extractive Metallurgical Industry. Jom, 2013. 65(12): p. 1710-1720.
3. Hirsch, T., et al., Advancements in the Field of Direct Steam Generation in Linear Solar Concentrators-A Review. Heat Transfer Engineering, 2014. 35(3): p. 258-271.
4. Spelling, J., B. Laumert, and T. Fransson, A Comparative Thermoeconomic Study of Hybrid Solar Gas-Turbine Power Plants. Journal of Engineering for Gas Turbines and Power-Transactions of the Asme, 2014. 136(1).
5. Shen, J.M., et al., Hybrid photovoltaic generation system with novel islanding detection method. Electric Power Systems Research, 2014. 106: p. 101-108.
6. Ho, W.S., et al., Electric System Cascade Analysis (ESCA): Solar PV system. International Journal of Electrical Power & Energy Systems, 2014. 54: p. 481-486.
29
7. Chen, C.L., C.E. Ho, and H.T. Yau, Performance Analysis and Optimization of a Solar Powered Stirling Engine with Heat Transfer Considerations. Energies, 2012. 5(9): p. 3573-3585.
8. Mousazadeh, H., et al., A review of principle and sun-tracking methods for maximizing solar systems output. Renewable & Sustainable Energy Reviews, 2009. 13(8): p. 1800-1818.
9. Koussa, M., et al., Measured and modelled improvement in solar energy yield from flat plate photovoltaic systems utilizing different tracking systems and under a range of environmental conditions. Applied Energy, 2011. 88(5): p. 1756-1771.
9 Fraunhofer, http://www.ise.fraunhofer.de/en/press-and-media/press-releases/presseinformationen-2013/world-record-solar-cell-with-44.7-efficiency. Information retrieved on 23 December 2013.
APPENDIX 1
ENGINEERING DRAWINGS
30
APPENDIX 2
MOTOR DATA SHEET
31
APPENDIX 3
MATERIAL TEST
32
APPENDIX 4
PROGRAM CODEunsigned char readbuff[8] absolute 0x500; // Buffers should be in USB RAM, please consult datasheet
unsigned char writebuff[8] absolute 0x540;
char txt4[7];
char txt5[7];
char txt6[7];
char txt7[7];
charcnt;
charkk;
void interrupt(){
USB_Interrupt_Proc(); // USB servicing is done inside the interrupt
}
void rot1r(void)
{
PortB=0b00000100;
delay_ms(50);
PortB=0b00001000;
delay_ms(50);
PortB=0b01000000;
delay_ms(50);
PortB=0b10000000;
33
delay_ms(50);
PortB=0b00000000;
}
void rot1l(void)
{
PortB=0b10000000;
delay_ms(50);
PortB=0b01000000;
delay_ms(50);
PortB=0b00001000;
delay_ms(50);
PortB=0b00000100;
delay_ms(50);
PortB=0b00000000;
}
void rot2r(void)
{
PortC=0b00000001;
delay_ms(50);
PortC=0b00000010;
delay_ms(50);
34
PortC=0b00000100;
delay_ms(50);
PortC=0b01000000;
delay_ms(50);
PortC=0b00000000;
}
void rot2l(void)
{
PortC=0b01000000;
delay_ms(50);
PortC=0b00000100;
delay_ms(50);
PortC=0b00000010;
delay_ms(50);
PortC=0b00000001;
delay_ms(50);
PortC=0b00000000;
}
void main(void){
// ADCON1 |= 0x0F; // Configure all ports with analog function as digital
HID_Enable(&readbuff,&writebuff);
TRISA = 0xFF;
35
TRISB = 0;
TRISc = 0;
CMCON |= 7; // Disable comparators
HID_Enable(&readbuff,&writebuff); // Enable HID communication
while(1){
while(!HID_Read())
;
IntToStr(ADC_Read(0),txt7);
for(cnt=0;cnt<8;cnt++)
writebuff[cnt]=txt7[cnt];
while(!HID_Write(&writebuff,8));
IntToStr(ADC_Read(1),txt4);
for(cnt=0;cnt<8;cnt++)
writebuff[cnt]=txt4[cnt];
while(!HID_Write(&writebuff,8));
IntToStr(ADC_Read(2),txt5);
36
for(cnt=0;cnt<8;cnt++)
writebuff[cnt]=txt5[cnt];
while(!HID_Write(&writebuff,8));
IntToStr(ADC_Read(3),txt6);
for(cnt=0;cnt<8;cnt++)
writebuff[cnt]=txt6[cnt];
while(!HID_Write(&writebuff,8));
for(cnt=0;cnt<8;cnt++)
writebuff[cnt]=" ";
while(!HID_Write(&writebuff,8));
if (ADC_Read(0)>ADC_Read(1))
{
if ((ADC_Read(0)-ADC_Read(1))>50)
{
rot1l();
}
else
PortC=0x00;
37
}
if (ADC_Read(1)>ADC_Read(0))
{
if ((ADC_Read(1)-ADC_Read(0))>50)
{
rot1r();
}
else
PortC=0x00;
}
else if (ADC_Read(1)==ADC_Read(0))
{
PortC=0x00;
}
if (ADC_Read(2)<ADC_Read(3))
{
if ((ADC_Read(3)-ADC_Read(2))>50)
{
rot2l();
}
else
PortC=0x00;
38
}
else if (ADC_Read(2)>ADC_Read(3))
{
if ((ADC_Read(2)-ADC_Read(3))>50)
{
rot2r();
}
else
PortC=0x00;
}
else if (ADC_Read(2)==ADC_Read(3))
{
PortC=0x00;
}}}
39