Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

wait vs timer
Goto page Previous  1, 2
 
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: Sun Apr 27, 2014 2:08 pm    Post subject: Reply with quote

Hey man! You did the whole software.? Smile
Thanks man!

I think to use 8Mhz crystal but I think the internal oscillator should do the job too. Or?
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 757

poland.gif
PostPosted: Sun Apr 27, 2014 2:26 pm    Post subject: Reply with quote

You can try but the internal oscillator is not very accurate. For short procedures is sufficient but I would advise here external oscillator. Therefore, Timer 1 is loaded into a constant. It can be changed when you change the frequency.

Enjoy. The software requires a few more thoughts. Deleting variables may be another key, also need to think out what the variable Hours after eight hours.
Back to top
View user's profile Visit poster's website
jodank

Bascom Member



Joined: 22 Apr 2014
Posts: 49

blank.gif
PostPosted: Sun Apr 27, 2014 2:35 pm    Post subject: Reply with quote

I finished before this software with the wait function but as I told I figured out does it would be better to made it with the timer function but I'm not so familiar with it and therefore I will learn how to use the timer and I stuck with the prescaler. ..
I will try and make mods on your software and share the result with you here.
I'm very happy for the code which you shared with as.
Thanks man. .. Smile
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 757

poland.gif
PostPosted: Sun Apr 27, 2014 2:44 pm    Post subject: Reply with quote

I write It by night and when now look into code i see so instruction "Incr Hours" must be after "End select" of Hours and before Writing to Eeprom

Code:
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

    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
   Incr Hours                                               'next LED can be trigged
   Writeeeprom B_port , 4
   Writeeeprom Hours , 2
   Waitms 50
 End If

 End Select

Return

 



And once again ->try calculator bullit in MkAVcalculator. Is "userfriendly" Show all possibilites for desired freq/interval/osc output and prescalers. Is not mine Very Happy but this is cool staff and easy to use and understand timers
Back to top
View user's profile Visit poster's website
jodank

Bascom Member



Joined: 22 Apr 2014
Posts: 49

blank.gif
PostPosted: Tue Apr 29, 2014 4:28 am    Post subject: Reply with quote

Can somebody help me to solve the problem with this code:

Code:

$regfile = "2313def.dat"
$crystal = 8000000

$hwstack=40
$swstack=16
$framesize = 32

const Timer1Reload = 7812
Config Timer1 = Timer , Prescale = 1024
Config Portb.0 = Output

load timer1 , Timer1Reload
on ovf1 Timer1_isr
enable timer1
Start Timer1

enable interrupts

Portb.0 = 1

Timer1_ISR:
   load timer1, Timer1Reload
    If Portb.0 = 1 Then
      Portb.0 = 0
      Waitms 500
   Else
      Portb.0 = 1
      Waitms 500
   End If
  return
 


I try to toggle the led on portb.0 pin but nothing is going on and off...

Sad
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 757

poland.gif
PostPosted: Tue Apr 29, 2014 1:42 pm    Post subject: Reply with quote

In interrupts routines we try to not using ANY delay.
For this "job" a Time to interrupt should be delay.
In your code Return instruction dont have place to return Very Happy

Try this
Code:
$regfile = "2313def.dat"
$crystal = 8000000                                          'remember that calculations are for this freq

$hwstack=40
$swstack=16
$framesize = 32

Config Portb.0 = Output : Portb.0 = 1
Config Portb.1 = Output : Portb.0 = 1

Const Timer1reload = 61631                                  'this should be 500ms

Config Timer1 = Timer , Prescale = 1024
Enable Timer1 : On Timer1 Timer1_isr

Enable Interrupts

'***** start o neverending loop *****
Do


Loop
'***** end of loop **********
End
'


Timer1_isr:
  Timer1 = Timer1reload

   Toggle Portb.0                                           'toggle change state of pin
   Portb.1 = Not Portb.1                                    'this is the same

  Return                                                    ' return to what? In your code no place to return

 


One question in the end. Do you change fusebit DIV8 ? (dividing by 8 setted factory) If not your Freq is 1MHz and LED blink slowly Wink
Back to top
View user's profile Visit poster's website
jodank

Bascom Member



Joined: 22 Apr 2014
Posts: 49

blank.gif
PostPosted: Wed Apr 30, 2014 10:17 am    Post subject: Reply with quote

Thank's for the advice.
I put the wait function into the isr routine because I was very frustrated Smile and I put it just in...

The main problem is the do - loop. I didn't give the program to do something but runs through the whole program and through the isr process. Smile
Back to top
View user's profile
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 Previous  1, 2
Page 2 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