![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi guys, Am I doing this simple two step 16 bit math operation correctly? I'll simulate it as soon as I wake up... Code: ;
; CCP1CONbits.CCP1M0 = 0;
; CCPR1L += (20000-Pulse)%256;
; CCPR1H += (20000-Pulse)/256;
;
; pulse is lo so setup CCP1 to go hi on pulse "off-time" match
;
Pulse_Lo
bcf CCP1CON,CCP1M0 ; setup CCP1 to go hi next int |B0
movf PulseLo,W ; W = Pulse%256 |B0
sublw low d'20000' ; W = 20000%256 - Pulse%256 |B0
skpc ; borrow? no, skip, else |B0
decf CCPR1H,f ; borrow from CCPR1H |B0
addwf CCPR1L,f ; CCPR1L += (20000-Pulse)%256 |B0
skpnc ; carry? no, skip, else |B0
incf CCPR1H,f ; carry into CCPR1H |B0
movf PulseHi,W ; W = Pulse/256 |B0
sublw high d'20000' ; W = 20000/256 - Pulse/256 |B0
addwf CCPR1H,f ; CCPR1H += (20000-Pulse)/256 |B0
;
| |
| |
| | #2 |
|
Also should have mentioned that if you've got an easier and/or better way to do it (fewer instructions, more intuitive, etc.), please pass it along. I suck at math (grin).
| |
| |
| | #3 |
|
Just wanted to note you've used skpc & skpnc awesome.
| |
| |
| | #4 | |
| Quote:
| ||
| |
| | #5 | |
| Quote:
The Skip Carry (skpc) and Skip No Carry (skpnc) pseudo instructions are much more intuitive than the equivalent btfss STATUS,C and btfsc STATUS,C instructions, respectively. And the 12/14 bit "branch" pseudo instructions bz, bnz, bc, bnc, etc., are real instructions on the 16 bit core devices. Last edited by Mike, K8LH; 8th April 2007 at 05:32 PM. | ||
| |
| | #6 |
|
I think the pseudo instructions make the core more readable.
| |
| |
| | #7 | |
| Quote:
which was basically a collection of such macros.Although I would agree that they do make it more readable. | ||
| |
| | #8 |
|
I wonder if it doesn't make sense to denote macros in the name- like "skpc_m" -to make the code clearer?
__________________ I thought what I'd do was I'd pretend I was one of those deaf-mutes. | |
| |
| | #9 |
|
Actually they're part of MPASM. They are what they are. You don't need to define them; just use them. I've attached the Firefly 16F88 version of both the main instruction & pseudo commands (omitting the silly b (branch)) Don't have the cycle times worked out though. Last edited by blueroomelectronics; 8th April 2007 at 07:51 PM. | |
| |
| | #10 |
|
For the 18F family their use seems to be discouraged. Nowhere I saw them mentioned in connection with the 18F. Never used them, thanks God.
__________________ Agustín Tomás In theory, there is no difference between theory and practice. In practice, however, there is. | |
| |
| | #11 | |
| Quote:
| ||
| |
|
| Tags |
| math |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Electrical Math Books? | Andy1845c | Chit-Chat | 1 | 31st October 2006 05:58 PM |
| Microchip fixed point math library -16CXXX family | atferrari | Micro Controllers | 10 | 19th May 2005 09:48 AM |
| 89c51 32-bit Math calculation | garg29 | Micro Controllers | 1 | 1st February 2005 06:15 AM |
| Need Help In Math | shermaine | General Electronics Chat | 6 | 8th March 2004 02:46 PM |
| PIC math question | Tako Kichi | Micro Controllers | 4 | 12th November 2003 03:48 AM |