Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 01:54 30 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : RTC Problem

     Page 2 of 2    
Author Message
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 10:27am 20 Oct 2014
Copy link to clipboard 
Print this post

  WhiteWizzard said   Brilliant.
Now can you sample 4 cycles (reduce the sleep time to something like 2 seconds) i.e. grab about 10seconds of sample and send the screen shot.

I don't need to see the I2C detail, but as long as I can see the INT pin level and the 'test' pin levels and their relative timings then that would be helpful (Leave I2C connected - will just be 'blips' in the screen grab).

Thanks Jed . . . .


WW

I would but even at 1 sec there is not enough resolution you can't see the timings
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5905
Posted: 12:53pm 20 Oct 2014
Copy link to clipboard 
Print this post

Your RTC routines seem to be different to mine.

' PCF8563 RTC used as a timed interrupt
' TassyJim 12 OCT 2014


DIM RTCbuffer(16)
PCF8563address = &h51

' r = setRTC() ' only do this if the MicroMite clock has been set first
RTC GETTIME
PRINT "Startup at ";TIME$;" ";DATE$

I2C OPEN 400, 200 ' Enable I2C. use slow speeds for long leads
PAUSE 20

r=setRTCint(10,2) ' set RTC to interrupt every 10 seconds
'r=setRTCint(1,3) ' set RTC to interrupt every 1 minutes
'r=setRTCalarm(16,01) ' set the once a day alarm


'SETPIN 5, INTL, doread ' set the interupt routine
doread ' do an initial reading

DO
CPU sleep
doread
k$=INKEY$
'if k$="C" or k$="c" then r = setRTC()

LOOP UNTIL k$=CHR$(27)

END

SUB doread
r= clearRTCalarm()
'do all your routines
RTC GETTIME ' keep the MicroMite time correct
PRINT TIME$;" etc"
END SUB


FUNCTION setRTCint(count,scale)
' scale: 2 = seconds, 3 = minutes
LOCAL t_ctrl
t_ctrl = 128 + scale
I2C WRITE PCF8563address,0,1, &H00 ' set the starting address for a read
I2C READ PCF8563address,0,16,RTCbuffer(0)
I2C WRITE PCF8563address,0,2, &H01, &H11
I2C WRITE PCF8563address,0,3, &H0E, t_ctrl, count' timer control register
setRTCint=RTCbuffer(1)
END FUNCTION

FUNCTION setRTCalarm(hour, minute,day,WkDay)
LOCAL alarmH,alarmM,alarmD,alarmWD
alarmH=INT(hour/10)*16+(hour MOD 10)
'alarmH=128 ' not used (once an hour)
alarmM=INT(minute/10)*16+(minute MOD 10)
'alarmD=int(day/10)*16+(day mod 10)
alarmD=128 ' not used (every day)
'alarmWD=WkDay
alarmWD=128 ' not used (every day)
I2C WRITE PCF8563address,0,1, &H00
I2C READ PCF8563address,0,16,RTCbuffer(0)
I2C WRITE PCF8563address,0,2, &H01, &H12
I2C WRITE PCF8563address,0,5, &H09, alarmM, alarmH,alarmD, alarmWD
setRTCint=RTCbuffer(1)
END FUNCTION

FUNCTION setRTC()
' set the RTC to MicroMite time
LOCAL newtime$, year, month, day, hour, min, sec
newtime$= TIME$ ' make a copy to stop time changing while we set the clock
year = VAL(MID$(DATE$,9))
month = VAL(MID$(DATE$,4,2))
day = VAL(MID$(DATE$,1,2))
hour = VAL(MID$(newtime$,1,2))
min = VAL(MID$(newtime$,4,2))
sec = VAL(MID$(newtime$,7,2))
RTC SETTIME year,month,day,hour,min,sec
END FUNCTION

FUNCTION clearRTCalarm()
' two bits indicate if alarm or timer triggered the interupt
' we clear them both
LOCAL x
I2C WRITE PCF8563address,0,1, &H00
I2C READ PCF8563address,0,2,RTCbuffer(0)
x = (RTCbuffer(1) AND &H13)
I2C WRITE PCF8563address,0,2, &H01, x
clearRTCalarm=RTCbuffer(1) AND &H0C ' 8 = alarm and 4 = timer
END FUNCTION


This code runs happily on a 28 pin MX150
It wakes the uMite every 10 seconds.

The interrupt from the RTC clock is attached to pin 16 with a 4.7k resistor to VCC

Jim
VK7JH
MMedit   MMBasic Help
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024