Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Strange results form variable calculations

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

Bascom Member



Joined: 26 Sep 2006
Posts: 8

germany.gif
PostPosted: Thu Jan 10, 2019 6:15 pm    Post subject: Strange results form variable calculations Reply with quote

Hello,
in my program I noticed some strange behaviour of some variables. All definitions are correct, no error messages etc. form compiler. The purpose of the program is to read an RC pulse and divide the measured range into 14 steps to control some lights.
wSwitchStep is 71, SwitchTolerance is 10, wPulseMinStore is 984

Code:
wLowLightWarn = wSwitchStep * 8 : wLowLightWarn = wLowLightWarn + wPulseSwitchMinStore
wLowLightWarnLow = wLowLightWarn - SwitchTolerance
wLowLightWarnHigh = wLowLightWarnHigh + SwitchTolerance

These definitions result in wLowLightWarn = 1552, wLowLightWarnLow = 1542, but wLowLightWarnHigh = 20 (!)
I'm using the same logic of variable assignment for the other switching states and there everything is o.k.

If I rename the variable like this, the calculation is correct.
Code:
wWarn= wSwitchStep * 8 : wWarn = wWarn + wPulseSwitchMinStore
wWarnL = wWarn - SwitchTolerance
wWarnH = wWarn + SwitchTolerance


Does somebody has an idea, what can cause this calculation error for variable wLowLightWarnHigh?

(BASCOM-AVR version : 2.0.8.1 )

_________________
Best regards
Jürgen
Back to top
View user's profile
laborratte

Bascom Expert



Joined: 27 Jul 2005
Posts: 243
Location: Berlin

germany.gif
PostPosted: Thu Jan 10, 2019 7:13 pm    Post subject: Reply with quote

Most likely a High too much: wLowLightWarnHigh = wLowLightWarnHigh + SwitchTolerance
Back to top
View user's profile
JL

Bascom Member



Joined: 26 Sep 2006
Posts: 8

germany.gif
PostPosted: Fri Jan 11, 2019 10:57 am    Post subject: Reply with quote

laborratte wrote:
Most likely a High too much:...

Yes, that's it.
Believe me (or not); I spent some hours to find the cause, and wasn't able to see it Brick wall Brick wall in that bunch of code lines with similar definitions. It's the typical behaviour of seeing not the wood for the trees Wink

_________________
Best regards
Jürgen
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