Previous in Forum: Sonar High Frequency Piezoelectric Device   Next in Forum: Low Voltage Wiring
Close
Close
Close
21 comments
Rate Comments: Nested
Member

Join Date: Feb 2010
Posts: 7

Help Needed with Solar Tracking Program

02/18/2010 12:26 AM

Hi all of you..

I am doing a project on solar tracker. For this I am using 2 photo transistors on either side of the solar panel. The light intensity falling on the photo transistors are given to ADC and then given to micro controller (AT89S52). The program has to compare the values of the photo transistors and then depending upon this the micro controller will control the stepper motor's movement to either clockwise or anti- clockwise. The motor has to stop in case if both the values are equal.

Heres the program i have written, but its kinda not working. Also i need to check for the photo transistors values for every 15 minutes. And the motor has to rotate only once and stop, I mean for a particular degree of rotation. So if you could please check it and let me know, it would be of great help.. Thank you...




#include <reg51.h>
sbit READ_1 = P0^0;
sbit WRITE_1 = P0^1;
sbit INTR_1 = P0^2;
sbit READ_2 = P0^4;
sbit WRITE_2 = P0^5;
sbit INTR_2 = P0^6;
#define MYDATA_1 P1
#define MYDATA_2 P3
#define Stepper_motor P2
void main(void)
{
unsigned char value_1,value_2;
MYDATA_1 = 0xFF;
MYDATA_2 = 0xFF;
INTR_1 = 1;
INTR_2 = 1;
READ_1 = 1;
READ_2 = 1;
WRITE_1 = 1;
WRITE_2= 1;
while(1)
{
WRITE_1 = 0;
WRITE_2 = 0;
WRITE_1 = 1;
WRITE_2 = 1;
while(INTR_1 == 1);
while(INTR_2 == 1);
READ_1 = 0;
READ_2 = 0;
value_1 = MYDATA_1;
value_2 = MYDATA_2;
if ( value_1 == value_2 )
{
Stepper_motor = 0;
}
else if ( value_1 < value_2 )
{
stepper = 0x0C;
delay();
stepper = 0x06;
delay();
stepper = 0x03;
delay();
stepper = 0x09;
delay();
}
else if
{
stepper = 0x09;
delay();
stepper = 0x03;
delay();
stepper = 0x06;
delay();
stepper = 0x0C;
delay();
}

READ_1 = 1;
READ_2 = 1;
}
}



With Regards,
Thank you.

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.

Good Answers:

These comments received enough positive votes to make them "good answers".

"Almost" Good Answers:

Check out these comments that don't yet have enough votes to be "official" good answers and, if you agree with them, vote them!
3
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#1

Re: hi help me out here please///

02/18/2010 4:18 AM

It is difficult enough to work out how one's own software works even when it is thoroughly annotated.
To figure out how someone else's works when it is not annotated is frustrating to say the least.
A casual glance at it makes me feel it is overcomplex.
I would suggest simplifying down to very basic steps and testing it a step at a time.

A flow chart is a good place to start.

I daresay we all write uncommented code, without flowcharts and sensble planning, but then we have to debug it ourselves.
Del

PS. A simple example. If the phototransistor outputs are A and B

If A>B then pulse the motor towards A.
If B>A then pulse the motor towards B
Just repeat this process in a loop, once that works you can build up sophistication for cases where say A abd B are both low.

__________________
health warning: These posts may contain traces of nut.
Register to Reply Good Answer (Score 3)
Guru
Popular Science - Weaponology - New Member Safety - ESD - New Member Hobbies - Fishing - New Member

Join Date: Sep 2006
Location: Near Frankfurt am Main, Germany. 50.390866N, 8.884827E
Posts: 17996
Good Answers: 200
#14
In reply to #1

Re: hi help me out here please///

02/19/2010 9:28 AM

GA for a truly "good" comment.

__________________
"What others say about you reveals more about them, than it does you." Anon.
Register to Reply
3
Guru

Join Date: Jul 2008
Posts: 1688
Good Answers: 145
#2

Re: hi help me out here please///

02/18/2010 6:19 AM

If the block diagram and flowchart don't work then the code probably won't work either.

If you don't have a block diagram and flowchart that seem to work then you should not be writing code yet.

Those of us that have been around for a few years have heard just about every reason why someone does not need to take the time to make a flowchart and block diagram. We hear the reasons every time someone wants help to make something work that is "so easy I don't need to do the planning". Do you see a pattern here?

