Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

config clock = soft

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Thu Nov 20, 2014 12:02 am    Post subject: config clock = soft Reply with quote

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
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1198
Location: SYDNEY

australia.gif
PostPosted: Thu Nov 20, 2014 1:06 am    Post subject: Reply with quote

Hello hobby

Are the fuse bits set correctly
is any code in the boot loader using the timer

I do not use Bascom to create my clock interrupt I use my own ISR that lets me put other timers in the ISR and also enables me to keep in step with the NTP servers
See here
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=10604&highlight=simple+clock+using+cpu


Regards Paul
Back to top
View user's profile
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Thu Nov 20, 2014 1:51 am    Post subject: Reply with quote

I use MCS Bootloader.

The fuse bit set is:


Thanks
Olivier
Back to top
View user's profile
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 474

PostPosted: Thu Nov 20, 2014 3:47 am    Post subject: Reply with quote

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
View user's profile
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Thu Nov 20, 2014 9:34 am    Post subject: Reply with quote

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
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 699

poland.gif
PostPosted: Thu Nov 20, 2014 10:53 am    Post subject: Reply with quote

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 Sad 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
View user's profile Visit poster's website
hobby

Bascom Member



Joined: 12 Apr 2004
Posts: 109
Location: Brussels

belgium.gif
PostPosted: Fri Nov 21, 2014 11:25 pm    Post subject: Reply with quote

Thanks, its works.

Olivier
Back to top
View user's profile
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 474

PostPosted: Sat Nov 22, 2014 1:45 am    Post subject: Reply with quote

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
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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