PBP Using too many instructions


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    The code i posted originally is what ive been using to test how many instruction cycles things take. I have 4 sockets (A to D) on this board each with 6 outputs (1 to 6).

    Code:
    'Define output pins
    pA1 VAR PORTB.1
    pA2 VAR PORTB.2
    pA3 VAR PORTB.0
    'etc...
    
    
    'Then further down inside the TMR0 interrupt
    
    'Is the vPWMPos equal to 0?
    IF vPWMPos=0 THEN
    	
    	'Turn off any outputs that are less than 255
    	IF vPWM[0]<255 THEN pA1=0
    	IF vPWM[1]<255 THEN pA2=0
    	IF vPWM[2]<255 THEN pA3=0
    	'etc...
    ELSE
    
    	'If vPWMPos is less than any of the chanels then turn those chanels on
    	IF vPWMPos=vPWM[0] THEN pA1=1
    	IF vPWMPos=vPWM[1] THEN pA2=1
    	IF vPWMPos=vPWM[2] THEN pA3=1
    	'etc...
    ENDIF
    
    'Decrement the PWM counter
    vPWMPos=vPWMPos-1
    There doesnt have to be an array involved. I just used that to make other parts of the code a little easier. I could create a bunch of variables named vPWM0, vPWM1 etc instead. The important part is reducing the number of instructions an if statement uses or not using an if statement at all.

  2. #2
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    Soft' PWM for that many outputs is difficult but you might be able to reduce 'overhead' using one of the following assembler methods;

    Good luck on your project Sir. Regards, Mike

    Code:
    ;
    ;  6 bit (single port), 256 step, 20 cycles (isochronous) for 16F
    ;
            movf    led+5,W         ; led[5] duty cycle, 0..255       |B0
            subwf   dcy,W           ; C = led[5] >= dcy               |B0
            rlf     shadow,F        ;                                 |B0
            movf    led+4,W         ; led[4] duty cycle, 0..255       |B0
            subwf   dcy,W           ; C = led[4] >= dcy               |B0
            rlf     shadow,F        ;                                 |B0
            movf    led+3,W         ; led[3] duty cycle, 0..255       |B0
            subwf   dcy,W           ; C = led[3] >= dcy               |B0
            rlf     shadow,F        ;                                 |B0
            movf    led+2,W         ; led[2] duty cycle, 0..255       |B0
            subwf   dcy,W           ; C = led[2] >= dcy               |B0
            rrf     shadow,F        ;                                 |B0
            movf    led+1,W         ; led[1] duty cycle, 0..255       |B0
            subwf   dcy,W           ; C = led[1] >= dcy               |B0
            rlf     shadow,F        ;                                 |B0
            movf    led+0,W         ; led[0] duty cycle, 0..255       |B0
            subwf   dcy,W           ; C = led[0] >= dcy               |B0
            rlf     shadow,F        ;                                 |B0
            xorlw   0xFF            ; for active hi outputs           |B0
            movwf   PORTB           ; update LEDs                     |B0
    ;
    ;  bump duty cycle counter
    ;
            movlw   b'00111111'     ; just in case                    |B0
            incf    dcy,F           ; bump duty cycle counter         |B0
            skpnz                   ; end-of-period? no, skip, else   |B0
            movwf   shadow          ; reset shadow                    |B0
    Code:
    ;
    ;  6 bit (single port), 256 step, 15 cycles (isochronous) for 18F
    ;
            movf    dcy,W           ; duty cycle counter, 0..255      
            cpfsgt  Led+0           ; if(Led[0] >= dcy)               
            bcf     Shadow,0        ;   Shadow.0 = 0                  
            cpfsgt  Led+1           ; if(Led[1] >= dcy)               
            bcf     Shadow,1        ;   Shadow.1 = 0                  
            cpfsgt  Led+2           ;                                 
            bcf     Shadow,2        ;                                 
            cpfsgt  Led+3           ;                                 
            bcf     Shadow,3        ;                                 
            cpfsgt  Led+4           ;                                 
            bcf     Shadow,4        ;                                 
            cpfsgt  Led+5           ;                                 
            bcf     Shadow,5        ;                                 
            movff   Shadow,LATB     ;
    ;
    ;  bump duty cycle counter
    ;                         
            movlw   b'00111111'     ; just in case
            infsnz  dcy,F           ; if end-of-period                
            movwf   Shadow          ; reset shadow

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    971


    Did you find this post helpful? Yes | No

  4. #4
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Ive been trying to get my head round this ASM code. Mike's ASM seems to do almost exactly what i want but i just want to clarify things as im completely new to ASM.

    Is W some kind of temp byte? It appears that ASM compare commands only accept 1 input and that is always compared with W.

    Ive read the part in the datasheet about CPFSGT. It says "Compare f with W, skip if f > W". I assume this means skip the following line of code

    BCF looks pretty obvious. What is "Shadow" though? Is that a predefined variable of some kind or does it need declaring anywhere?

  5. #5
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    971


    Did you find this post helpful? Yes | No

    Default

    Is W some kind of temp byte? It appears that ASM compare commands only accept 1 input and that is always compared with W.
    Yes, W is the Accumulator on which almost all operations are performed.

    What is "Shadow" though? Is that a predefined variable of some kind or does it need declaring anywhere?
    Yes, shadow is a byte sized variable which holds a copy of the actual bits which turn on/off the leds attached to PORTB. It has to be declared like this

    Code:
    shadow:  var byte

  6. #6
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    So "LATB" is the ASM version of PORTB?

    Is Shadow just a normal variable then? So i could call it LATBTemp if i wanted?

    Is there a reason i would use Shadow instead of performing the operations directly on LATB?

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 13:55
  2. PBP, ASM and LST files
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th January 2010, 14:43
  3. List of instructions used in PBP ?
    By AndrewC in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd November 2007, 12:22
  4. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 20:01
  5. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2005, 00:30

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts