SolarTracker to track every 5 minutes

For MIAC users to discuss projects, applications, and any other issues related to the MIAC unit.

Moderators: Benj, Mods

Monie Jacobsen
Posts: 428
Joined: Mon Jul 30, 2012 3:39 pm
Has thanked: 9 times
Been thanked: 42 times
Contact:

SolarTracker to track every 5 minutes

Postby Monie Jacobsen » Wed Jul 10, 2019 6:48 am

Hello everyone

Does anyone here help with getting SolarTracker to track every 5 minutes?
Have tried very much but without success ;-)
Hope much you will come up with a proposal and like where it goes wrong!

Interrup Tracking.JPG
Interrup Tracking.JPG (45.67 KiB) Viewed 322 times

Tracking.JPG
Tracking.JPG (45.9 KiB) Viewed 322 times

Attached file:
MIAC dsPICSetting SolarTracker_10-07-2019.fcfx
(181 KiB) Downloaded 3 times
Best Regard
Monie

mnf
Valued Contributor
Valued Contributor
Posts: 457
Joined: Wed May 31, 2017 11:57 am
Has thanked: 50 times
Been thanked: 256 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby mnf » Wed Jul 10, 2019 7:57 am

One problem is here:

tick.jpg
tick.jpg (14.73 KiB) Viewed 318 times


tick is a byte variable and can only have (integer) values of 0..255. It can NEVER equal 1068.115 so tracking period is never updated..... If tick=60 ?

The timing routines need changing (but don't change Tick to a float !)

Martin

Monie Jacobsen
Posts: 428
Joined: Mon Jul 30, 2012 3:39 pm
Has thanked: 9 times
Been thanked: 42 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby Monie Jacobsen » Wed Jul 10, 2019 8:56 am

Hello everyone

I wish (CODE) to start Tracker every 5 minutes and finish (STOP) after 1 minute.
Would you like to help with a proposal;-)

Yours sincerely
Monie
Best Regard
Monie

mnf
Valued Contributor
Valued Contributor
Posts: 457
Joined: Wed May 31, 2017 11:57 am
Has thanked: 50 times
Been thanked: 256 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby mnf » Wed Jul 10, 2019 7:36 pm

Hi Monie,

There are (as ever) many ways to do this..

As your interrupt routine runs at 50Hz something like

tick.jpg
tick.jpg (10.68 KiB) Viewed 283 times

as the interrupt routine would increment seconds and minutes (and could be extended to hours etc)
(Note that I've used some modulo arithmetic to avoid the 'if ticks = 50 then secs = secs + 1'... for coding speed - the 'ifs' would probably be slightly more efficient in practice)
Then check if minutes % 5 = 0 and run code whilst it does? (runs whilst minutes ends with 0 and 5 (and not for endings of 1,2,3,4,6,7,8,9))
Note that you may need to extend this to hours etc (ie Hours = Hours + Minutes / 60, Minutes = Minutes % 60)..
I don't know how accurate the frequency of the interrupts is (ie is it exactly 50Hz and stable) - if not then:

As you have a RTC device - can you use this to check the time - or generate an alarm 'interrupt' every 5 minutes? (the DS3232 would allow something like this) (This may allow you to 'sleep' the MCU saving some power.

Or you may use a combination and 'correct' the MCU time from the RTC occasionally?


Martin

Monie Jacobsen
Posts: 428
Joined: Mon Jul 30, 2012 3:39 pm
Has thanked: 9 times
Been thanked: 42 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby Monie Jacobsen » Thu Jul 11, 2019 8:05 am

Hi Martin
Many thanks for your suggestions;-)
Have tried many of your suggestions but unsuccessfully.
Can't Get the Tracker Function to Work!
Would you like to help insert your suggestions into the Tracker operation.

Tracking.JPG
Tracking.JPG (102.25 KiB) Viewed 260 times


Attached file:
MIAC dsPICSetting SolarTracker_11-07-2019.fcfx
(181.99 KiB) Downloaded 3 times
Best Regard
Monie

mnf
Valued Contributor
Valued Contributor
Posts: 457
Joined: Wed May 31, 2017 11:57 am
Has thanked: 50 times
Been thanked: 256 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby mnf » Thu Jul 11, 2019 8:24 am

Hi Monie,

I'll have a look after work.

In the meantime, you set tick = 0 just before stopping the motor.
If this is in a loop it will effectively 'stop the clock' whenever the solar tracker runs (including minutes=0)

So try deleting this and leave the timekeeping to the interrupt!

Martin

Monie Jacobsen
Posts: 428
Joined: Mon Jul 30, 2012 3:39 pm
Has thanked: 9 times
Been thanked: 42 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby Monie Jacobsen » Thu Jul 11, 2019 10:42 am

Hi Martin
I've tried out some of your suggestions.
But it does not seem to grout properly.
I'm just as stuck.
So a code example in the attach file will greatly benefit me;-)

