chVTGetSystemTime() restarts every 4s !!!!

Discussions and support about ChibiOS/RT, the free embedded RTOS.
jonesrayan
Posts: 16
Joined: Sat Oct 01, 2016 5:07 pm

chVTGetSystemTime() restarts every 4s !!!!

Post by jonesrayan »

Hi, tehre i'm faceing a big problem. the chVTGetSystemTime() restarts every 4 seconds !!!
i want the chVTGetSystemTime() don't restart.
i read a post who hase the same problem and Mr Giovanni said, that the tickless mode should be disabled ??? but i d'ont know how to find the option and diseable it
please help
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chVTGetSystemTime() restarts every 4s !!!!

Post by Giovanni »

Hi,

System time is a 32 bits variable, always incremented, it will reset to zero after a while anyway. What you can do is to increase the interval by lowering the system tick frequency.

Giovanni
jonesrayan
Posts: 16
Joined: Sat Oct 01, 2016 5:07 pm

Re: chVTGetSystemTime() restarts every 4s !!!!

Post by jonesrayan »

Do you mean that i change the #define CH_CFG_ST_FREQUENCY 1000 to 10 ??
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chVTGetSystemTime() restarts every 4s !!!!

Post by Giovanni »

Yes but note that the systick frequency affects the resolution of the system timers and timeouts, are you fine with this?

Anyway, you should NOT rely on system time not wrapping to zero, I believe that if you are trying to do something in the wrong way.

Giovanni
jonesrayan
Posts: 16
Joined: Sat Oct 01, 2016 5:07 pm

Re: chVTGetSystemTime() restarts every 4s !!!!

Post by jonesrayan »

Hi, i tried to change CH_CFG_ST_FREQUENCY 1000 to 10 but the chVTGetSystemTime() still reseting :(
i'm using the arduino library for arm.
how do i resolve that please
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chVTGetSystemTime() restarts every 4s !!!!

Post by Giovanni »

It is a counter it is meant to reset after a while, you can't fix that.

Giovanni
jonesrayan
Posts: 16
Joined: Sat Oct 01, 2016 5:07 pm

Re: chVTGetSystemTime() restarts every 4s !!!!

Post by jonesrayan »

ok, i have another probleme using chThdSleepMicroseconds();

on arduino i did
this code
void setup() {
// initialize digital pin 7 as an output.
pinMode(7, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
delayMicroseconds(100);
digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
delayMicroseconds(100);}

i see on the oscilloscope the time between faling edje and rising edje is exactly 100 microseconde

with chibios kernel i did this
// Example to demonstrate thread definition, semaphores, and thread sleep.
#include <ChibiOS_ARM.h>

// The LED is attached to pin 13 on Arduino.
const uint8_t LED_PIN = 7;

// Declare a semaphore with an inital counter value of zero.
SEMAPHORE_DECL(sem, 0);
//------------------------------------------------------------------------------
// Thread 1, turn the LED off when signalled by thread 2.

// 64 byte stack beyond task switch and interrupt needs
static THD_WORKING_AREA(waThread1, 64);

static THD_FUNCTION(Thread1, arg) {

while (!chThdShouldTerminateX()) {
// Wait for signal from thread 2.
chSemWait(&sem);

// Turn LED off.
digitalWrite(LED_PIN, LOW);
}
}
//------------------------------------------------------------------------------
// Thread 2, turn the LED on and signal thread 1 to turn the LED off.

// 64 byte stack beyond task switch and interrupt needs
static THD_WORKING_AREA(waThread2, 64);

static THD_FUNCTION(Thread2, arg) {
pinMode(LED_PIN, OUTPUT);
while (1) {
digitalWrite(LED_PIN, HIGH);


chThdSleepMicroseconds(100);

// Signal thread 1 to turn LED off.
chSemSignal(&sem);

chThdSleepMicroseconds(100);
}
}
//------------------------------------------------------------------------------
void setup() {

chBegin(chSetup);
// chBegin never returns, main thread continues with mainThread()
while(1) {
}
}
//------------------------------------------------------------------------------
// main thread runs at NORMALPRIO
void chSetup() {

// start blink thread
chThdCreateStatic(waThread1, sizeof(waThread1),
NORMALPRIO + 2, Thread1, NULL);

chThdCreateStatic(waThread2, sizeof(waThread2),
NORMALPRIO + 1, Thread2, NULL);

}
//------------------------------------------------------------------------------
void loop() {
// not used
}

on osciloscope the time between faling edje and rising edje is 1ms

i change the tick frequacy but it still doesn't work. how can resolve that please
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chVTGetSystemTime() restarts every 4s !!!!

Post by Giovanni »

Hi,

Times are approximated to the system tick resolution, if your systick frequency is 1000Hz then your resolution is 1mS, you can't wait for 100uS.

The arduino function works because it is implemented as a software loop, the ChibiOS function counts interrupts and does not do polling during the wait thus freeing time for other threads.

Giovanni
jonesrayan
Posts: 16
Joined: Sat Oct 01, 2016 5:07 pm

Re: chVTGetSystemTime() restarts every 4s !!!!

Post by jonesrayan »

thaks for this anwer but i change the systick frequency from 1000 to 1000000 , but the resolution is always 1m. i have arduino due 32bit arm cortex m3.
please how can i control the microseconds
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chVTGetSystemTime() restarts every 4s !!!!

Post by Giovanni »

Hi,

Increasing the resolution to 1000000 means that you get 1000000 interrupts per second, way way to much for an AVR, 1000Hz should be considered a limit for AVR. If you need such high resolutions you need to use and HW timer or the polled delay function.

Giovanni
Post Reply