Skip to content
Advertisement

weird issue with time function in C

I’m trying to get my Beaglebone Green to read an input from a certain pin, and when that pin sees a 1 to 0 transition (defined in pulse()), then it should set a timer. I want to make my timer like this:

In idle, the timer is set to a TIMER_HOLD value (900000) To start the timer, I set it to something lower then TIMER_HOLD. Then it should decrement (with the timerupdate() function). If it reaches 0 or less -which for an unsigned long is higher than TIMER_HOLD – then a trigger action is executed.

To test/debug this, I added: printf("timer 1: %lld n",timer[1]); And this works perfect… I see this output:

JavaScript

This is my c code:

JavaScript

now the weird thing: When I remove the printf("timer 1: %lld n",timer[1]); then I only see PULSE

on the output… the timer never triggers….

Any idea what’s happening?

system info:

JavaScript

Advertisement

Answer

I fixed it by reading /proc/uptime instead, then multiplying it by 10 (tenth of a second resolution is sufficient for my program)

I think the original thing didn’t work because of a rounding error, or a conversion float to int…. not sure though

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement