Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20563

Share your working BASCOM-AVR code here : Moving average for INTEGER and SINGLE data streams : REPLY

$
0
0
Hi Per, I am using your moving average in Bascom like this: I was not able to use a function (I hardly understand Bascom function behaviour':x') [code:1:b59b891637]Accum2 = Temperature_accumulator2 Shift Accum2 , Right , Sm2 , Signed 'Accumulator sum divided by 2^moothing factor Temperature_average2 = Accum2 'returnvalue Temperature_accumulator2 = Temperature_accumulator2 - Accum2 'Subtract old value Temperature_accumulator2 = Temperature_accumulator2 + Ma_smooth Ma_smooth = Temperature_average2 'Ma_smooth is continously updated.[/code:1:b59b891637] The routine seems to do what is should. However, I am not sure if that yields the same result as your function construct due the question of passing the variables. [code:1:b59b891637]Declare Function Temperature_average(temperature_accumulator As Long , Temperature_new_val As Word , Byval Smooth_factor As Byte) As Integer 'Your function definition[/code:1:b59b891637] I also want to use it in a Java program. The compiler (IDE) is called B4J. There function values are always passed by value. Will this do the same as the Bascom code? [i:b59b891637] Sub movaverag( Temperature_new_val As Int , Smooth_factor As Byte) As Int 'Function Temperature_average(temperature_accumulator As Long , Temperature_new_val As Integer , Byval Smooth_factor As Byte) As Integer Dim Accum1 As Long Accum1 = Temperature_accumulator 'This is the old average on LONG form. 'Shift Accum1 , Right , Smooth_factor , Signed 'Accumulator sum divided by 2^moothing factor Accum1=Accum1/Power(2,Smooth_factor) Temperature_average = Accum1 Temperature_accumulator = Temperature_accumulator - Accum1 'Subtract old value Temperature_accumulator = Temperature_accumulator + Temperature_new_val Return Temperature_average End Sub[/i:b59b891637] Best regards, Meister

Viewing all articles
Browse latest Browse all 20563

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>