Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

wait vs timer
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
jodank

Bascom Member



Joined: 22 Apr 2014
Posts: 49

blank.gif
PostPosted: Tue Apr 22, 2014 2:07 pm    Post subject: wait vs timer Reply with quote

Hi! to all folks...
I have a simple question.
I'm new on avr and Bascom.
I have a small project to do.
Project:

- 8 led's represents each one 1h time
- Human should press a button on every 50-70 min.
If button pressed in the time between 50 - 70 min. then a led goes on.

I wish to use the wait function to measure the time between 0 - 70 min.
I wish to use an INT0 for the input button.

Is the wait function precise enough to make this job or should I use the Timer from my Attiny2313?

Can somebody advice me for what and wen should we use the WAIT function of Bascom if not in case like this?
I'm not really understand the difference between the WAIT and the TIMER function... Sad

Thank's for any advice.

(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1548
Location: Basel, Switzerland

switzerland.gif
PostPosted: Tue Apr 22, 2014 5:50 pm    Post subject: Reply with quote

Hi,

Wait just sits in a tight Loop, incrementing a variable unril a value is reached.

A timer is a Hardware function that Counts CPU ticks allowing the main CPU do something else or sleep (saving power)-

I would recommend using a timer that fires every few seconds, incrementing a Counter until you reach the required time.


Regards
Ian Dobson

_________________
Home of AVRTimer, the Bascom timer value calculator.
http://www.planet-ian.com

Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile Visit poster's website
Arera

Bascom Member



Joined: 23 Sep 2007
Posts: 375
Location: Wuppertal, Germany

germany.gif
PostPosted: Tue Apr 22, 2014 5:58 pm    Post subject: Reply with quote

Hi jodank and welcome to this friendly forum!
Your question contains 100 subquestions...
WAIT stops your prog for a given time. That is sometimes useful for microsec to single secs.
Do not wait for an hour!!!!
Timers are powerful and versatile. In your case, I'd suggest following:
Choose the shortest tomeunit you need to resolve. Here this might be one second.
Set one timer to interrupt every second. In the interrupt, increase a word-var. In the main routine, calculate the elapsed time since a button was pushed or anything else.
Think about that, then poke the next question!
Marc
Back to top
View user's profile
Arera

Bascom Member



Joined: 23 Sep 2007
Posts: 375
Location: Wuppertal, Germany

germany.gif
PostPosted: Tue Apr 22, 2014 8:51 pm    Post subject: Reply with quote

Ians and my posts crossed. Ian is THE ONE to ask how to insert a timer for this specific purpose.
Come on Ian, post the link!
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1548
Location: Basel, Switzerland

switzerland.gif
PostPosted: Tue Apr 22, 2014 9:05 pm    Post subject: Reply with quote

Arera wrote:
Ians and my posts crossed. Ian is THE ONE to ask how to insert a timer for this specific purpose.
Come on Ian, post the link!


Just go over to my web site, Software Tools.

AVRTimer calculates the correct reload values for an AVR timer that fires every x MS and even generates the Bascom code for you.
I was hopeing that my signature would be enough Smile

Regards
Ian Dobson

_________________
Home of AVRTimer, the Bascom timer value calculator.
http://www.planet-ian.com

Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1216
Location: SYDNEY

australia.gif
PostPosted: Tue Apr 22, 2014 11:56 pm    Post subject: Reply with quote

Hello jodank

The wait is mainly for short delays but it will work but accuracy might be a problem if you have a look in the blog & share your working avr code sections you will find some projects from me in them there is a one second timer that uses the avr clock via an interrupt very good time can be achieved if a crystal or more so if a much higer frequecy crystal oscillator is used and its ouput divided down to run the avr you can see this in my ENC28J60 web server project where the ENC28J60 has a clock output driving the avr that is half of its 25Mhz crystal with this it keeps good time with better than one second per day. Also look at this post http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=10604&highlight=real+clock

Regards Paul
Back to top
View user's profile
jodank

Bascom Member



Joined: 22 Apr 2014
Posts: 49

blank.gif
PostPosted: Wed Apr 23, 2014 1:28 am    Post subject: Reply with quote

Ok folks I will try to use the timer function.
I can see that option is better ad I have to learn the timer from AVR too... Smile
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 757

poland.gif
PostPosted: Thu Apr 24, 2014 8:53 am    Post subject: Reply with quote

I'm interested in what this device works. Is man at work? Very Happy And what if you do not press a button? Show for which it was not, or only seven leds lights?
Back to top
View user's profile Visit poster's website
jodank

Bascom Member



Joined: 22 Apr 2014
Posts: 49

blank.gif
PostPosted: Fri Apr 25, 2014 7:27 am    Post subject: Reply with quote

Hi EDC
Yes, the button should press men on work ( night guard ) have to walk around the company and on some points of interest will be mounted one of my device...

If the night guard is missing one hour ( to press the button between 50 & 70 min ) then the led which represent that hour will not fire up.
So on the morning another person will check the result and inform the boss about the situation.
Back to top
View user's profile
jodank

Bascom Member



Joined: 22 Apr 2014
Posts: 49

blank.gif
PostPosted: Sat Apr 26, 2014 8:38 pm    Post subject: Reply with quote

Hi folks I'm here again. I stuck with the prescaler stuff. I can't figure out how to get the right prescaler number. I know I should some math do but I'm really stuck with in. Sad

I tried the calculator software which some good people shared her but it won't start. Crashed, don't know why. ..

Can somebody help me with the prescaler no to understand?

Thanks so much. ..
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1548
Location: Basel, Switzerland

switzerland.gif
PostPosted: Sat Apr 26, 2014 9:13 pm    Post subject: Reply with quote

Hi,

What error message did you get when AVRTimer crashed? Maybe your missing a DLL or something.

Regards
Ian Dobson

_________________
Home of AVRTimer, the Bascom timer value calculator.
http://www.planet-ian.com

Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile Visit poster's website
jodank

Bascom Member



Joined: 22 Apr 2014
Posts: 49

blank.gif
PostPosted: Sat Apr 26, 2014 9:20 pm    Post subject: Reply with quote

Right now I'm away from my pc and can't tell you what type of error I got but I will check and text you.
I will check now on the notebook of my girlfriend to see what's going on. . .
Back to top
View user's profile
jodank

Bascom Member



Joined: 22 Apr 2014
Posts: 49

blank.gif
PostPosted: Sat Apr 26, 2014 9:41 pm    Post subject: Reply with quote

i.dobson:
Sorry but it's seems it is a problem on my pc.
Right now I tried your calculator on the notebook of my girlfriend and it's work fine.

So, pls sorry...
I will check what is wrong on my pc.
Dif are between this notebook and my pc is in the OS.
On my pc is XP installed and on the notebook is Win7 but I think on my pc is something other wrong...
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1548
Location: Basel, Switzerland

switzerland.gif
PostPosted: Sat Apr 26, 2014 9:49 pm    Post subject: Reply with quote

Hi,

No Problems. AVRTimer is written in VB 6.0 and requires several DLL's, that I don't supply with the ZIP.

Just grab the Visual Basic 6.0 runtime files from Microsoft. That should do it.

Regards
Ian Dobson

_________________
Home of AVRTimer, the Bascom timer value calculator.
http://www.planet-ian.com

Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 757

poland.gif
PostPosted: Sat Apr 26, 2014 10:14 pm    Post subject: Reply with quote

Hello. Tell us what freq of oscilator you use. In new chip you have Divider by 8 and internal oscillator set by factory so freq is 1MHz.
If you want some other freq for your project then you must change the Fuse bits. I think so is good idea to use this tool http://atnel.pl/mkavrcalculator.html
This is software freeware for popular uC like Tinny2313 and ATmega8. It support many programmers. This tool can read Fuse Bits and "translate" for you to language you can understand Very Happy then in easy way can change without mistakes like "seting external oscilator" or "disable serial programming" or "use reset pin like port pin".
Inside software is another "stuff" Very Happy Timer calculator or resistor divider with many calculated value.
Sorry for my english guys Very Happy

Everyone probably would have done it differently but here's my idea for comparison Very Happy

Code:

$regfile = "2313def.dat"
$Crystal=1000000
$hwstack=40
$swstack=16
$framesize = 32

Config Portb = &B11111111 : Portb = &B11111111              'for LED`s (light On in Low)
Config Portd = &B00000000 : Portd = &B11111111              'inputs for switches

Config Timer1 = Timer , Prescale = 64
Enable Timer1 : On Timer1 Clock                             'jump to Clock every second

Const Presettimer1 = 49912                                  ' value for timer load

Dim Seconds As Byte , Minutes As Byte , Hours As Byte
Dim Countdown As Byte , B_port As Byte , Help As Byte

Waitms 100                                                  'time for port to set properly

If Pind.6 = 0 Then                                          ' If switch pressed on reboot then
 Hours = 1                                                  'reset counters
 B_port = 255                                               'all LED`s off
 Writeeeprom Hours , 2
 Writeeeprom B_port , 4
 Waitms 100
End If

Readeeprom Hours , 2                                        'reached value are saved and restored if power interrupted
Readeeprom B_port , 4

If Hours > 24 Then Hours = 1                                'this secure from FF when program is writing
Minutes = 10                                                ' offset for non Integer use +/- 10min
Portb = B_port                                              'this light LED`s

Enable Interrupts
'************* START ******************
Do

If Minutes = 81 Then                                        'if switch not pressed then hour is missed and showed on "LED bar"
    Minutes = 21
    Incr Hours
    Writeeeprom Hours , 2                                   'only next LED can be  trigged
    Waitms 50
    Countdown = 39                                          'and only after 40 min (now is 10 min after hour)
End If

Debounce Pind.6 , 0 , Time_check , Sub                      'switch to ground

Loop
'************ END *********************
Time_check:

Select Case Minutes

 Case 60 To 80                                              'betwen 50 - 70 min including ofset
 If Countdown = 0 Then
  If Minutes < 70 Then
   Help = 70 - Minutes
   Minutes = 10 - Help
  Elseif Minutes > 70 Then
   Help = Minutes - 70
   Minutes = 10 + Help
  End If
  Incr Hours                                                'next LED can be trigged
    Countdown = 49                                          ' and only after 50 min
   Select Case Hours
    Case 1
     Reset Portb.0
    Case 2
     Reset Portb.1
    Case 3
     Reset Portb.2
    Case 4
     Reset Portb.3
    Case 5
     Reset Portb.4
    Case 6
     Reset Portb.5
    Case 7
     Reset Portb.6
    Case 8
     Reset Portb.7
   End Select
   B_port = Portb                                           'read port to value
   Writeeeprom B_port , 4
   Writeeeprom Hours , 2
   Waitms 50
 End If

 End Select

Return




Clock:
Timer1 = Presettimer1
Incr Seconds
  If Seconds >= 60 Then
     Seconds = 0
     Incr Minutes
     If Countdown > 0 Then Decr Countdown
  End If
Return
 
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
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