I have a solution that seems to work for our purposes.
Thanks for all the suggestions and help. I am going to keep learning the
PRUs because I think we'll need them in a more sophisticated version of the
product.
This is a great community and I appreciate the patience with this neophyte
to BB.
Here's the C code with some parts eliminated for simplicity.
// ********************* ReadDetectors **********************************
void ReadDetectors(int TimeToRead)
{
// initialize local variables
struct timeval tv_start; //start time
struct timeval tv_now; // current time
long total_elapsed_time_us;
long start_secs;
long last_secs;
long last_usecs;
long elapsed_us;
int KeepReading = 1;
gettimeofday(&tv_now,NULL);
start_secs = tv_now.tv_sec;
last_usecs = tv_now.tv_usec;
elapsed_us = 0;
total_elapsed_time_us = 0;
while (KeepReading)
{
// READ SENSORS CODE IS HERE. REMOVED FOR SIMPLICITY IN THE POST
// update elapsed time
gettimeofday(&tv_now,NULL);
if (tv_now.tv_sec >= last_usecs) // this if/else code handles
the situation where the microsecond value crosses over zero between reads.
{
elapsed_us = tv_now.tv_usec - last_usecs;
}
else
{
elapsed_us = (1000000 - last_usecs) + tv_now.tv_usec;
}
total_elapsed_time_us = (tv_now.tv_sec - start_secs)*1000000 +
elapsed_us; // this code adds microseconds for every second that has
elapsed since the routine started. In our case, we won't be in the routine
more than 5 seconds ever.
if (total_elapsed_time_us > TimeToRead) KeepReading = 0;
}
}
}
On Thursday, February 18, 2021 at 2:36:45 PM UTC-5 Walter Cromer wrote:
> Yes I did and it did not work on my system. I don't remember why now.
>
> On Thursday, February 18, 2021 at 1:47:29 PM UTC-5 Dennis Bieber wrote:
>
>> On Thu, 18 Feb 2021 08:27:48 -0800 (PST), in
>> gmane.comp.hardware.beagleboard.user Walter Cromer
>> <walterc-2dFtBuzUeF/[email protected]> wrote:
>>
>> >I think if I could just find how to read the clock on the PRU with C, I
>> can
>> >probably take it from here. And of course, it needs to be giving me
>> >milliseconds. From what I read the main clock functions don't work below
>> >seconds.
>>
>> Have you even looked at the link I posted some hours ago? Duplicated
>> below.
>>
>> >On Wed, 17 Feb 2021 10:45:49 -0800 (PST), in
>> >gmane.comp.hardware.beagleboard.user Walter Cromer
>> ><walterc-2dFtBuzUeF/[email protected]> wrote:
>> >
>> >>You are correct that this application does not need to know the actual
>> real
>> >>time but only the relative (elapsed) time since the subroutine began.
>> I'm
>> >>familiar with clock_gettime but didn't think it could give me subsecond
>> >>information. I'll explore it!
>> >>
>> >
>> >https://www.tutorialspoint.com/c_standard_library/c_function_clock.htm
>> >
>> > The worst you may have to handle is the wrap-around in a long-running
>> >program.
>>
>> According to the documentation, that function returns clock TICKS
>> (whatever the tick rate is for the system in question). If you know the
>> CLOCKS_PER_SECOND you should be able to compute the clocks per
>> millisecond...
>>
>> https://linux.die.net/man/3/clock
>>
>> or use
>>
>> https://linux.die.net/man/2/times
>>
>> or better
>>
>> https://linux.die.net/man/2/clock_gettime in which the return structure
>> is
>> seconds AND NANOSECONDS
>>
>>
>> --
>> Dennis L Bieber
>>
>>
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/beagleboard/2230dd99-125e-4d58-a5c5-2faf54e9f2b1n%40googlegroups.com.