Shop OBEX P1 Docs P2 Docs Learn Events
Sine function — Parallax Forums

Sine function

Hello again!
For my new project i need to find the sine values of numbers, like in this formula used to determine solar declination at a given date (or more correct day of year, d):
declination.jpg

I have looked at the sine table code example in the Propeller manual (page 385 I think) but I'm not familiar with PASM and I also get an error when compiling that code using a standard object template.

Does anyone have a good idea on using that code or is it a more simple way to find SIN and also INV SIN?

KjellO

Comments

  • I wrote a Spin program to list out a lot of the values in the sine table.

    Hopefully my program will make it easier to understand how the table works.

    http://forums.parallax.com/discussion/160994/my-attempt-to-understand-the-sine-table
  • AribaAriba Posts: 2,690
    Here you find some code to access the sine tabel from Spin:
    forums.parallax.com/discussion/103610/accessing-sin-cos-tables-in-spin

    But I think you will need floating point math to solve such a formula, and the float objects have there own sine functions.

    IMO it makes not much sense to calculate the delta angles at runtime anyway. Just precalculate the angle for every day on the PC, and store a table with the 360 values in a DAT section for Spin.

    Andy
  • I'm with Ariba on that one. Better yet, if you don't want a huge table, compute for every fourth or eighth day, and linearly interpolate between values for the days not itemized.

    -Phil
  • There is Gregg Erickson's versatile and well documented solar calculator object in OBEX:
    http://obex.parallax.com/object/551
  • Thanks to all for replies and for the links to the different codes. I will take a look at them and try to figure out the sine mystery. Much of Gregg Erickson's code will probably be extreamly overkill. However, I guess I can pick up some nice ideas on running servos, based on the sun's current position.
    So, a few words on my project: I'm building two solar heaters both a little more then one square meters. They will both be placed on a kind of frame in parallell, and be able to track the sun in two axis.
    Tracking will probably start at 8am and end at 6 or 7pm. Not earlier because of nearby buildings, not later because of less solar energy at night.
    The azimut bearing will not be tilted but stay in level, just because of the construction itself. Tracking the sun's different elevation during the hours will be left to the Propellers software and the servos. I guess one adjustment/hour will be good enough. Also for calculating declination, once every week would probably be good enough, I do agree with Ariba and Phil here.
    The heaters will be run from first week of february and until end of october, the rest of the year they will be in the shade due to the hills and mountains. I also plan to use a closed circuit of anti freeze liquid and heat exchangers for the heat transportation up the house. Purpose is to pre heat water for the main water heater. Gets lots of useful ideas from my friend Peter LA6WNA who is heavy into such kind of things!
    Will post pictures here showing the progress of the project.
  • Heater.Heater. Posts: 21,230
    Of course you don't need to actually do any calculations with sines or complicated solar calculators to track the sun.

    All you need is a clock!

    Crank the thing to a know starting position every morning and start winding it around at a known starting time. At a constant rate of 1 degree every 4 minutes.

    Set the start position and start time up once and it will always be correct. Don't use local time with daylight saving adjustments, use the Proper time (GMT :) ).

    Back in late seventies when this sort of thing was all the rage due to the oil crisis at the time a guy in my tech college built such a tracking solar heater. It used a big old wind up clock work mechanism turning a wooden "gear" that was simply a semicircle of plywood.
  • @Moskog
    btw. you can simplify the formula to
    declination[degree] = 23.4 * sin(360° * (284+x)/365) = 23.4 * sin(360° * (x-81)/365)
    because arcsin(sin(23.4°)) is 23.4°

    but like Heater say, a clock is all you need

    ;-) Reinhard
  • ... otherside, is not time critical.
    see attached zip file with prop-gcc project

    ;-) Reinhard
  • I guess I won't need to change the declination angel more often then once a week, that means I need some 36 or so precalculated values in the DAT section to cover the sunny periode of the year. And also 10-12 values for the azimut adjustment every top-of-the-hour. The tricky part could be the hourly adjustment for the suns real angel above the horizon, from the morning and througout the day. Maybe use some precalculated values there too, one for each hour.
Sign In or Register to comment.