I need help with a math question.
I'm reading an analog input, and now also on the micro 8-bit analog converters are 10/12 bit. When I read the value I have to do an average, and would be good to use the shift (I read all the posts on the subject), 1, 2, etc.. that is left to right for the various mathematical operations to base 2. over the integers.
In C there is the << and >> they do also on the integers, and the long, do not know if there are special commands in asembler that they do, but usually the shift is much more compact in code that division or multiplication.
Any help is welcome, Thaks, Marco
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anobium good evening
Thanks as always for your assistance, I have seen this command, and also rotate, but only work on bytes, I downloaded the manual of AVR assembler and I'm investigating but as you know at this level is quite difficult for me.
In the meantime, if anyone has some more information, so be it. Thanks, Marco
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
' using uf_shift to ensure we do not clash with any potential PUBLIC method.
Function uf_shift ( l_invar as word , l_rotateval, l_direction ) as word
for ul_loop = 1 to l_rotateval
set C off
if l_direction = 1 then
rotate l_invar RIGHT
else
rotate l_invar LEFT
end if
next
uf_shift = l_invar
end function
' using uf_shift to ensure we do not clash with any potential PUBLIC method.
Function uf_shift_long ( l_invar as Long , l_rotateval, l_direction ) as Long
for ul_loop = 1 to l_rotateval
set C off
if l_direction = 1 then
rotate l_invar RIGHT
else
rotate l_invar LEFT
end if
next
uf_shift_long = l_invar
end function
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
and, then today. I remembered the code from the F1 Evaluation Port of last year.
This has an average function.... this may help.
~~~~~
Dim g_average As Long
Function input_pot( Optional ccount As byte = 2 ) as word
g_average = 0
for lloop = 1 to ccount
g_average = [Long] g_average + [Long] ReadAD10(ADCPort)
next
g_average = [Long]g_average / [Long]lloop
input_pot = g_average
' use the three LED's to show the ADC value
select case g_average
case < 200
set led1 off
set led2 off
set led3 off
set led4 off
case < 400
set led1 on
set led2 off
set led3 off
set led4 off
case < 600
set led1 on
set led2 on
set led3 off
set led4 off
case < 800
set led1 on
set led2 on
set led3 on
set led4 off
case => 800
set led1 on
set led2 on
set led3 on
set led4 on
end select
End Function
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello
I need help with a math question.
I'm reading an analog input, and now also on the micro 8-bit analog converters are 10/12 bit. When I read the value I have to do an average, and would be good to use the shift (I read all the posts on the subject), 1, 2, etc.. that is left to right for the various mathematical operations to base 2. over the integers.
In C there is the << and >> they do also on the integers, and the long, do not know if there are special commands in asembler that they do, but usually the shift is much more compact in code that division or multiplication.
Any help is welcome, Thaks, Marco
This may help. http://gcbasic.sourceforge.net/help/average.htm
There is a function that will average two numbers.
Anobium
Anobium good evening
Thanks as always for your assistance, I have seen this command, and also rotate, but only work on bytes, I downloaded the manual of AVR assembler and I'm investigating but as you know at this level is quite difficult for me.
In the meantime, if anyone has some more information, so be it. Thanks, Marco
Two functions I have in my own utils.h file, uf_shift and uf_shift_long. You need the two defines.
Usage example: w_addrH = uf_shift ( w_addr, 8, >> )
~~~~
define << 0
define >> 1
' using uf_shift to ensure we do not clash with any potential PUBLIC method.
Function uf_shift ( l_invar as word , l_rotateval, l_direction ) as word
end function
' using uf_shift to ensure we do not clash with any potential PUBLIC method.
Function uf_shift_long ( l_invar as Long , l_rotateval, l_direction ) as Long
end function
Thanks Anobium
This night I study this
and, then today. I remembered the code from the F1 Evaluation Port of last year.
This has an average function.... this may help.
~~~~~
Dim g_average As Long
End Function