Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 8th April 2007, 03:26 PM   #1
Default Math help?

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
;
Mike, K8LH is offline  
Old 8th April 2007, 03:37 PM   #2
Default

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).
Mike, K8LH is offline  
Old 8th April 2007, 04:43 PM   #3
Default

Just wanted to note you've used skpc & skpnc awesome.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 8th April 2007, 04:45 PM   #4
Default

Quote:
Originally Posted by blueroomelectronics
Just wanted to note you've used skpc & skpnc awesome.
Personally I tend to disapprove of using those macros, it only confuses beginners.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 8th April 2007, 05:02 PM   #5
Default

Quote:
Originally Posted by Nigel Goodwin
Personally I tend to disapprove of using those macros, it only confuses beginners.
You're certainly entitled to your opinion but I believe promoting the use of meaningless _config lines in example "tutorial" programs and providing example keypad code that could short PIC output pins when more than one key is pressed, all for the sake of not confusing beginners, is not cool.

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.
Mike, K8LH is offline  
Old 8th April 2007, 07:16 PM   #6
Default

I think the pseudo instructions make the core more readable.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 8th April 2007, 07:20 PM   #7
Default

Quote:
Originally Posted by blueroomelectronics
I think the pseudo instructions make the core more readable.
That's because you come from the Parallax assembler which was basically a collection of such macros.

Although I would agree that they do make it more readable.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 8th April 2007, 07:42 PM   #8
Default

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.
Oznog is offline  
Old 8th April 2007, 07:45 PM   #9
Default

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.
Attached Files
File Type: pdf 16F instruction set.pdf (35.3 KB, 39 views)
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/

Last edited by blueroomelectronics; 8th April 2007 at 07:51 PM.
blueroomelectronics is offline  
Old 9th April 2007, 07:05 PM   #10
Default Nowadays

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.
atferrari is offline  
Old 9th April 2007, 11:07 PM   #11
Default

Quote:
Originally Posted by atferrari
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.
The 18F are teriffic chips, a little intimidating at first but in fact eaiser to program than the 16F & 12F chips.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Reply

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



All times are GMT. The time now is 09:17 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker