View previous topic :: View next topic |
Author |
Message |
nicofer
Joined: 01 May 2013 Posts: 90 Location: GRJ
|
Posted: Mon Jun 29, 2015 12:42 pm Post subject: DELTA value |
|
|
Hi
I need to know if a sensor value has changed more than a specified DELTA value from a previous reading .
One way is to subtract the 2 , get the ABS and compare with a DELTA value .
Is there a faster , less code , way to do this compare ? - for now I only need to know if delta is more than 2 .
A BASCOM function to perform this will be very useful. ( res = DELTA(var1, var 2 , range) )
Cheers
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
Plons
Joined: 24 May 2005 Posts: 435 Location: Hilversum - The Netherlands
|
Posted: Mon Jun 29, 2015 4:53 pm Post subject: |
|
|
If you use integers, the procedure you describe will be processed very fast. Bascom is a compiler !
If you're using Singles or Doubles, it will take more time .... of course.
If you have an oscilloscope, hook it up to a free pin, set pin @ entry of calculation, clear on exit, and witness the speed of this compiler
I doubt if a specific statement as you describe will be faster. And personally I prefer plain and simple code over smart statements. But that's personal ...
Enjoy!
Nard _________________ Bascom AVR ver 2.0.8.6
Dragon-lair: http://www.aplomb.nl/TechStuff/Dragon/Dragon.html
"leef met vlag en wimpel, maar hou het simpel" |
|
Back to top |
|
|
nicofer
Joined: 01 May 2013 Posts: 90 Location: GRJ
|
Posted: Mon Jun 29, 2015 7:28 pm Post subject: |
|
|
Hi
Yes , at the end of the day I subtract the 2 , get the abs and do the compare and it is very fast , all on word values .
Thanks for the
reply.
Groetnis . |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Tue Jun 30, 2015 1:42 am Post subject: |
|
|
I hope you mean integer, not word. word is not signed, so the result of w1 - w2 may not be what you expect. And taking the ABS of a word may not do much either. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
|