ASM code


Closed Thread
Results 1 to 21 of 21

Thread: ASM code

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136

    Default ASM code

    Help please.

    The PIC is an 18F8772 on a Futulec board (so hopefully the wiring is correct).
    I'm trying to use assembler to make the MCU produce two pulse streams for a set number of pulses:

    1. I use TIMER0 and TIMER1 for the inter-pulse delays.
    2. A simple 'count down' for the pulse duration.
    3. A counter that holds the numer of pulses to be generated, this is decremented - and when the counter hits zero - the routine should end.

    The code works OK - BUT! keeps 're-running.' i.e it puts out the required number of pulses, pauses for a bit and then does it all over again.

    Debugging with an ICD2 shows all the SFRs changing properly and the code ending after the requisite number of pulses - but when running normally it just keeps looping.

    The last few lines of ASM code is

    Code:
    Main_loop:                   ; Check if X_steps_lb is zero			tstfsz	X_steps_lb   ; Test, skip next if equal
    	goto	Main_loop    ; More steps to do, so loop	
    	bcf	INTCON,7    ; Disable all high priority interrupts
    	bcf	INTCON,6    ; Disable all low priority interrupts
    	bcf	T0CON,7	    ; Timer0 off
    	bcf	T1CON,0     ; Timer1 off	
    	end
    I've not posted all the code because I don't think anyone would trawl through it.

    The CONFIG settings are:

    Code:
                                               ;  Configuration bits
                 CONFIG  OSC = HSPLL         ; Run at 4X speed
                 CONFIG  CP0=OFF              ; Disable code protect		
                 CONFIG  PWRT = OFF         ; Powerup off so DEBUG works            
                 CONFIG  WDT=OFF             ; WDT off
                 CONFIG  LVP = OFF            ; LVP off
                 CONFIG  WAIT = OFF          ; External bus data wait disabled
    The re-set on MLCR is OK. The IDE is MPLAB. Anyone got any ideas?

    Regards Bill Legge

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Code:
    Main_loop:                   ; Check if X_steps_lb is zero			tstfsz	X_steps_lb   ; Test, skip next if equal
    	goto	Main_loop    ; More steps to do, so loop	
    	bcf	INTCON,7    ; Disable all high priority interrupts
    	bcf	INTCON,6    ; Disable all low priority interrupts
    	bcf	T0CON,7	    ; Timer0 off
    	bcf	T1CON,0     ; Timer1 off	
    END_LOOP:
           GOTO END_LOOP
    	end
    Once it hits END_LOOP it will stay there forever, This is sorta what PBP's END does.. I think//
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default ASM code

    Dave,

    Thanks - I've just tried that and it works fine - the first time in 2 days that I have managed to get the code to output the correct number of pulses.

    However, I presume that when I incorporate the .asm code inside PBP the loop will prevent the .asm from ever finishing?

    ASM
    ; lots of my asm code goes here
    End_loop:
    goto End_loop
    ENDASM

    Any other ideas please? What on earth is making the PIC ignore all the 'end stuff' instructions?

    Regards Bill Legge

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Code:
    ASM
    ; lots of my asm code goes here
    ENDASM
    
    END ' THE PBP TYPE
    When you jump out of the ASM routine and go back to PBP the END command should do what you want.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default ASM code

    Dave,

    Thanks for your support and interest.

    Having got it to work using the 'end-loop' process you suggested, I had a further play-around with the interrupts - and made it work!

    I added the code:

    Code:
    bcf  RCON,7    ; Clear IPEN=0, disable priority interrupts
    And now all is OK.

    If anyone is interested in the code I'm happy to put it up here. The routine uses ASM to:

    1. Drive 2 stepper motors at the same time.
    2. Main purpose is to get diagonal moves on an XY plotter
    3. The asm code is passed parameters by PBP:
    a. X steps to be done
    b. Y steps to be done
    c. X inter-pulse delay
    d. Y inter-pulse delay
    4. Code has yet to be 'polished' and oly works with byte size parameters.
    Next is changing to accept WORD size parameters.

    Once again - thanks for your help.

    Regards Bill Legge

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bill Legge View Post
    Code:
    bcf  RCON,7    ; Clear IPEN=0, disable priority interrupts
    If anyone is interested in the code I'm happy to put it up here. The routine uses ASM to:

    1. Drive 2 stepper motors at the same time.
    2. Main purpose is to get diagonal moves on an XY plotter
    3. The asm code is passed parameters by PBP:
    a. X steps to be done
    b. Y steps to be done
    c. X inter-pulse delay
    d. Y inter-pulse delay
    4. Code has yet to be 'polished' and only works with byte size parameters.
    Next is changing to accept WORD size parameters.
    Hi Bill,
    I would like to see it,
    Thank You.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bill Legge View Post
    I added the code:

    Code:
    bcf  RCON,7    ; Clear IPEN=0, disable priority interrupts
    And now all is OK.
    I have my doubts about that.

    IPEN defaults to 0 on Power-Up/Reset.
    So unless you have another RCON statement in your program that already changed it to 1, that statement will have no effect.
    <br>
    DT

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. Adding PBPro code to an ASM file - how to?
    By wjsmarine in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th January 2010, 18:49
  3. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  4. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  5. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26

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