Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

over range Compare

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
nicofer

Bascom Member



Joined: 01 May 2013
Posts: 90
Location: GRJ

southafrica.gif
PostPosted: Fri Feb 24, 2017 9:24 am    Post subject: over range Compare Reply with quote

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
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Fri Feb 24, 2017 6:13 pm    Post subject: Reply with quote

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
View user's profile
nicofer

Bascom Member



Joined: 01 May 2013
Posts: 90
Location: GRJ

southafrica.gif
PostPosted: Fri Feb 24, 2017 8:29 pm    Post subject: Reply with quote

Hi
Now that is a cool plan , never thought of it . thanks .

Cheers
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Fri Feb 24, 2017 8:47 pm    Post subject: Reply with quote

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
View user's profile
nicofer

Bascom Member



Joined: 01 May 2013
Posts: 90
Location: GRJ

southafrica.gif
PostPosted: Sat Feb 25, 2017 6:27 am    Post subject: Reply with quote

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
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Sat Feb 25, 2017 7:45 am    Post subject: Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sat Feb 25, 2017 3:56 pm    Post subject: Reply with quote

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
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1570
Location: Basel, Switzerland

switzerland.gif
PostPosted: Sat Feb 25, 2017 4:24 pm    Post subject: Reply with quote

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
View user's profile
nicofer

Bascom Member



Joined: 01 May 2013
Posts: 90
Location: GRJ

southafrica.gif
PostPosted: Sun Feb 26, 2017 5:25 pm    Post subject: Reply with quote

Hi
Yes , value is a word .

will have a look at your sugestion .

Thanks
Cheers
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum