Working with numbers larger than 255
kingneb
Posts: 65
I want to read a nibble (4 bits on the ra channel)·off the RA·channel on the sx28.· I want to multiply that nibble value by 100.· I want to also subtract that value from 1000.· I know there is a trick for this type of operation.· how do you do it?
Thanks,
kingneb·
Thanks,
kingneb·
Comments
·· There are plenty of Math routines on www.sxlist.com for doing up to 32-bit math I believe.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
1.· Read a nibble
2.· Multiply that nibble by 100 (this is for pulse width modulation, calculating the high delay and the low delay) to get the high duration.
3.· Subtract the nibble by 1000 to get the low duration
Here is the Picbasic code:
Thanks, kingneb
for the high duration you iterate ra 100 cycle delays,
for the low duration you iterate 10-ra 100 cycle delays (by doing 'mov w,#10' followed by 'sub w,ra')
though you should probably have ra buffered in the event that ra is changed externally between the use of ra when calculating the high duration and the low duration.
Use Gunther's·link in your other post to generate the code for the 100 cycle delay.
The nice thing about this method is you keep all the math as 8 bit values, reducing computational overhead.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 10/8/2005 2:18:00 PM GMT
d1 DS 1
;98 cycles
mov w, #$19
mov d1, w
Delay_0:
decsz d1
jmp Delay_0
;2 cycles
nop
nop
Post Edited (kingneb) : 10/9/2005 12:18:18 AM GMT