View previous topic :: View next topic |
Author |
Message |
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Thu Mar 27, 2008 6:26 pm Post subject: synchronus clock |
|
|
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 |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Thu Mar 27, 2008 11:01 pm Post subject: |
|
|
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
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 |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Fri Mar 28, 2008 10:00 am Post subject: |
|
|
Hi,
Used AVR chip?
Used clock? (8 MHz)?
Which timers are used by your application?
Best regards,
Luciano |
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Fri Mar 28, 2008 10:54 am Post subject: |
|
|
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 |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Fri Mar 28, 2008 11:42 am Post subject: |
|
|
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 |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Fri Mar 28, 2008 12:32 pm Post subject: |
|
|
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? |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Fri Mar 28, 2008 1:11 pm Post subject: |
|
|
Arera wrote: | Do You need help? |
Just a "thank you" in your reply is enough. |
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Fri Mar 28, 2008 1:29 pm Post subject: |
|
|
I hope you didnīt get me wrong! I tried to be funny
Quote: | Why do you know almost erverything | was meant to be a big "thank you" and a compliment!
Thank you! |
|
Back to top |
|
|
|