10/8/2017 2:48 PM  
Joined: 1/30/2017 Last visit: 12/5/2019 Posts: 18 Rating: (0) 
Hi all, I am facing a problem with cyclic interrupt pulse. I have a variable say, a= 0s . Its value should increment after every 100 ms. That is value should be 0,0.1s,0.2s e.tc So i made a 100 ms pulse and at its positive edge, a:= a+0.1; This is working but not accurate . After 1s and additional 0.001 is adding . That is a:= 1.001 and this is repeating after every 1 s like 2.002,3.003... 10.010. e.t.c Can anyone say what is the problem behind this. ? Is their any problem with pulse ..? Please some one help..!!! Thanks in advance.. 
10/9/2017 10:12 AM  
Joined: 9/23/2005 Last visit: 12/5/2019 Posts: 2355 Rating: (345) 
The problem behind is finite resolution of a floating point representation. It makes that 0.1 is not actually 0.1, but rather 0.100000001490116119384765625. So the lesson is  do not use a floating point representation for counting. The good news is that the pulse is ok. 
Regards, 

10/10/2017 5:07 PM  
Joined: 7/7/2010 Last visit: 12/6/2019 Posts: 8266 Rating: (1397)

It would be simpler to trust the cyclic interrupt and just add one to a counter, and in regular scan time, multiply the count value by 0.100 ms to get the time value without the round off error.

science guy 

Follow us on