learning PIC assembly

Status
Not open for further replies.

t.man

New Member
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.

ericgibbs

Well-Known Member
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.?

Last edited:

t.man

New Member
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.?

i'm just going thru Nigels tutorials, i'll pop back if i can't get something clearly

t.man

New Member
I can see how to initialize and make the ADC run( and reading the result)

i.e
Code:
Read_ADC
goto    \$-1			;wait for ADC to finish

andlw   0x03
movwf   NumH
movwf	NumL			;return result in NumL and NumH
return

now i want work out the input voltage
Code:
v_in = v_ref x adc/1023

ericgibbs

Well-Known Member
I can see how to initialize and make the ADC run( and reading the result)

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.?

Last edited:

t.man

New Member
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.?

the procedure you are telling is very clear with one exception(how do i insert the decimal?).
again i couldn't grasp the divide and multiply subroutines in PIClist.

Last edited:

birdman0_o

Active Member
You would know the decimal place, eric is assuming you are using some kind of display to output the data, is that whats getting you confused? It would be a visual DP, not in the actual code.

Last edited:
Status
Not open for further replies.

Replies
4
Views
1K
Replies
7
Views
2K
Replies
3
Views
2K
Replies
11
Views
3K
Replies
9
Views
2K