Problem with DS_1302 used as a timer in a 8-channel Temperature Data Logging Sy
Hello everyone,
·I am building a real time data logging system for my final project. I used 8 Temperature AD592 probes, MAX1270 A/D converter and real time clock DS1302 with BS2. For data exchange and interactive control with BS2, i used PLX-DAQ to insert the desired values for sampling duration and sampling period. So, timing issues for me, are very important. I am facing some problems with DS1302. As real time clock works just fine with DS1302_Template.BS2, a code i found in this forum.
I just want to use it as a timer and read the values of hours, minutes and·seconds and use them in the program. I first initialize time using this code...
reg = $80········· ' Point to register 80h
ioByte = %00000000 ' starts the clock by clearing the Clock Halt bit and clears the Seconds to "00"
GOSUB RTC_Out····· ' Send Command
reg = $84········· ' Point to register 84h
ioByte = %00000000 ' initializes the clock in 24 hour mode and clear the hours to "00"
GOSUB RTC_Out····· ' Send Command
reg = $82········· ' Point to register 80h
ioByte = %00000000 ' starts the clock by clearing the Clock Halt bit and clears the minutes to "00"
GOSUB RTC_Out····· ' Send Command
...and·then a subroutine Get_time to get the values for hours, secs, minutes.
· HIGH CS1302·························· ' Select DS1302
· SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
· SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins, hrs]
· LOW CS1302
·I found from Nuts & Volts an article named "Column #33: It’s Time to Get Real Using the Dallas Semiconductor 1302 – Part 1" to read elapsed minutes correctly, due to the BCD format that DS1302 uses to store values.
elapsed_minutes=((hrs10& %11)*600)+(hrs01*60)+(mins10*10)+ mins01
For the project seconds accuracy is needed. So logically the corversion will be...
elapsed_seconds=((hrs10& %11)*36000)+(hrs01*3600)+(mins10*600)+(mins01*60)+(secs10*10)+ secs01
The·programm works fine with minutes and seconds, but when using these equations, i thing·there is problem reading hours correctly from DS_1302.·.·What could be wrong???
Sorry if i got you bored with the details...:-) Any help and suggestions·would be valuable for me...
I have also·posted the code for anyone interested...
Thank you in advance,
Christofer
·I am building a real time data logging system for my final project. I used 8 Temperature AD592 probes, MAX1270 A/D converter and real time clock DS1302 with BS2. For data exchange and interactive control with BS2, i used PLX-DAQ to insert the desired values for sampling duration and sampling period. So, timing issues for me, are very important. I am facing some problems with DS1302. As real time clock works just fine with DS1302_Template.BS2, a code i found in this forum.
I just want to use it as a timer and read the values of hours, minutes and·seconds and use them in the program. I first initialize time using this code...
reg = $80········· ' Point to register 80h
ioByte = %00000000 ' starts the clock by clearing the Clock Halt bit and clears the Seconds to "00"
GOSUB RTC_Out····· ' Send Command
reg = $84········· ' Point to register 84h
ioByte = %00000000 ' initializes the clock in 24 hour mode and clear the hours to "00"
GOSUB RTC_Out····· ' Send Command
reg = $82········· ' Point to register 80h
ioByte = %00000000 ' starts the clock by clearing the Clock Halt bit and clears the minutes to "00"
GOSUB RTC_Out····· ' Send Command
...and·then a subroutine Get_time to get the values for hours, secs, minutes.
· HIGH CS1302·························· ' Select DS1302
· SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
· SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins, hrs]
· LOW CS1302
·I found from Nuts & Volts an article named "Column #33: It’s Time to Get Real Using the Dallas Semiconductor 1302 – Part 1" to read elapsed minutes correctly, due to the BCD format that DS1302 uses to store values.
elapsed_minutes=((hrs10& %11)*600)+(hrs01*60)+(mins10*10)+ mins01
For the project seconds accuracy is needed. So logically the corversion will be...
elapsed_seconds=((hrs10& %11)*36000)+(hrs01*3600)+(mins10*600)+(mins01*60)+(secs10*10)+ secs01
The·programm works fine with minutes and seconds, but when using these equations, i thing·there is problem reading hours correctly from DS_1302.·.·What could be wrong???
Sorry if i got you bored with the details...:-) Any help and suggestions·would be valuable for me...
I have also·posted the code for anyone interested...
Thank you in advance,
Christofer