Highspeed Timer(Counter)


I don't see whats wrong with the Linux function gettimeofday() which can give you accuracy down to 1 μsec / 1 Mhz, but also gives seconds since epoch if you want something a bit slower.
 
Squidge said:
I don't see whats wrong with the Linux function gettimeofday() which can give you accuracy down to 1 μsec / 1 Mhz, but also gives seconds since epoch if you want something a bit slower.

I did have that before trying the rtc in libcastor seemed to work too. Although I think SDL's time functions are based off it, so if SDL timing is off gettimeofdaymay be off too. Like the example exophase gave, maybe something isnt right in the kernel.
 
Last edited by a moderator:
RTC and timer are different things. RTC remembers wall clock when the unit is off (seems to work fine), timer does high precision stuff (also works fine). The problem is with buggy code in some system calls that causes accuracy drop to ~8ms.

Squidge said:
I don't see whats wrong with the Linux function gettimeofday() which can give you accuracy down to 1 μsec / 1 Mhz
See post #6 of this thread.
 
Last edited by a moderator:
Hey Pickle. Do you have the Pollux manual? I could send it to you if you don't. It'll explain how to use the timers.
 
Exophase said:
Hey Pickle. Do you have the Pollux manual? I could send it to you if you don't. It'll explain how to use the timers.

I dont have the manual.
Seems you cant receive any more PM's Pop in on IRC if have some time.
 
Last edited by a moderator:
That's odd, I should have room there. I cleared some more, so you might want to try again. I'm not really on IRC very much now and you always seemed to miss me before so that might not work. If I don't hear from you I'll PM you my e-mail address.
 
Exophase said:
That's odd, I should have room there. I cleared some more, so you might want to try again. I'm not really on IRC very much now and you always seemed to miss me before so that might not work. If I don't hear from you I'll PM you my e-mail address.

dont worry about it ;-)
 
Last edited by a moderator:
Pickle said:
Exophase said:
That's odd, I should have room there. I cleared some more, so you might want to try again. I'm not really on IRC very much now and you always seemed to miss me before so that might not work. If I don't hear from you I'll PM you my e-mail address.

dont worry about it ;-)

Did anyone ever figure out how to get a reliable clock down to the millisecond (or better) range? I'd like to calculate how many milliseconds have passed since the last frame, the libcastor lc_gettime() function doesn't appear to be nearly accurate enough.
 
Last edited by a moderator:
satacoy said:
Did anyone ever figure out how to get a reliable clock down to the millisecond (or better) range? I'd like to calculate how many milliseconds have passed since the last frame, the libcastor lc_gettime() function doesn't appear to be nearly accurate enough.

yeah dont use lc_gettime, like it was said that is for RTC timing.
Im looking into using some timer hw directly and add it to libcastor.
 
Last edited by a moderator:
Pickle said:
satacoy said:
Did anyone ever figure out how to get a reliable clock down to the millisecond (or better) range? I'd like to calculate how many milliseconds have passed since the last frame, the libcastor lc_gettime() function doesn't appear to be nearly accurate enough.

yeah dont use lc_gettime, like it was said that is for RTC timing.
Im looking into using some timer hw directly and add it to libcastor.

is there any progression/update on this ? ...

if not, may someone send me that pollux manual? :D
 
Last edited by a moderator:
crow_riot said:
Pickle said:
satacoy said:
Did anyone ever figure out how to get a reliable clock down to the millisecond (or better) range? I'd like to calculate how many milliseconds have passed since the last frame, the libcastor lc_gettime() function doesn't appear to be nearly accurate enough.

yeah dont use lc_gettime, like it was said that is for RTC timing.
Im looking into using some timer hw directly and add it to libcastor.

is there any progression/update on this ? ...

if not, may someone send me that pollux manual? :D

I got as far as to read the active timer, but setting the others hasnt worked. Ive put on the side for now, ive lost interest for now
 
Last edited by a moderator:
I got as far as to read the active timer, but setting the others hasnt worked. Ive put on the side for now, ive lost interest for now

hm no good news then... i'll try to do my best and get my fingers dirty finding a solution. did exophase (?) send u the pollux manual? would be nice to share if you are allowed to ...
 
crow_riot said:
I got as far as to read the active timer, but setting the others hasnt worked. Ive put on the side for now, ive lost interest for now

hm no good news then... i'll try to do my best and get my fingers dirty finding a solution. did exophase (?) send u the pollux manual? would be nice to share if you are allowed to ...

I'd love a copy of any documentation going too if it's OK to distribute it. OLED controller and NAND datasheets were easy enough to find, but I can't find any SoC docs. :)
 
Last edited by a moderator:
pseudonym404 said:
I'd love a copy of any documentation going too if it's OK to distribute it. OLED controller and NAND datasheets were easy enough to find, but I can't find any SoC docs. :)

didn't get one either. i was desperately searching for a manual, but no chance to find. i also asked a friend of mine in china to check out if he can reach mesdigital.com - but not even from there ;)
 
Last edited by a moderator:
MES won't give you one anyway. They do hand them out in exchange for large sums of money, but they even only do that under NDA.
 
Orkie said:
MES won't give you one anyway. They do hand them out in exchange for large sums of money, but they even only do that under NDA.

nda ... that makes sense in a way :)
 
Last edited by a moderator:
here's the code that I use in PicoDrive:

Code:
#define TIMER_BASE3 0x1980
#define TIMER_REG(x) memregl[(TIMER_BASE3 + x) >> 2]

void ptimer_init(void)
{
        TIMER_REG(0x44) = 0x922;
        TIMER_REG(0x40) = 0x0c;
        TIMER_REG(0x08) = 0x6b;
}

unsigned int ptimer_get_ticks_us(void)
{
        TIMER_REG(0x08) = 0x4b;  /* run timer, latch value */
        return TIMER_REG(0);
}

void ptimer_cleanup(void)
{
        TIMER_REG(0x40) = 0x0c;
        TIMER_REG(0x08) = 0x23;
        TIMER_REG(0x00) = 0;
        TIMER_REG(0x40) = 0;
        TIMER_REG(0x44) = 0;
}

This is accurate 32bit microsecond timer, using one of (currently) free SoC timers. Since it's 32bit it will wrap every 4295 seconds, so don't cause deadlocks for someone playing for more than a hour and a bit :)

Also be nice and don't forget to call ptimer_cleanup() to free the timer on exit.

oh BTW 'memregl' is standard
Code:
volatile unsigned int *memregl;
int memdev = open("/dev/mem", O_RDWR);
memregl = mmap(0, 0x20000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0xc0000000);
 
:blink:

don't know how to thank u! that's really great to have. i was going such a naive/wrong way - since i'm coming from windows - i'm astonished how simple and easy things can be with direct memory access :)
 
Back
Top