Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I do I work with more than 8-bit numbers in assembly. e.g i want to read and manipulate a 10-bit ADC result.
I know variable type int will hide everything for me in C.
hi t,
PICList on the web has lots of 16 and 32 bit Math subr also look thru Nigels tutorials, link near my signature.
Any specific maths subr that you require.?
Read_ADC
bsf ADCON0, GO_DONE ;initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ;wait for ADC to finish
movf ADRESH,W
andlw 0x03
movwf NumH
BANKSEL ADRESL
movf ADRESL,W
BANKSEL ADRESH
movwf NumL ;return result in NumL and NumH
return
v_in = v_ref x adc/1023
I can see how to initialize and make the ADC run( and reading the result)
v_in = v_ref x adc/1023[/CODE]
Assuming a 5Vref and say 2.5Vinput
V = 5 * [512/1023] = 5 * 0.5 = 2.5V
So do the 512/1023 part first, as you need to avoid decimals, multiply the 512 by say 100.
This gives 51200/1023, which can be done with unsigned integer math subr, yields 50 as a integer result.
Now multiply this result by 5 [Vref] to give 250
When you display the result, insert a decimal point between the 2 and 5, so you display 2.50V.
If you require a higher resolution, multiply the 512 by 1000.
OK.?