Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

synchronus clock

 
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
Arera

Bascom Member



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

germany.gif
PostPosted: Thu Mar 27, 2008 6:26 pm    Post subject: synchronus clock Reply with quote

Hi all!

Is there a way to run the clock with the seconds ticked by timer1? Instead of 32kHz christal?
Itīs easy to generat an 1s interrupt with timer1, but can I use that to inrease the syssec?

My idea:

config clock = user
.
.
.
on timer1isr:
incr syssec
return
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Thu Mar 27, 2008 8:58 pm    Post subject: Reply with quote

Hi,

See my post in this thread:
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=3846

Best regards,

Luciano
Back to top
View user's profile
Arera

Bascom Member



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

germany.gif
PostPosted: Thu Mar 27, 2008 11:01 pm    Post subject: Reply with quote

OK, thatīs half the way...
to get Timer1 to to do something every second is not my main problem.
I would like to use all the little helpers from the async clock, e.g. _day , _month, _year , _sec, _hour, _min, SECELAPSED, syssecelapsed.
But with NO 32kHz crystal. Instead Iīd like to use the internal RC oszilator to clock the softwareclock Confused
syssec is the place to read the elapsed second from, but itīs not possible to write to syssec in the timer1 ISR. Is there an other variable to be inreased there?
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Fri Mar 28, 2008 10:00 am    Post subject: Reply with quote

Hi,

Used AVR chip?
Used clock? (8 MHz)?
Which timers are used by your application?

Best regards,

Luciano
Back to top
View user's profile
Arera

Bascom Member



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

germany.gif
PostPosted: Fri Mar 28, 2008 10:54 am    Post subject: Reply with quote

mega8
int RC clock, 1, 2, 4, or 8MHz possible
no timer used yet.

Iīve created a universal modul with 4 inputs, 3 relays. LCD or RS232 as optional feature. PB6 and PB7 are hardware IOs, so no async Timer2 usage is possible.

Shure itīs possible to use your very good "timer1 increases second_count".
I just asked myself why not to use the BASCOM sofware clock features.
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Fri Mar 28, 2008 11:42 am    Post subject: Reply with quote

Hi,

Tested with an ATmega16. Should work also with an ATmega8 without changes.

Best regards,

Luciano

Code:
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600

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

Config Clock = Soft
Config Date = Dmy , Separator = .
Date$ = "28.03.08"
Time$ = "23:59:45"

' ======================================================
'  Timer1 initialization
'
'  Mode: Clear Timer1 on Compare Match (CTC mode TOP = OCR1A)
'  System clock: 8 MHz
'  Clock source: I/O Clock / 256

TCCR1A = &H00 'See datasheet for details
TCCR1B = &H0C 'See datasheet for details

' In CTC mode the counter is cleared to zero when
' the counter value (TCNT1) matches OCR1A.
' We will load the value 0x7A12 (31250) in OCR1A so that
' we will have an interrupt every second.

OCR1AH = &H7A 'Set OCR1A.
OCR1AL = &H12 'Set OCR1A.

On Oc1a Oc1a_isr Nosave
Enable Compare1a

' Reset the Timer1 count
TCNT1H = &H00      'Set Timer1 count to 0
TCNT1L = &H00      'Set Timer1 count to 0

' ======================================================

' ======================================================
' This code will free the resources used by the Bascom soft clock
ASSR= &H00    
TCCR2= &H00
TIMSK.TOIE2 = 0 'Timer2 Overflow Interrupt disabled
' ======================================================

Enable Interrupts

Print "Hello!"

Do

   Print Date$ ; "  " ; Time$
   Waitms 250

Loop

End

' ======================================================
' Timer1 Compare Match Interrupt service routine
Oc1a_isr:

!call _Soft_clock

Return
' ======================================================
Back to top
View user's profile
Arera

Bascom Member



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

germany.gif
PostPosted: Fri Mar 28, 2008 12:32 pm    Post subject: Reply with quote

YES!
Thatīs exactly what I was lookig for!

BTW: Why do you know almost erverything, and how can you spend time on helping all of us? Are you locked up in a dungeon? Do You need help? Very Happy
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Fri Mar 28, 2008 1:11 pm    Post subject: Reply with quote

Arera wrote:
Do You need help? Very Happy

Idea Just a "thank you" in your reply is enough.
Back to top
View user's profile
Arera

Bascom Member



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

germany.gif
PostPosted: Fri Mar 28, 2008 1:29 pm    Post subject: Reply with quote

I hope you didnīt get me wrong! I tried to be funny Embarassed
Quote:
Why do you know almost erverything
was meant to be a big "thank you" and a compliment!
Thank you!
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
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