Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

calculations in pic

Status
Not open for further replies.

eddy123456

New Member
Hi guys,

Can i assume the only way to have a value larger than 255(for a variable) is by increasing the value of another variable every time the first variable overflow. By the way im using pic16f84 and im currently learning how to program in assembly language.

Example, "counta" for values from 0-256 and "countb" is for overflow of "counta".

This is an example code that i found which shows the calculation of numbers more than 256. The result will correspond to an address in a map.

rpmhi=counter overflow for rpmlow.
value of rpm : 74<(rpmhi+rpmlow)<600

Code:



; the formula to get the data stored in the map is as follows
;
; (rpmhi+rpmlow count) - 74
; 131 - ----- ----------------------
; 4
;
caladv movlw d'74' ; (rpmhi+rpmlow count) - 74
subwf rpmlo,F ; rpmlo = rpmlo - 74
btfss STATUS,C
decf rpmhi,F
;
; divide result by 4
;
bcf STATUS,C
rrf rpmhi,F
rrf rpmlo,F ; / 2
;
bcf STATUS,C
rrf rpmhi,F
rrf rpmlo,F ; / 4
;
movlw .131 ; 131 entries in map list
movwf math
;
movf rpmlo,W
subwf math,W ; W = 131 - result
;
bcf PCLATH,0 ; be sure to go h'200'
bsf PCLATH,1 ; where is the map.
call map ; read map
movwf rtdset ; come back with new retard value


Code:

Im not sure how the codes work.Ive tried the logic, and it seems fine for numbers <256,

example :

say value of rpm : (rpmhi+rpmlow)=240

where rpmhi=0 and rpmlow=d'240'

ive done 2 different approach :
a) using calculator =41.5
b) using the logic operator (subwf,rrf) =41


But when rpm value > 256, say (rpmhi+rpmlow)=496

where rpmhi=1 and rpmlow=d'240'

same approach as above:
a) using calculator =105.5
b) using the logic operator (subwf,rrf) =41

or am i missing something here..
 
Last edited:
[ code] tags (without the space) would help make your code more readable.

What you've posted of the code looks fine, except possibly for the last 4 lines. Are you sure you're using the correct bits of PCLATH (the PICs I've been using pull from bits 4 and 3 with a CALL instruction)? Are you sure your map subroutine is correct?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top