View previous topic :: View next topic |
Author |
Message |
nicofer
Joined: 01 May 2013 Posts: 90 Location: GRJ
|
Posted: Fri Feb 24, 2017 9:24 am Post subject: over range Compare |
|
|
Hi
I need to check if a value changed , but only if more than say 2 or 3 , to eliminate sensor noise etc , any faster / better ideas .
at the moment i use :
Deltad = value - Lastvalue
Delta = Abs(deltad)
If Delta > 3 Or Opt3last <> Limitprox Then
Enchange = 1
else
Enchange = 0
End If
Lastvalue = value
Cheers
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Fri Feb 24, 2017 6:13 pm Post subject: |
|
|
Hi
Why not just drop the lowest 2 bits before comparing
Code: |
reset Value.0
reset Value.1
if Value <> Old_value then
.....
|
That should be alot quicker than a subtraction and a abs but it won't work for floats.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
nicofer
Joined: 01 May 2013 Posts: 90 Location: GRJ
|
Posted: Fri Feb 24, 2017 8:29 pm Post subject: |
|
|
Hi
Now that is a cool plan , never thought of it . thanks .
Cheers |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Fri Feb 24, 2017 8:47 pm Post subject: |
|
|
Hi,
My method won't be super accurate. For example if you have the value 8 and it changes to 7 the compare will be true (1000 -> 0111).
Depending on how fast you Signal changes/what you want to do with the value, it might be better to just smooth (average) the value.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
nicofer
Joined: 01 May 2013 Posts: 90 Location: GRJ
|
Posted: Sat Feb 25, 2017 6:27 am Post subject: |
|
|
Hi ,
The plan is just to print a value if it changed but only if it changed by more than a dela value .
The values are between 0 and 4095
Cheers |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sat Feb 25, 2017 7:45 am Post subject: |
|
|
Hi,
And what data types are your variables (word, integer, single, double)?
If you only want to print something when the value changes more than a fixed Delta ny idea wont work, But let me think about it.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Feb 25, 2017 3:56 pm Post subject: |
|
|
i.dobson wrote: | And what data types are your variables (word, integer, single, double)? |
nicofer wrote: | The values are between 0 and 4095 | Looks like a 12 bit word, doesn't it?
Quote: | If you only want to print something when the value changes more than a fixed Delta my idea wont work, But let me think about it. | There's no reason it won't work, other than clearing single bits requires change of 1+, 2+, 4+, a.s.o.
Also it depends, where Lastvalue = value is placed - within or below the conditional block. |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sat Feb 25, 2017 4:24 pm Post subject: |
|
|
Hi,
Just because it's a 12bit value doesn't mean the OP is using a word, that's why I'm asking what type it is.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
nicofer
Joined: 01 May 2013 Posts: 90 Location: GRJ
|
Posted: Sun Feb 26, 2017 5:25 pm Post subject: |
|
|
Hi
Yes , value is a word .
will have a look at your sugestion .
Thanks
Cheers |
|
Back to top |
|
|
|