Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
View: 2643|Reply: 1

The best way to get microseconds precision time?

[Copy link]

1

Threads

3

Posts

65

Credits

Registered member

Rank: 2

Credits
65
Post time 2016-10-20 09:09:38 | Show all posts |Read mode
Hey folks,

It's my first time here. Cheers o/

Well, I have one Orange Pi Plus 2 and I am trying to make it read from one HC-SR04 utrassonic sensor. And it sends the measured distance by turning its echo port high by one instant of time. This time is proportional to the measured distance.
To work this out, I have a interruption callback using WereCatf's WiringOP fork, that works good but I can't get correct timing because the function I am using don't give me a good and accurate values.
I've used clock_gettime() with CLOCK_REALTIME but it have some milliseconds increments every second (even if I run OPi for performance) and I don't want more than 58 microsecond increments, because this is the time for each centimeter to be measured by the sensor (more info here https://docs.google.com/document ... 2qR4vP8saG73rE/edit).

So do you guys know any way to get one time with microseconds accurace? I saw in the Allwinner H3 documentation something about it's hardware Timers but that is completely unclear to me on how to setup and make it work properly.


Thank you and sorry about my english.

4

Threads

8

Posts

66

Credits

Registered member

Rank: 2

Credits
66
Post time 2017-9-16 13:24:13 | Show all posts
Edited by DarkSorrow at 2017-9-16 13:29

As you mentioned in your last paragraph you will have to take access of hardware timer.
Though I have never done this on Orange Pi or any Allwinner processor, I had done once for completely different SBC.
It is very similar to bare-metal programming like that of micro-controllers.
You will have to use mmap system call to map/get physical address of peripheral's (timer's) register address. Once you get the proper physical address of the necessary registers it is just matter of setting proper values. You will also have to write interrupt handler and register interrupts if you want interrupt driven approach or alternatively you can also pool for flag in while loop (very inefficient).
Refer page 156 of Allwinner H3 documentation to get Timer's register map.
You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2019-8-24 05:55 GMT+8 , Processed in 0.026654 second(s), 22 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list