Making a block diagram and flow chart helps you get it right and it helps you when you ask for help.

__________________
Few things limit our potential as much as knowing answers and setting aside questions.
Register to Reply Good Answer (Score 3)
Member

Join Date: Feb 2010
Posts: 7
#3
In reply to #2

Re: hi help me out here please///

02/18/2010 12:47 PM

Thanks for relpy...

here is the flowchart...

With Regards,

Thank you..

Register to Reply
3
Guru

Join Date: Aug 2006
Posts: 4484
Good Answers: 246
#19
In reply to #3

Re: hi help me out here please///

02/19/2010 12:54 PM

Things to consider:

- Updating the position more frequently would make sense, both for debugging and in actual operation.

- Unless you are certain that one motor step is adequate to advance the motor slightly more than enough for 15 minutes earth rotation (roughly 4 degrees), it would be possible that the panel would never "catch up" with apparent sun position.

- If the phototransistors are simply mounted one on each side of the panel, they will receive the same amount of light all the time (other than when clouds pass over). Am I right in assuming that you have something to put one or the other in shadow (side-by-side with a card in between), or that you have angled them substantially out of parallel?

- I think you would be wise to add some hysteresis, as someone else mentioned (e.g., check transistor values several times and average them, and then move, rather than checking once and then moving.) Otherwise, a passing cloud could cause the panel to seek to the wrong direction (and with the code as written, the panel might never catch up).

- Once this is operation (and assuming it is in a fixed location) then you could have the system "learn" the position of the sun, and update a positioning array that would be followed in time, to eliminate hunting.

- Definitely, comment the code. Always.

__________________
There is more to life than just eating mice.
Register to Reply Good Answer (Score 3)
Guru
Popular Science - Weaponology - New Member Safety - ESD - New Member Hobbies - Fishing - New Member

Join Date: Sep 2006
Location: Near Frankfurt am Main, Germany. 50.390866N, 8.884827E
Posts: 17996
Good Answers: 200
#15
In reply to #2

Re: hi help me out here please///

02/19/2010 9:31 AM

Equally as good as Del's comment, so a GA from me too.

Hopefully the OP understands, simplifies his code and puts full comments in for the future...

__________________
"What others say about you reveals more about them, than it does you." Anon.
Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#4

Re: Help Needed with Solar Tracking Program

02/18/2010 2:05 PM

The debug/fault finding process is pretty similar for all applications.

Check each block of your flow chart to see if it works.
Presumably you have some sort of emulator which allows you to see what's going on in the processor? If not you will have to test more carefully.
Check that you are reading the phototransistors. Maybe just light a LED to indicate which is receiving more light as a simple first step.
Check that your software can drive the motor in either direction.
Basically test each block the put them tgether.

Add breakpoints or telltale indicators to show what the program is doing (eg turn a LED on everery time the phototransistors get read.
Or test the circuit using simple switch inputs rather than photo transistors.

The principal is always simplify, divide up the hardware and software functions and test them individually.

Your flow chart is ok-ish but doesn't show the complete flow (e.g the motor drive blocks don't go anywhere)...however there is nothing on your listing relating it back to the flow chart!

Test and debug is a neglected artform, rarely taught.
Del

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Member

Join Date: Feb 2010
Posts: 7
#5
In reply to #4

Re: Help Needed with Solar Tracking Program

02/18/2010 2:36 PM

Yeah, I will..

Thanks a tonne...

With Regards,

Thank you.

Register to Reply
Guru

Join Date: Jun 2009
Location: Bangalore, India
Posts: 725
Good Answers: 24
#6

Re: Help Needed with Solar Tracking Program

02/18/2010 11:26 PM

Can you consider a different procedure? Suppose only one photosensor is used with an opaque beam obstructor (any thin metal sheet will do) mounted vertically above the sensor. The size of this sheet will be decided by the accuracy required for tracking.

The aim is to keep the sensor always in the shade of the sheet. If the sensor is in llight the micro controller rotates the assembly till the sensor goes dark.

MIT researchers devised in the early 70s a system based on this concept, which used a coiled bimetal strip which twisted when exposed to sunlight aligning the shaft to which it was attached till the coil went into shadow using the mechanism described above. This needed no electronics at all.

__________________
bioramani
Register to Reply
Associate

Join Date: Feb 2010
Posts: 43
Good Answers: 5
#7
In reply to #6

Re: Help Needed with Solar Tracking Program