GO' Working Day

Monie
Best Regard
Monie

mnf
Valued Contributor
Valued Contributor
Posts: 457
Joined: Wed May 31, 2017 11:57 am
Has thanked: 50 times
Been thanked: 256 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby mnf » Thu Jul 11, 2019 7:12 pm

Hi Monie,

So - first we need to establish that the interrupt routine is working correctly at 50Hz

I haven't used PIC and I don't have hardware to test on - so please test:

Timer5min.fcfx
(12.03 KiB) Downloaded 5 times

This just displays ON for 1 min at 0,5,10,15... mins runtime (and stopped elsewise)

Under simulation the timer increases more quickly - not sure if this is because the interrupt parameters are set incorrectly (just copied from your code) - or if the simulation of interrupts is 'faulty' - perhaps a PIC guru could comment ?

Let me know if it works!

Martin

Monie Jacobsen
Posts: 428
Joined: Mon Jul 30, 2012 3:39 pm
Has thanked: 9 times
Been thanked: 42 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby Monie Jacobsen » Fri Jul 12, 2019 8:53 am

Hi Martin

Thank you very much for your proposal for Tracking
I work well with your proposal and will tell you how it works in practice.

GO´ weekend
Monie
Best Regard
Monie

Monie Jacobsen
Posts: 428
Joined: Mon Jul 30, 2012 3:39 pm
Has thanked: 9 times
Been thanked: 42 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby Monie Jacobsen » Fri Jul 12, 2019 9:27 am

Hi Martin
Then I have a test in the practice world.
And the display shows start and stop. And this looks right.
But have tried to set the component Motor Reversible so this starts every 5 minutes and runs max 1 minute
But in simulation and in practice the Motor does not run.

Interrup Tracking Motor.JPG
Interrup Tracking Motor.JPG (115.28 KiB) Viewed 216 times

Can you see where it goes wrong or have a suggestion.

Yours sincerely
Monie
Best Regard
Monie

mnf
Valued Contributor
Valued Contributor
Posts: 457
Joined: Wed May 31, 2017 11:57 am
Has thanked: 50 times
Been thanked: 256 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby mnf » Fri Jul 12, 2019 2:48 pm

sorry - don't have a licence for the mechatronics pack so can't see anything for motor.

How are you powering it?
Can you run it from code normally?
Is there some initialisation needed?
Is it wired correctly?

Martin

Monie Jacobsen
Posts: 428
Joined: Mon Jul 30, 2012 3:39 pm
Has thanked: 9 times
Been thanked: 42 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby Monie Jacobsen » Sat Jul 13, 2019 3:11 pm

Hi Martin

How are you powering it? User Motor component DC Motor (Full Bridge)
Can you run it from code normally? Yes
Is there some initialisation needed? Component DC Motor (Full Bridge)
Is it wired correctly? Yes
Here you can see where I turn on Tracking and turn off after 1 minute
And I can use this!
Thank you so much for your great help;-)
See attached:
Timer5min.fcfx
(13.74 KiB) Downloaded 1 time


Here I have something to learn! What makes the picture below?
Diaplay Main secs.JPG
Diaplay Main secs.JPG (10.84 KiB) Viewed 177 times
Best Regard
Monie

