Page 1 of 1

SolarTracker to track every 5 minutes

Posted: Wed Jul 10, 2019 6:48 am
by Monie Jacobsen
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 14211 times
Tracking.JPG
Tracking.JPG (45.89 KiB) Viewed 14211 times
Attached file:
MIAC dsPICSetting SolarTracker_10-07-2019.fcfx
(181 KiB) Downloaded 268 times

Re: SolarTracker to track every 5 minutes

Posted: Wed Jul 10, 2019 7:57 am
by mnf
One problem is here:
tick.jpg
tick.jpg (14.73 KiB) Viewed 14207 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

Re: SolarTracker to track every 5 minutes

Posted: Wed Jul 10, 2019 8:56 am
by Monie Jacobsen
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

Re: SolarTracker to track every 5 minutes

Posted: Wed Jul 10, 2019 7:36 pm
by mnf
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 14172 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

Re: SolarTracker to track every 5 minutes

Posted: Thu Jul 11, 2019 8:05 am
by Monie Jacobsen
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 14149 times
Attached file:
MIAC dsPICSetting SolarTracker_11-07-2019.fcfx
(181.99 KiB) Downloaded 304 times

Re: SolarTracker to track every 5 minutes

Posted: Thu Jul 11, 2019 8:24 am
by mnf
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

Re: SolarTracker to track every 5 minutes

Posted: Thu Jul 11, 2019 10:42 am
by Monie Jacobsen
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

Re: SolarTracker to track every 5 minutes

Posted: Thu Jul 11, 2019 7:12 pm
by mnf
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 290 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

Re: SolarTracker to track every 5 minutes

Posted: Fri Jul 12, 2019 8:53 am
by Monie Jacobsen
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

Re: SolarTracker to track every 5 minutes

Posted: Fri Jul 12, 2019 9:27 am
by Monie Jacobsen
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.27 KiB) Viewed 14105 times
Can you see where it goes wrong or have a suggestion.

Yours sincerely
Monie

Re: SolarTracker to track every 5 minutes

Posted: Fri Jul 12, 2019 2:48 pm
by mnf
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

Re: SolarTracker to track every 5 minutes

Posted: Sat Jul 13, 2019 3:11 pm
by Monie Jacobsen
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 267 times
Here I have something to learn! What makes the picture below?
Diaplay Main secs.JPG
Diaplay Main secs.JPG (10.83 KiB) Viewed 14066 times

Re: SolarTracker to track every 5 minutes

Posted: Sat Jul 13, 2019 7:47 pm
by mnf
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.

Re: SolarTracker to track every 5 minutes

Posted: Sun Jul 14, 2019 9:46 am
by Monie Jacobsen
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 ;-)

Re: SolarTracker to track every 5 minutes

Posted: Sun Jul 14, 2019 9:57 am
by mnf
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

Re: SolarTracker to track every 5 minutes

Posted: Sun Jul 14, 2019 11:39 am
by mnf
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

Re: SolarTracker to track every 5 minutes

Posted: Mon Jul 15, 2019 7:06 am
by Monie Jacobsen
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 263 times

Re: SolarTracker to track every 5 minutes

Posted: Tue Jul 16, 2019 6:41 am
by mnf
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

Re: SolarTracker to track every 5 minutes

Posted: Tue Jul 16, 2019 9:50 am
by Monie Jacobsen
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
search.php?st=0&sk=t&sd=d&sr=posts&keyw ... t&start=50

Re: SolarTracker to track every 5 minutes

Posted: Tue Jul 16, 2019 2:47 pm
by mnf
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...