View previous topic :: View next topic |
Author |
Message |
hobby
Joined: 12 Apr 2004 Posts: 109 Location: Brussels
|
Posted: Thu Nov 20, 2014 12:02 am Post subject: config clock = soft |
|
|
Hello All,
I have small problem with this code:
Code: |
$regfile = "m328pdef.dat"
$crystal = 16000000
$baud = 19200
$hwstack = 64
$swstack = 64
$framesize = 64
Enable Interrupts
Config Date = Mdy , Separator = / ' ANSI-Format
Config Clock = Soft 'this is how simple it is
Date$ = "11/11/05"
Time$ = "23:59:50"
Do
Waitms 500
Print Date$ ; Spc(3) ; Time$
Loop
|
The time speed very quickly like 1second = few minutes.
I use external crystal (16Mhz) (Arduino Nano V3.0).
Thanks for your help.
Olivier
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
|
Back to top |
|
|
hobby
Joined: 12 Apr 2004 Posts: 109 Location: Brussels
|
Posted: Thu Nov 20, 2014 1:51 am Post subject: |
|
|
I use MCS Bootloader.
The fuse bit set is:
Thanks
Olivier |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Thu Nov 20, 2014 3:47 am Post subject: |
|
|
Do you have a 32.786 kHz clock crystal and pins 9/10 (B.6/B.7)?
Does the clock crystal need capacitors? |
|
Back to top |
|
|
hobby
Joined: 12 Apr 2004 Posts: 109 Location: Brussels
|
Posted: Thu Nov 20, 2014 9:34 am Post subject: |
|
|
Hi,
No, i have 16Mhz crystal connected on PB6 & PB7.
In help is write "For the USER mode you need to connect a special low frequency crystal with a value of 32768 Hz."
But i use SOFT !.
If i need the connect the 32Khz crystal, is not full software clock, it is a mixture between software and hardware.
I thought how 'SOFT' was simply a software-based time.
I do not understand!
Thanks
Olivier |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Thu Nov 20, 2014 10:53 am Post subject: |
|
|
Quote from Wiki
Quote: | The compiler also creates an ISR that gets updates once a second. This works for AVR chips which can be asynchronously clocked from the TOSC1/2 pins.
TOSC1 = Timer Oscillator Pin 1
TOSC2 = Timer Oscillator Pin 2 |
So I think You must connect Low Freq special Oscillator to TOSC1/2 and use Internal Oscillator 8MHz for aplication because ATmega328p don`t have separate pins for two oscillators Some chip`s have separate for XTAL and TOSC
EDIT. Yes! I try it and this works perfect with external 32kHz and internal for app.
Code: | $regfile = "m328pdef.dat"
$crystal = 8000000
'$baud = 19200
$hwstack = 64
$swstack = 64
$framesize = 64
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.1 , Rs = Portd.0 , Wr = Portc.3
Config Lcd = 20x4 'nowy sposob zapisu
'Initlcd
Cursor Off
Cls
Config Date = Mdy , Separator = / ' ANSI-Format
Config Clock = Soft 'this is how simple it is
Date$ = "11/11/05"
Time$ = "23:59:50"
Enable Interrupts
Do
Waitms 500
Locate 2 , 2
Lcd Date$ ; Spc(2) ; Time$
Loop
End |
|
|
Back to top |
|
|
hobby
Joined: 12 Apr 2004 Posts: 109 Location: Brussels
|
Posted: Fri Nov 21, 2014 11:25 pm Post subject: |
|
|
Thanks, its works.
Olivier |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Sat Nov 22, 2014 1:45 am Post subject: |
|
|
Hobby,
MWS wrote a true "soft" clock (ie without the 32.768KHz crystal) in http://mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=10176&highlight=softclock&sid=0042022df9af4a101e573a21edf39129
I have used a modified version of it similar to this:
Code: | $regfile = "m8535.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 32
$framesize = 32
$baud = 57600
'============================================
'Config SOFT/User Clock
'============================================
Config Clock = User
Config Date = Mdy , Separator = /
Dim Reload As Word , Cur_time As Long
Reload = 30005
Config Timer1 = Timer , Prescale = 256
Ocr1ah = High(reload)
Ocr1al = Low(reload)
Tccr1a = 0
Set Tccr1b.3
On Compare1a Isr_clock_tick
Enable Compare1a
Enable Interrupts
_sec = 50
_min = 4
_hour = 12
_day = 12
_month = 11
_year = 14
Cur_time = Syssec()
Do
Wait 1
Time$ = Time(cur_time) : Date$ = Date(cur_time)
Print Date$ ; " " ; Time$
Loop
End
Isr_clock_tick:
Incr Cur_time
Return
Setdate:
Return
Settime:
Return
Getdatetime:
Return |
|
|
Back to top |
|
|
|