Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

1 day delay

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO
View previous topic :: View next topic  
Author Message
velja

Bascom Member



Joined: 17 Aug 2015
Posts: 4

blank.gif
PostPosted: Sat Feb 25, 2017 11:31 pm    Post subject: 1 day delay Reply with quote

Hi,
I make weather station with atmega328 on 16MHz. I need for rain gauge period of 1 day. I can count impulse from rain gauge, accumulate it, but after 1 day I have to reset that value (mm/day rain fall). I use timer1 on interrupt for measuring period for wind speed sensor so I can't use it for making time base. How to solve this problem?
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Feb 26, 2017 2:08 am    Post subject: Reply with quote

In my web severs in the blog section I have created a real time clock
using the CPU clock I increment a variable during this interrupt
the variable is there to get NTP time each 24hours you could use
this for your purpose.
Regards Paul
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Sun Feb 26, 2017 11:02 am    Post subject: Reply with quote

With Arduino Uno you can't use the internal clock system because the M328 use PB6 and PB7 with the external 16MHz crystal so impossible to use a 32Khz crystal

but you can use an external I2C RTC as DS3231 or other softclock then you can use varWord= Sysday()

JP Wink
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Feb 26, 2017 12:02 pm    Post subject: Reply with quote

Hello Jp
I use the 16Mhz CPU clock and if you measure the frequency of the clock
I have found it to be ok for 24hour periods I then updated via NTP
Regards Paul
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Sun Feb 26, 2017 12:38 pm    Post subject: Reply with quote

Hi paul,
Right ! Embarassed I didn't look at your work before http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=12358&postdays=0&postorder=asc&start=0
Nice indeed !
but velja use a M328, is it possible to use Wiznet W5100 with a M328 and add all components of weather station ? maybe... I did a lot of programs on M32.

JP
Wink
Back to top
View user's profile Visit poster's website
velja

Bascom Member



Joined: 17 Aug 2015
Posts: 4

blank.gif
PostPosted: Sun Feb 26, 2017 12:50 pm    Post subject: Reply with quote

Well, it's not essential to be 24 hours strictly. About external RTC, I have module with DS1307 but it fit on 5V system which is not mine. I use 3,3V, but it is important to use less components as it is possible with low power consumption as it is solar powering device. The one day period is on second place.
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Feb 26, 2017 1:26 pm    Post subject: Reply with quote

Hello velja
It does not matter what voltage or crystal you just change the numbers
Have a look at this code http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=10604&highlight=using+cpu+clock
you only need the interrupt to increment a variable
every second and to check if its 24hours worth of seconds
in your main program if it is reset to zero and do the task.
Note you do not need the date time library or lcd only the interrupt.
Regards Paul
Back to top
View user's profile
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 320
Location: Japan

japan.gif
PostPosted: Sun Feb 26, 2017 3:06 pm    Post subject: Reply with quote

If Timer0 or Timer2 is not used, 1 second can be created even with 8bit timer.
And it is possible to count it 24 hours.
Code:
   Dim T8msec As Byte
   Config Portb.5 = Output

   Config Timer2 = Timer , Prescale = 1024 , Clear Timer = 1       '16,000,000Hz / 1024 = 15,625Hz
   Ocr2a = 125 - 1                                          '15,625Hz / 125 = 125Hz (8mS)

   Do
      If Tifr2.ocf2a = 1 Then                               'Did 8ms elapsed?
         Set Tifr2.ocf2a
         T8msec = T8msec + 1
         If T8msec = 125 Then                               'Did 1sec elapse? (8ms * 125 = 1sec)
            T8msec = 0
            Set Portb.5                                     'The Arduino LED lights up at 1 second intervals.
            Waitms 5
            Reset Portb.5
         End If
      End If
   Loop

   End
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum