AlexT_Intel wrote:
That's interesting, I see nothing in the code, which could cause that. How do you measure the period, where do you get those 2 seconds from?
Could you post a full sketch you're using, I'll check it out? I don't have a Galileo board with me right now, but I'll give it a try as soon as I can.
I can't explain it, but I believe that chotofo gets that because I am seeing a doubling also. It has been a long time since this thread was active and I am hoping you can take the time to see what I am doing wrong or right. I am trying to use timerone to create a running timer that is accessible in a sketch - that the basic task. They are, in my opinion, very useful, and it would be great to have this inside of a sketch.
I have followed this thread and others. The code attached runs fine. Timer1 is working. The running timer is working. It's just not working the way I thought it would.
I initialize the timer with
Timer1.initialize(100000);
Attach the ISR with
Timer1.attachInterrupt(timerIsr,100000);
Have the ISR simply increment a variable (defined using volatile like you should - but it makes no difference for this issue)
I am expecting .10 sec resolution such that a 10 sec delay would produce a count of 100. Instead it produces a count of 50.
I am using delay(10000) to produce a 10 sec delay.
In the code comments I am showing the results of a number of settings (the resulting single values were most common but in each case the loops would sometimes vary by a count of 1 - just a little jitter). I looked through timerone.cpp and h and I see nothing to account for this. Clearly I don't understand what is happening. I certainly don't expect a great deal of precision inside a sketch or from the delay(), but I can't believe that accounts for the discrepancy. It is almost as though interrupts are triggered twice where I think they should occur only once (which sounds like me thinking rising edge only but change is triggering - this make no sense because its not a pin interrupt). Not only do I not understand it when the initialize and attach values are the same, I am equally clueless when the attach value is a used as a divider or prescaler. So, what the heck is going on?