Page 1 of 2

Question to Giovanni

Posted: Tue Feb 16, 2016 7:55 pm
by RTOSman
Hello Mr Giovanni. i use chibios librrary for arduino and i find it powerful i tried many application on arduino uno board. but arduino board has not a real time clock. the timer of arduino it's not really accurate, so i want to use RTC DS3231. my question is how to make the function chThdSleepMilliseconds or ThreadSleepMicroseconds work with RTC DS3231
Please answer :)

Re: Question to Giovanni

Posted: Tue Feb 16, 2016 8:22 pm
by Giovanni
The OS does not need necessarily an RTC, it just need a periodic interrupt, any periodic interrupt source can be used.

Giovanni

Re: Question to Giovanni

Posted: Tue Feb 16, 2016 8:34 pm
by RTOSman
The problem is the chVTGetSystemTimeX() not accurate on the arduini uno. i did this code

Code: Select all

while (1)
   {
   start += 10;
   Serial.println(chVTGetSystemTimeX()/1000);
   }


i compare the values of chVTGetSystemTimeX()/1000) with my stopwatch of my phone. after 3 minutes the values of chVTGetSystemTimeX()/1000) not same with the values of my stop watch. 400 seconds from chVTGetSystemTimeX() and 399 from the stopwatch. and overt the time i had 500 497.

i did som modificaion to get 1000 ticks = 1000 ms in board.c

Code: Select all

#include "ch.h"
#include "hal.h"
CH_IRQ_HANDLER(TIMER0_COMPA_vect) {
  CH_IRQ_PROLOGUE();
  OCR0A += 250; // ****** ADD THIS LINE FOR 1.000 MS TICK************
  chSysLockFromISR();
  chSysTimerHandlerI();
  chSysUnlockFromISR();
  CH_IRQ_EPILOGUE();
}
/*
 * Board-specific initialization code.
 */
void boardInit(void) {
  /*
   * Timer 0 setup.
   */
  OCR0A = 128;
  TIMSK0  |= (1 << OCIE0A);                               /* IRQ on compare.  */
  TCCR0A &= ~((1 << WGM00) | (1 << WGM01)); // ****** ADD THIS LINE FOR 1.000 MS TICK************
}


and i change this
#define CH_CFG_ST_FREQUENCY 1000 // WHG.


so please MR Giovanni, how do i to get exactly the real time please. i use arduino uno.
find me a solution :(

Re: Question to Giovanni

Posted: Tue Feb 16, 2016 8:37 pm
by Giovanni
Just set CH_CFG_ST_FREQUENCY to the exact timer frequency and you will have the best approximation. Alternatively provide a system tick from some external timer to an interrupt pin.

Giovanni

Re: Question to Giovanni

Posted: Tue Feb 16, 2016 8:53 pm
by RTOSman
how do i know the exact timer frequency value of CH_CFG_ST_FREQUENCY.
i have arduino uno
please

Re: Question to Giovanni

Posted: Tue Feb 16, 2016 9:28 pm
by RTOSman
Giovanni you didn't answer me !!!

Re: Question to Giovanni

Posted: Tue Feb 16, 2016 9:55 pm
by Giovanni
You should not expect answers in real time...

I don't have Arduino one and cannot provide specific support, what I can do is to give generic advice. Studying documentation about your platform is up to you.

Giovanni

Re: Question to Giovanni

Posted: Tue Feb 16, 2016 10:14 pm
by RTOSman
but you did a library for arduino !!!!

Re: Question to Giovanni

Posted: Tue Feb 16, 2016 10:26 pm
by Giovanni

Re: Question to Giovanni

Posted: Tue Feb 16, 2016 11:09 pm
by RTOSman
Yes this library