02/19/2010 12:20 AM

Hi bioramani,

While a single photosensor works in principle, a differential photosensor greatly reduces the effects of common-mode variations in light levels due, for example, to clouds passing overhead, and so forth.

One of the simplest differential forms consists of a pair of closely matched photosensors separated by a thin, opaque barrier. So long as the signal levels from the photosensors are approximately the same, the system can assume 1) it is on-track, or 2) it is in shadow. If the system is equipped with an accurate timebase, it can return to an eastward-facing direction at dusk in preparation for the next day's tracking.

Our OP should seriously consider adding a small amount of hysteresis to his tracking algorithm so that the system won't sit "on the edge" and chatter. His tracking motor and its drive electronics will thank him dearly for this little kindness.

Best Regards,

SR

Register to Reply Score 1 for Good Answer
Guru

Join Date: Aug 2005
Location: Hemel Hempstead, UK
Posts: 5826
Good Answers: 322
#8

Re: Help Needed with Solar Tracking Program

02/19/2010 3:18 AM

I don't have a clue about this sort of thing so just ignore me if I'm being stupid, but, is this right?

delay();
}
else if
{
stepper = 0x09;

It would make sense to me without the if, or, with another conditional.

Incidentally couldn't you do the whole thing with analogue. I know that microcontrollers cost very little nowadays but a few transistors is nearly nothing: and you could de-bug it with a DMM.

__________________
If you spend all your time looking for people and things to complain about: trust me, you will find plenty to complain about.
Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#9
In reply to #8

Re: Help Needed with Solar Tracking Program

02/19/2010 3:41 AM

Analog Woo hoo them were the days. Arrr I remembers the days when transistors were in plack painted cans which you could cut the top off and use 'em as photy transistors... Arrr Jim lad.
Del <click pirate mode off>

__________________
health warning: These posts may contain traces of nut.
Register to Reply Off Topic (Score 5)
Associate

Join Date: Feb 2010
Posts: 43
Good Answers: 5
#10
In reply to #8

Re: Help Needed with Solar Tracking Program

02/19/2010 3:57 AM

A couple of CdS cells, some resistors, a DC motor and, if the motor is small enough (or the opamps big enough),

1) one opamp and two batteries,

or

2) two opamps and one battery,

assuming you want the ability to drive the motor in either direction.

"Programming" the system consists in selecting the appropriate components and values for the given application and then assembling them together. Not Assembly "language" as such, but potentially every bit as messy. In a pinch the power switch (do we really need one?) can serve as the boot loader.

Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#11
In reply to #10

Re: Help Needed with Solar Tracking Program

02/19/2010 4:35 AM

A piece of string tied onto the shadow of a stick will do the job
Del

__________________
health warning: These posts may contain traces of nut.
Register to Reply Off Topic (Score 5)
Guru

Join Date: Aug 2005
Location: Hemel Hempstead, UK
Posts: 5826
Good Answers: 322
#12
In reply to #10

Re: Help Needed with Solar Tracking Program

02/19/2010 5:12 AM

If you're prepared to reset it by hand every morning, can't it be done with one photovoltaic solar panel one DC motor and a gear train. No other power supply, electronics or storage required.

