ASM help


Closed Thread
Results 1 to 17 of 17

Thread: ASM help

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default

    You need to consider the interrupt latency along with the bit time and adjust the timer accordingly. Look at the generated listing to know how much it is. Another improvement is here

    Code:
    BitTimer
          bcf T4CON,2     ; Turn Timer4 off 
          movlw 0xBF      ; 104uSec   / 16, 40 Mhz  1 bit time
          movwf TMR4      ; load it
          bsf T4CON,2     ; Turn it back on
          bsf   STATUS,C   ; move bit into carry
          btfss PORTB,0   ; check status of portB.0
          bcf   STATUS,C  ; move bit into carry
          rrcf   _rcv_byte,f ; shift carry into rec'd byte
          decfsz _bit_cntr,f ; decrement the bit counter
          bra   Donebit      ; get out and wait for next int
          bra Donebyte       ; got 8  bits

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I understand your improvement, and I realized that I hadn't considered latency, but at 40Mhz, it is only a few uSec.

    Even with a small timing error, it should get the first few bits right - but doesn't!
    Charles Linquist

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    In Donebyte, before re-enabling the INT0 interrupt, it clears the Timer4 flag.
    INT0IF will still be set and you'll get a false start when there's no data.
    Code:
          bcf  PIR3,3       ; clear the int flag
          bsf INTCON,4   ; turn on the INT0 interrupt for next byte
    And I think the 1-1/2 bit time is off.
    97 would be right if it were decimal, but it's hex.
    Try it with 0x61.


    Knowing you, this is probably part of a much bigger program with lots of variables ...
    You'll probably want to put the variables used in ASM into BANK0
    Code:
             bit_cntr  VAR BYTE BANK0
             rcv_byte  VAR BYTE BANK0
             rcv_buffer   VAR BYTE BANK0
    There's really no need to stop timer4 when reloading since it's an 8-bit timer.
    But adding the reload value to TMR4 instead of just loading it will cancel out any latencies.
    <br>
    DT

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Unhappy

    Yes, this *WILL* be part of a much bigger program!

    I made some changes -

    I cleared INTCON.1 before I re-enabled it in the
    Donebyte routine

    Code:
    Donebyte      
          movff _rcv_byte,_rcv_buffer
          movff _rcv_buffer,PORTD  ; this is a debug, just to see rec'd byte on LEDS
          bcf  PIR3,3       ; clear the int flag
          bcf INTCON,1
          bsf INTCON,4   ; turn on the INT0 interrupt for next byte
          INT_RETURN
    But that didn't help. It shouldn't have been set anyway, since I clear it
    after I shut off INT0 in the
    GetStart section.

    I changed the TMR4 reload value to 0x61

    I put the variables in BANK0

    I made the change recommend by Jerson to take one line out of the setb/clrb
    sequence.

    Still, when I hit ANY character, all the LEDs on PORTD light up (high).

    Something small still isn't right.
    Charles Linquist

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I think you need to disable the TMR4 interrupts in Donebyte, instead of clearing the flag.

    I'll try to run it here on a 4520.

    No Timer4, but Timer2 should do the same thing for me.
    <br>
    DT

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    OK, got it working here ...

    You do need to disable T4 ints (last post).

    And I haven't figured out why yet, but it was missing a bit in each byte, so I increased _bit_cntr to 9 and now it works.

    I'll play with it some more and post the final results.
    <br>
    DT

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Here ya go ...

    The 9-bit issue was due to flags not being cleared first before enabling.

    I've changed it to put the bit periods in PR4 instead of TMR4, this eliminates the latencies without having to reload the timer.

    Since I was using an 18F4520 (no TMR4), I made it so you can use any of the 8-bit timers that count up to PR?, TMR2, 4 or 6.

    I've also changed several other things, so look carefully if you're trying to pick them out.

    My debug method was sending the received byte out the USART, instead of PORTD.
    Code:
    DEFINE OSC 40
    
    DEFINE RX_TMR  4          ; can be 2, 4 or 6
    DEFINE TMR_INT TMR4_INT   ; int must match timer selection
    
    ;RCSTA = $90 ' Enable serial port & continuous receive
    ;TXSTA = $20 ' Enable transmit, BRGH = 0
    ;SPBRG = 64  ' 9600 Baud @ 40MHz, 0.16%
    
    
                   
     bit_cntr    VAR BYTE BANK0
     rcv_byte    VAR BYTE BANK0
     byteready   VAR BYTE BANK0
     rcv_buffer  VAR BYTE BANK0
    ;-----------------------------------------------------------------------
    
            INCLUDE "DT_INTS-18.bas"         ; Base Interrupt System
    
      
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
                  INT_Handler    INT0_INT,   GetStart,   ASM,  yes 
                  INT_Handler     TMR_INT,   BitTimer,   ASM,  yes
    
              endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
                             
    Goto OverInt
    
    '---[INT - interrupt handler]---------------------------------------------------
    ASM
    #define TMR_VAL TMR#v(RX_TMR)
    #define TMR_CON T#v(RX_TMR)CON
    #define TMR_PR  PR#v(RX_TMR)
    ENDASM
       
    ASM
    GetStart  
          movlw 0x02             ; T? OFF, /16 prescale, no postscalers
          movwf TMR_CON          
          movlw 0x61             ; 156uSec dly @ 40Mhz = 1.5 bit times
          movwf   TMR_PR 
          clrf    TMR_VAL
          bsf     TMR_CON,2      ; Turn timer on
          INT_ENABLE  TMR_INT    ; turn on the Timer INT
          movlw   0x08           ; load the bit counter  
          movwf   _bit_cntr
          INT_DISABLE INT0_INT   ; shut off the INT0 interrupt
          INT_RETURN
    ENDASM     
         
    ASM
    BitTimer
          movlw 0x41             ; load PR2 for 1 bit period
          movwf TMR_PR 
          btfss PORTB,0          ; check status of portB.0
          bcf   STATUS,C         ; move bit into carry
          btfsc PORTB,0          ; check status of portb.0
          bsf   STATUS,C         ; move bit into carry
          rrcf   _rcv_byte,f     ; shift carry into rec'd byte
          decfsz _bit_cntr,f     ; decrement the bit counter
          bra   Donebit          ; get out and wait for next int
          bra Donebyte           ; got 8  bits
    Donebit
          INT_RETURN
          
    Donebyte      
          movff _rcv_byte,_rcv_buffer
    ;TXwait
    ;      btfss  PIR1, TXIF
    ;      bra  TXwait
    ;      movff _rcv_buffer, TXREG
          
          movff _rcv_buffer,PORTD  ; this is a debug, just to see rec'd byte on LEDS
          bcf  TMR_CON,2
          INT_DISABLE  TMR_INT
          INT_CLEAR    INT0_INT
          INT_ENABLE   INT0_INT      ; turn on the INT0 interrupt for next byte
          INT_RETURN
    ENDASM      
          
              
    OVERINT:
    
        TRISD = 0
        PORTD = 0
        TRISE = 0
        INTCON2.6 = 0            ; int0 on falling edge
             
        PAUSE 100
    
    @   INT_CLEAR  INT0_INT  
    @   INT_ENABLE INT0_INT  
      
      
    WAITT:
    
        GOTO WAITT
    HTH,
    DT

Similar Threads

  1. PBP, ASM and LST files
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th January 2010, 13:43
  2. ASM or PBP First?
    By mackrackit in forum Off Topic
    Replies: 4
    Last Post: - 10th October 2009, 12:08
  3. Serial Output - for an ASM numb
    By scomi85 in forum Serial
    Replies: 0
    Last Post: - 1st March 2009, 10:13
  4. Problem using ASM instruction
    By ewandeur in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd April 2008, 15:26
  5. Can an asm interrupt contain gosub to a picbasic routine?
    By sougata in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st April 2005, 19:49

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