Inline Asm Problem


Closed Thread
Results 1 to 7 of 7
  1. #1

    Default Inline Asm Problem

    Hello group,

    I am trying to get an adjustable delay routine that is less than 1us increaments i.e (pauseus). I use to program in assembly and had a working delay routine. It took three machine cycles to decrement the counter by one. Using
    a 40mhz it should have a 300ns resolution. It is adjustable by taking a adc reading in pbp and passing the variable to the inline assembly routine. When I compile it in PBP3 it produces some errors. Using a PIC18F25K80. If anyone knows why it won't compile or has an alternate idea, I would be greatful.

    Thanks
    Mark

    See screen capture of error messages
    Name:  error.pg.JPG
Views: 277
Size:  71.0 KB

    Code:
    ' Name  : Asm delay test
    'pic18f25k80  10mhz x 4pll 40mhz
    'pbp 3.07
    'CONFIGS sec osc set to digital i/o,intoscio off, hs-pll on,SECONDARY OSC OFF, ext intructions off
    'configs set in melabs u2 programmer
    '------------------------------------------------------
    DEFINE OSC 40    '64mhz
    
    REFOCON = 0          'Ref osc off
    '--------------------------------------------------    
    ODCON = 0          '   OPEN DRAIN OFF , CONNECTED TO VDD
    'ADC-----------------------------------------------------		    
    ADCON0 = %00000101 ' A/D module enabled, channel 1
    ADCON1 = %01110000 '%01110000 Vref = INT 4096, TRIG ctmu, NEG REF VSS
    ADCON2 = %10010100 ' Right justified, 12 Tad, Frc clock
    ANCON1 = %00000000  'Select Digital or Analog AN8 - AN14
    SLRCON = 0 'SLEW RATE STANDARD
    '-------------------------------------------------------------
    'COMPARATOR      '*********SET TRIS INPUTS
    CM1CON = 0 '%11000000    'COMPARATOR 1 on all pins external
    CM2CON = 0 '%11000000    'COMPARATOR 2 on all pins external              
    CVRCON = %00100111    'COMPARATOR vref off
    '--------------------------------------------
    CTMUCONH = 0  'Charge time measurement unit off
    'MSSP-------------------------------------------
    SSPSTAT = %00000000   'TX IDLE LOW,SAMPLE MIDDLE
    SSPCON1 = 0'%00100001 ' ENABLE MSSP,CLK IDLE LOW,FOSC/4
    '-----------------------------------------------------------------------
    TRISA = %00000111
    TRISB = %00000000
    TRISC = %00010000
    
    AUX1 VAR LATC.0  ' output
    Delay1 var word 
    Temp1  var word
    adc_an1 var word
    
    
    '-------------------------------------------
    mainloop:
    
    gosub get_adc 
    
    LATC.0 = 1 'Portc.0 High
    
    ; Delay routine 3 cycles for each count. Number of loops = adc read
    ; at 40mhz delay should have 300ns resolution
    ASM      
       movfw  _Delay1
       movwf  _Temp1
       decfsz _Temp1,1
       goto   $-1
    Endasm
    LATC.0 = 0 'Portc.0 Low
    
    pauseus 500
    
       Goto mainloop
    '------------------------------------------      
    get_adc:  '12bit
       ADCON0 = %00000111  'SAMPLE AN1 
                       '
     WHILE ADCON0.1 = 1  'WAIT FOR CONVERSION
        WEND
         ADC_AN1.HIGHBYTE = ADRESH
         ADC_AN1.LOWBYTE  = ADRESL
            DELAY1 = 1 + adc_an1  '1 to 4097
    Return
       End
    Last edited by mark_s; - 26th February 2016 at 19:59.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Inline Asm Problem

    Hi Mark,
    I'm really bad at assembly language but as far as I can see from the instruction set summary in the datasheet there is no MOVFW instruction.

    The Destination adress must be Word aligned-warning is probably because on the 18F series the program counter adresses bytes while the instructions are WORDS so you need jump in increments of 2.

    Finally, your variables are WORDs but I'm not sure you're catering for that in your assemble routine but then again, I'm really bad at it so perhaps you are.

    /Henrik.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Inline Asm Problem

    Delay1 var word
    Temp1 var word

    ASM
    movfw _Delay1
    movwf _Tem p1
    decfsz _Temp1,1
    goto $-1
    Endasm
    IT'S a 8 bit cpu how can a 16 bit value fit in a 8 bit register ?



    Code:
    Delay1 var byte  
    Temp1  var byte 
    
    
    asm
           MOVE?BB   _Delay1, _Temp1
    DLN    decfsz _Temp1,1
           goto   DLN
    endasm

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Inline Asm Problem

    Thanks Henrik,

    On your first point, I'll restudy the data sheet for the proper command. I might of reversed the WF when entering the code.

    Second point makes sense also. The asm delay routine was being used for pic16f's and worked. I have run into the count by two
    before on pic18's. So I know what you mean. Still interested in alternative.

    Regards
    Mark

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Inline Asm Problem

    Thanks Richard,

    I will give it a try. It's been a long time since I used the code, and It probably was a byte variable.


    It compiles fine here. I will try it on hardware later.

    Cheers!
    Last edited by mark_s; - 26th February 2016 at 21:39.

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Inline Asm Problem

    It’s crying because there’s no such movfw instruction, only movf.

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Inline Asm Problem

    Already been said... Captain obvious!

Similar Threads

  1. ASM - Problem at first step!
    By Megahertz in forum Off Topic
    Replies: 13
    Last Post: - 27th July 2011, 00:43
  2. Problem with -ASM
    By Megahertz in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th May 2011, 16:29
  3. Problem using ASM instruction
    By ewandeur in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd April 2008, 15:26
  4. LCD 16 characters inline: only first 8 work
    By Mugel in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th October 2006, 22:07
  5. problem with asm interrupt
    By servo260 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th December 2004, 17:02

Members who have read this thread : 1

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