Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Timer2 not working in real hardware..

 
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 Unsupported versions
View previous topic :: View next topic  
Author Message
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Tue Nov 10, 2015 8:18 am    Post subject: Timer2 not working in real hardware.. Reply with quote

Hi
I am using the following code having attached a 32.768khz crystal to pins 28,29 of atmega16, the code runs fine in Proteus but not working in real hardware as for incrementing of second minute and hour variable, this is a simple code where i want the time in minutes and not a real clock rather i want to get seconds and minutes to be displayed in 40X4 lcd..





'Procesor Identification ==============================
$regfile = "m16adef.dat"
$crystal = 8000000
$baud = 19200
$hwstack = 128
$swstack = 128
$framesize = 128

'Hardware Configuration ===============================
Config Aci = Off
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc

Disable Jtag
'Disable 12c
Disable Twi

'Config Clock = Soft

Enable Interrupts
'RTC_Init
Config Timer2 = Timer , Prescale = 128
On Ovf2 Tim2_isr
Enable Ovf2
Assr.as2 = 1 'Timer2 in asynchronous mode





$lib "Lcd4e2.lib"
Config Lcd = 40 * 4

Mcusr = &H80

Ddrd = &B10110010
Ddrb = &B11111111
Ddrc = &B00111111
Ddra = &B00000000



Dim ___lcde As Byte


Dim Second As Byte
Dim Minut As Byte
Dim Hour As Byte
Dim Sec_flag As Byte
Dim Min_flag As Byte


Do

___lcde = 0

'Cls
Cursor Off
___lcde = 1
'Cls
Cursor Off
___lcde = 0
Locate 1 , 1
Lcd " CLOCK SYSTEM "

Locate 2 , 1
Lcd "HOUR " ; Hour


___lcde = 1
Locate 1 , 1
Lcd "MINUTS " ; Minut

Locate 2 , 1
Lcd "SECOND " ; Second




Loop

End



Tim2_isr:
Incr Second

If Second > 59 Then
Second = 0
Incr Minut
End If

If Minut > 59 Then
Minut = 0
Incr Hour
End If

If Hour > 23 Then
Hour = 0
End If
Sec_flag = 1
Return



(BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.8 )
Back to top
View user's profile
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Tue Nov 10, 2015 8:32 am    Post subject: Reply with quote

the fuse settings are:
24 D9
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1934

blank.gif
PostPosted: Tue Nov 10, 2015 8:54 am    Post subject: Re: Timer2 not working in real hardware.. Reply with quote

MOD BY ADMIN


Would you mind to leave your religious stuff out of the forum? I'm a infidel and I feel insulted.


#ADMIN : This forum is not for sharing and discussing religion, politics and the weather. It also means that references to gods, prophets and other religious matters may not be posted. There are zillions forum where you can do that, but not here. Of course the exception is when you make something electronic with BASCOM like an electronic vote system or compass that shows you the east.
Back to top
View user's profile
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Tue Nov 10, 2015 6:24 pm    Post subject: Reply with quote

as it has been MOD now lets come to the business..
Back to top
View user's profile
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Wed Nov 11, 2015 6:34 am    Post subject: Reply with quote

Ok it GOT it now lets come to my real problem
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2130

netherlands.gif
PostPosted: Wed Nov 11, 2015 8:30 pm    Post subject: Reply with quote

Try this.
If it's not working then most likely you have a problem with the hardware.
Are you using something like a breadboard? won't work on that (low freq crystal).

Code:

$regfile = "m16adef.dat"

$crystal = 8000000
$baud = 19200
$hwstack = 40
$swstack = 40
$framesize = 40


Enable Interrupts

'[now init the clock]
Config Date = Mdy , Separator = /                          ' ANSI-Format

Config Clock = Soft                                         'this is how simple it is
'The above statement will bind in an ISR so you can not use the TIMER anymore!

'assign the date to the reserved date$
'The format is MM/DD/YY
Date$ = "11/11/05"

'assign the time, format in hh:mm:ss military format(24 hours)
'You may not use 1:2:3 !! adding support for this would mean overhead
'But of course you can alter the library routines used

Time$ = "23:59:50"
Do
    Waitms 500
    Print Date$ ; Spc(3) ; Time$
Loop
end
 

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Thu Nov 12, 2015 5:34 pm    Post subject: Reply with quote

As I said earlier I dont want the time/date to be displayed I just want the counts of minuts..
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 733

poland.gif
PostPosted: Sat Nov 14, 2015 10:36 am    Post subject: Reply with quote

Code:
$regfile = "m16adef.dat"

$crystal = 8000000
$baud = 19200
$hwstack = 40
$swstack = 40
$framesize = 40




Config Clock = Soft
'this create Int for Timer2 and hidden variables
'variables _sec, _min, _hour

' *** You can access them directly so where is the problem? ***

Dim Old_sec As Byte
Dim Old_min As Byte

 Enable Interrupts


Do

  'if mark for running time is needed

  If Old_sec <> _sec Then
      Old_sec = _sec

     'this code is fired every second (if needed)

  End If

  If Old_min <> _min Then
      Old_min = _min

     'this code is fired every minute (if needed)

  End If



 ' *** AT ANY MOMENT YOU CAN SET VARIABLES TO ZERO ***

 ' _sec = 0
 ' _min = 0
 ' _hour = 0


Loop
End
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 Unsupported versions 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