Hello, this is odd... If you open the RTClock files, you'll see that these are the functions used to set the time. I'll test these and see if i can find what's going on.
The stdlib.h and time.h are already included in the rt library.
Hello, this is odd... If you open the RTClock files, you'll see that these are the functions used to set the time. I'll test these and see if i can find what's going on.
The stdlib.h and time.h are already included in the rt library.
This works for me...
#include <RTClock.h>
/* choose one of the available Clocks.
* I'll choose the HSE/128 that works in all boards
* people with Olimexino can choose any clock (LSE is the 32kHz).
*/
//RTClock rt(RTCSEL_LSE);
RTClock rt(RTCSEL_HSE);
//RTClock rt(RTCSEL_LSI);
//RTClock rt; // this starts HSE clock as a default.
void AlarmFunction () {
SerialUSB.println("WAKE UP!!!!");//somehow this shows up late in the USB connection. :(
//if you want an interrupt every minute...
//time_t now = rt.getTime();
//rt.setAlarmTime(now + 60);
}
struct tm time_tm, *tm_ptr;//this is a structure with date and time fields
time_t Alarm_period; //this can hold the number of seconds from 00:00:00 1/1/1970
void setup() {
pinMode(BOARD_LED_PIN, OUTPUT);//setup our alive pin.
//define My Epoch. No need to try, don't use these numbers in passwords.
time_tm.tm_sec = 0;
time_tm.tm_min = 45;
time_tm.tm_hour = 15;
time_tm.tm_mday = 27;
time_tm.tm_mon = 6;
time_tm.tm_year = 80;//years since 1900
rt.setTime(&time_tm);
rt.attachSecondsInterrupt(&toggleLED);//the led will toggle every second.
time_tm.tm_min = 47;
rt.createAlarm(&AlarmFunction, &time_tm); //ring the alarm 2 minutes later...
}
void loop() {
if (SerialUSB.available() >0) {
SerialUSB.read(); //bogus read...
tm_ptr = rt.getTime(tm_ptr);
SerialUSB.print ("time: ");
SerialUSB.print (tm_ptr->tm_hour);
SerialUSB.print (":");
SerialUSB.print (tm_ptr->tm_min);
SerialUSB.print (":");
SerialUSB.println (tm_ptr->tm_sec);
SerialUSB.print ("date: ");
SerialUSB.print (tm_ptr->tm_mday);
SerialUSB.print ("/");
SerialUSB.print (tm_ptr->tm_mon);
SerialUSB.print ("/");
SerialUSB.println ((1900 + tm_ptr->tm_year));
}
}
CAn you try this sketch?
In here time is set using the actual struct tm and not a pointer. When I try to compile your example the board goes into error state. :\
bubulindo - I added the back-quote character around your code to show the indentation.
Nice, thank you.
Thanks bubulindo, That worked.
The mistake I was doing was struct tm * tm_ptr instead of struct tm time_tm.
I tried both LSE and HSE, both works fine. Anybody compared the time accuracy of HSE and LSE?
Not yet... but I would love if someone did. :)
bubulindo, at your epoch, I was in college ;) (did I understand it correctly?)
On my board, LSE is very inaccurate - gaining about one second every hour - roughly 275ppm - very poor.
Let me give a try on HSE.
I guess so. :)
Hmm, I'm yet to give it a go testing the accuracy. I've read that lsi has really bad accuracy, but nothing about the other ones.
It is possible to calibrate them and you can always mess around with the prescaler if that helps.
It may be somehow related to the capacitance of the crystal connection, that affects its accuracy, as well as the crystals quality. I have no idea how good mine is, but considering the price I paid, I'm not expecting miracles.
HSE is loosing about 30 seconds per minute!!
Bad accuracy for LSI is expected as it is just RC without crystal stabilization.
About LSE, you are right - it must be the stray capacitance. On my board, the crystal is laid flat on the PCB which IMHO may be contributing to the stray capacitance.
But HSE - I don't understand. Some thing seriously wrong. So far I have run it only for a few minutes. let it run overnight and let us check later. probably some serious tweaking of pre-scalers will be required. Well, it could be a stray /2 somewhere.
bubulindo, I've checked your sketch (along with appropriate updates to libmaple) and found that my Mini64 board works just fine with LSE clock setting. Same is correct for Mini48 (will be submitted into HW repository later today).
phisatho
The prescaler load register powers up to a value of 0x8000. The documentation says to set it to 0x7fff for a 32K crystal. That's a difference of 31 ppm. If the load caps are not correct for the crystal that could be some more of the issue. That seems unlikely but possible.
I haven't seen a mention of setting the prescaler register in the discussion so far, but you do need to be aware of it.
The HSE source is actually the HSE speed divided by 128, which with an 8 Mhz crystal is 62,500 or about twice the clock speed of the LSE. Could explain what you are seeing.
Thanks siy.
The prescaler values are set in the software according to the manual. But because the LSI is so bad (and to be honest, because I'm planning a stopwatch with this) I decided to put in the possibility of choosing the prescaler value.
One thing I'm thinking of is checking how much overhead does the time.h add to the library compared to the bare mktime functions... it may be worth not to include time.h for the sake of space. :)
It is confirmed - HSE clock is running at half speed.
Something else I noticed is - if I set alarm to repeat every 60 seconds, it actually takes 61 seconds - both in HSE and LSE modes.
Now back to LSE. Where can I apply a correction factor for LSE clock?
I think that is yet to be done. :$ However, inside the .c files there is a calibration routine I believe. I did not test it yet.
You must log in to post.