(I've never heard of the sun changing directions)

__________________
If you spend all your time looking for people and things to complain about: trust me, you will find plenty to complain about.
Register to Reply
Associate

Join Date: Feb 2010
Posts: 43
Good Answers: 5
#18
In reply to #12

Re: Help Needed with Solar Tracking Program

02/19/2010 11:00 AM

Yes, but I must confess that I simply cannot resist the urge to do other things with it. Fun things. Honestly, watching a unidirectional sun tracker at work is about as much fun as watching paint dry. Even beer doesn't help.

And besides, you know darned well we engineers can't leave well enough alone.

Register to Reply
Anonymous Poster
#13

Re: Help Needed with Solar Tracking Program

02/19/2010 5:54 AM

Either it's running through the big while loop or it's not. Can you put a scope on the pins corresponding to WRITE_1 or WRITE_2 to see if they are toggling. If they're not then I would be suspicious of the while loops where it is probably stuck:

while(INTR_1 == 1);
while(INTR_2 == 1);

Check to see if the pins for INTR_1 and INTR_2 are ever changing.

I've worked with microcontrollers and it's frustrating to not know where it is in the program or what it's doing. You need to look at the interface pins to deduce what is happening inside.

Register to Reply
Guru

Join Date: Dec 2009
Posts: 581
Good Answers: 15
#16

Re: Help Needed with Solar Tracking Program

02/19/2010 9:47 AM

Yes, comments would help, but this is a trivial algorithm. What is essential to help solve the problem is clarifying what "kinda not working" means. Does the motor turn on at all? Does it run at the wrong times? Does it not turn off? Does it start and stop okay but rotate the unit to the wrong position?

My first suspicion is the motor control code:

stepper = 0x0C;
delay();
stepper = 0x06;
delay();
stepper = 0x03;
delay();
stepper = 0x09;
delay();

Without knowing the details of your device, it looks like it might be right. Have you tried a prototype program that turns the motor on for some time then turns it off? Or that pulses the motor repeatedly for some time then stops? (Substitute "while (counter < limit) do something and increment counter" for your "while (1)". The loop limit needs to be tested and tuned to provide a useful delay.) Obviously, you need to be aware that software that controls hardware might damage the hardware if it's broken in the wrong way, and then avoid writing such software...

__________________
Ignorance is no sin. Willful ignorance is unforgiveable.
Register to Reply
Guru
Popular Science - Weaponology - New Member Safety - ESD - New Member Hobbies - Fishing - New Member

Join Date: Sep 2006
Location: Near Frankfurt am Main, Germany. 50.390866N, 8.884827E
Posts: 17996
Good Answers: 200
#17

Re: Help Needed with Solar Tracking Program

02/19/2010 10:37 AM

Firstly, I have changed the logic in the flowchart to allow the solar cell to be more accurately positioned, look here:-

You could add a short delay into the bottom of where the two motor movements join back together again to stop "cycling" back and forwards, but really you need to catch that properly in the software and maybe allow a slight difference between A and B to be accepted as OK and to NOT move the motor. Experience will tell.......

You have also made no correction for the Sun's altitude. You could adjust say once per month by hand, but a similar system as to that for left and right would so the trick...

Also, I notice that you have made no provision for nights, at least no proper provision I find. If it stays pointing west in the evening, it may not pick up that the sun has reappeared in the east the next morning!!!

My suggestion is that you evaluate a level of darkness for A+B in some way, decide when its dark and drive the solar cell back to the east (say to a micro switch that positions slightly "east" of the awaited sunrise position say on midsummer's day morning! Or even just a specific number of stepper motor steps, in the right direction of course! But I personally prefer either a switch or some other position sensor).

Once its positioned back to the east, then give it a test only say once every 15 minutes for a usable A+B light level before starting to adjust the cell position again....thats already in the logic of my version of your flow chart, as both dark means they are also equal!!

You need a method of adjusting the sensors to account for slight differences in both being light or both being dark to make sure that no movement occurs due to that...

Mounting all this temporarily on a rotating table will allow easier/quicker testing than waiting for the sun to move......

Remember, that with the wrong sensors, street lighting and similar may become a problem at nights!!! IR or UV (with filters) would be better, do not use visible light.....but do test, test and test!!

Best wishes.

__________________
"What others say about you reveals more about them, than it does you." Anon.
Register to Reply
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#20

Re: Help Needed with Solar Tracking Program

02/19/2010 5:03 PM

Don't think anyone else has pointed this out (sorry if they did), but in your code, you have

#define Stepper_motor P2

... and later ...

Stepper_motor = 0;

BUT

stepper = 0x0C;
stepper = 0x06;

... etc. refers to an undefined variable. The assembler may just assign a memory location (instead of port P2).

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply Score 1 for Good Answer
Member

Join Date: Feb 2010
Posts: 7
#21
In reply to #20

Re: Help Needed with Solar Tracking Program

02/19/2010 11:40 PM

Ya thanks mate for that..

I ll rectify it..

With Regards,

Thank you.

Register to Reply
Register to Reply 21 comments

Good Answers:

These comments received enough positive votes to make them "good answers".

"Almost" Good Answers:

Check out these comments that don't yet have enough votes to be "official" good answers and, if you agree with them, vote them!
Copy to Clipboard

Users who posted comments:

Andy Germany (3); Anonymous Poster (1); bioramani (1); Blink (1); BruceFlorida (1); JohnDG (1); kungfutar (3); Lynn.Wallace (1); Randall (2); Sonos Research (3); user-deleted-1105 (4)

Previous in Forum: Sonar High Frequency Piezoelectric Device   Next in Forum: Low Voltage Wiring

Advertisement