mnf
Valued Contributor
Valued Contributor
Posts: 457
Joined: Wed May 31, 2017 11:57 am
Has thanked: 50 times
Been thanked: 256 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby mnf » Sat Jul 13, 2019 7:47 pm

Glad to hear you are progressing.

The group is just select some icons and group them. You can right click and ingroup. They weren't important to the coffee, so just a way of keeping things tidy.

Monie Jacobsen
Posts: 428
Joined: Mon Jul 30, 2012 3:39 pm
Has thanked: 9 times
Been thanked: 42 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby Monie Jacobsen » Sun Jul 14, 2019 9:46 am

Hi Martin

Questions regarding the below illustrated!
In Display, the following step shows:

1 : 0
ON

After some drawings, the display shows, for example,
90 : 0
ON

How can we know at each startup of Tracking reset Minutes and Seconds in Dispaly ??
Do you have a suggestion ?
Have tried a lot but unsuccessfully, therefore the question?

The Tracking works very well ;-)
Best Regard
Monie

mnf
Valued Contributor
Valued Contributor
Posts: 457
Joined: Wed May 31, 2017 11:57 am
Has thanked: 50 times
Been thanked: 256 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby mnf » Sun Jul 14, 2019 9:57 am

Hi Monie,

The sample I sent just displays minutes and seconds since start.

See notes above about extending to hours.
I thought you would probably use the rtc to get the time for the tracking as this is likely more accurate.
Also I used a byte so minutes will wrap at 255 - change to an int or long if you just want to track minutes since start up.

Martin

mnf
Valued Contributor
Valued Contributor
Posts: 457
Joined: Wed May 31, 2017 11:57 am
Has thanked: 50 times
Been thanked: 256 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby mnf » Sun Jul 14, 2019 11:39 am

If you want minutes to go 0..4 repeatedly.

Then have minutes=(minutes+(seconds / 60))%5
In the interrupt handler.

Seconds go 0..59 and you need this to time the minutes run time

Monie Jacobsen
Posts: 428
Joined: Mon Jul 30, 2012 3:39 pm
Has thanked: 9 times
Been thanked: 42 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby Monie Jacobsen » Mon Jul 15, 2019 7:06 am

Hi everyone

Is it possible to convert Minutes to Byte file called Track_Period from Clock Coderne attached below! This will make the whole processes simpler. And don't use anything interrupts.
So that Track_Period = (convert Minutes to Byte).
Attached files:
MIAC_dsPIC_ClockOrginal.fcfx
(34.87 KiB) Downloaded 3 times
Best Regard
Monie

mnf
Valued Contributor
Valued Contributor
Posts: 457
Joined: Wed May 31, 2017 11:57 am
Has thanked: 50 times
Been thanked: 256 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby mnf » Tue Jul 16, 2019 6:41 am

Do you mean:

On = (Minutes % 5) == 0 where on is a bool or a byte ( in a calculation block)
Or use an if block - if (minutes % 5) = 0 then on = true ( yes branch)

Note that the use of == in the first technique and remember to set on to false in the no branch if you use a decision macro

Martin

Monie Jacobsen
Posts: 428
Joined: Mon Jul 30, 2012 3:39 pm
Has thanked: 9 times
Been thanked: 42 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby Monie Jacobsen » Tue Jul 16, 2019 9:50 am

HI Martin
Thanks for your reply...

Please see the web link below!
There you will be able to see the topic (Minutes% 5) = 0 described a LeighM
https://www.matrixtsl.com/mmforums/search.php?st=0&sk=t&sd=d&sr=posts&keywords=Minut&start=50
Best Regard
Monie

mnf
Valued Contributor
Valued Contributor
Posts: 457
Joined: Wed May 31, 2017 11:57 am
Has thanked: 50 times
Been thanked: 256 times
Contact:

Re: SolarTracker to track every 5 minutes

Postby mnf » Tue Jul 16, 2019 2:47 pm

Thanks Monie,

They so explains why your motor didn't work - each time motor start was called it set the speed to 0 ready to accelerate up. If, for example, you set a pin high in the on branch, it would work as expected.

What's really needed is ac way to call start at the start of the minute and stop at the end of it...