I am using this variable: CapturedTime As Word Alias CCPR1H,CCPR1L
to capture the time between 2 magnets and it works fine.
Now I want to keep the 4 last measures rolling variables as follow:
CapturedT4 = CapturedT3
CapturedT3 = CapturedT2
CapturedT2 = CapturedT1
CapturedT1 = CapturedTime
GCBASIC accept the following line with no error message:
Unfortunatly I do not know how to implement a function. So I tried to use the undocumented function AVERAGE, the compiler do not give any error message on my code.
CapturedTime is a word variable and can vary from 2500 up to 65535.
Therefore it is impossible to add the 4 word variables capturedT(4) before dividing. It would give a very long result 4x64535 = 258140
May be the AVERAGE function should divide first and then do the addition.
Why the AVERAGE function is undocumented ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using this variable: CapturedTime As Word Alias CCPR1H,CCPR1L
to capture the time between 2 magnets and it works fine.
Now I want to keep the 4 last measures rolling variables as follow:
CapturedT4 = CapturedT3
CapturedT3 = CapturedT2
CapturedT2 = CapturedT1
CapturedT1 = CapturedTime
GCBASIC accept the following line with no error message:
Time180Degr = [Word] AVERAGE (CapturedT1 , CapturedT2 , CapturedT3 , CapturedT4)
The hex file does not give the expected average captured time.
What is wrong ?
Thank you for your help
Are you using the undocumented AVERAGE function? Or, have you written your own AVERAGE function?
See https://sourceforge.net/p/gcbasic/discussion/579126/thread/d7802e8f/#f6ff/dc6c for the undocumented function. The takes two parameters looking at the URL info, so, you this would be an issue.
If you have your own function. Please post.
Unfortunatly I do not know how to implement a function. So I tried to use the undocumented function AVERAGE, the compiler do not give any error message on my code.
CapturedTime is a word variable and can vary from 2500 up to 65535.
Therefore it is impossible to add the 4 word variables capturedT(4) before dividing. It would give a very long result 4x64535 = 258140
May be the AVERAGE function should divide first and then do the addition.
Why the AVERAGE function is undocumented ?
I cannot explain why the function is not documented. I do know it may not do what you want.
try
Dim ugl_AverageCalc as Long
ugl_AverageCalc = [Long] CapturedT1 + CapturedT2 + CapturedT3 + CapturedT4
Time180Degr = [Word] ugl_AverageCalc / 4