My project is starting - Page 2


Closed Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 41 to 80 of 92
  1. #41
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    I have a problem, not sure where it is. My gut feeling is its with the background things that may be happing when using DT-INT. Here is the entire program.
    Code:
    ' Name        : Interface card.pbp
    ' Compiler    : PICBASIC PRO Compiler 2.6A
    ' Assembler   : MPASM
    ' Target PIC  : 16F1947
    ' Hardware    : PIMill Interface 
    ' Oscillator  : internal
    ' Keywords    : 
    ' Description : PICBASIC PRO program to interface parallel port
    ' to 4 stepper drives and limit switches
    '
    
    '
    ' 
    '
    ' Configure ports
    ' 
    ' 
    ANSELA = %00000000  'port A all digital
    ANSELE = %00000000  'port E all digital
    ANSELF = %00000000  'port F all digital
    ANSELG = %00000000  'port G all digital
    
    CM1CON0 = %00000000  'No comparaters
    CM1CON1 = %00000000
    CM2CON0 = %00000000
    CM2CON1 = %00000000
    
    ' preload latches before setting direction
    LATB = %00000000
    LATC = %00000000
    LATD = %00010000 'LED's 0 for red, 1 FOR GREEN should start red
    LATF = %00001111 ' low nibble is drive enable. 1 disables
    LATG = %00000000
    
    ' I/O direction
    
    TRISA = %11111111'step and dir inputs
    TRISB = %11000001'7-0 icsp,icsp,h4o,h3o,h2o,h1o,estopO,enable In
    TRISC = %00000000'step and dir outputs
    TRISD = %00000000'led6,i2c,i2c,led5,led4,led3,led2,led1
    TRISE = %11111111'ls4,lsh4.ls3,lsh3,ls2,lsh2,ls1,lsh1
    TRISF = %00010000'spindle dir,servo out,dac out,flood input,4en,3en,2en,1en
    TRISG = %11100111'x,x,icsp/mclr,rly2,rly1,Rx2,Tx2,DI
    
    
    
    
    'REMOVE THIS LINE IF NOT SETTING THE CONFIGS IN CODE SPACE
    @ __config _CONFIG1,_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    @ __config _CONFIG2,_WRT_OFF & _VCAPEN_OFF & _PLLEN_ON & _STVREN_OFF & _BORV_25 & _LVP_OFF
    
    'Internal osc setup
    OSCCON = %01110000 'clock is 8 meg. turn on PLL for 32 meg clock
    DEFINE OSC 16 ' 32 meg not allowed according to book. be sure to double things that need this
    
    'Variables
    LED0    VAR LATD.0   ' Assign name "LED" to PORTD
    LED1	VAR LATD.1
    LED2	VAR LATD.2
    LED3    VAR LATD.3
    LED4    VAR LATD.4
    LED5	VAR LATD.7
    CNT 	VAR BYTE
    
    ENALL   VAR PORTB.0
    BSRSTORE VAR BYTE
    
    EN1     VAR LATF.0
    EN2     VAR LATF.1
    EN3     VAR LATF.2
    EN4     VAR LATF.3
    ASM
    	#DEFINE EN1A LATF,0 'stuff for testing
    	
    ENDASM
    wsave VAR BYTE $70 SYSTEM
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    'INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR2_INT,  _FiveMicroSec,   ASM,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    '5.0 uSec OR 200,000 Hz INTERRUPTS
    
    T2CON = %00000100         'Prescaler = 1:1, TMR2ON
    
    'PRELOAD 223 "FROM MULTI-CALC"
    PRELOAD     VAR byte
    PRELOAD =  239 ' FROM TESTING TO FIND THE RIGHT NUMBER
    TMR2 = PRELOAD
    
    @ INT_ENABLE  TMR2_INT     ; enable Timer 2 interrupts
    
    Main:      'DO WHATEVER YOU WANT HERE
     
      
      IF CNT=200 THEN
    	TOGGLE EN2
    	TOGGLE LED1
    	CNT=0
      ENDIF
      TOGGLE LED2
    GOTO Main
    
    
    	
    '---[TMR2 - interrupt handler]--------------------------------------------------
    FiveMicroSec:
    	TMR2 = PRELOAD  'THIS LINE
    	TOGGLE EN1      'AND THIS LINE
    	CNT =CNT+1      'WITH THIS CREATE A INT ROUTINE EVERY 4.99uS
    '	LATC = PORTA    'ADDING THIS LINE CHANGES THE TIME TO 5.245uS!!
                        ' SO WHY DOES THIS CHANGE THE TIMING?@ INT_RETURN
    Now It doesn't make sense to me. I am running a 32mHz clock. 5 uS interupt should takes 160 clock cycles, or 40 asm instructions. my interupt routine has 3 PBP instructions when working and 4 when I add the LATC=PORTA line. I can't imagine that would be 40 lines of ASM. I have tried to do this with a pure ASM handler, but I can only get it to work if I toggle LATA instead of LATF. I am sure this is a bank select issue. I can work through that if I must, but I would really like to use PBP instead.

    Maybe all the time is taken up with the entry and return? Also note the large disparity between what I thought the preload should be and what it is.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default

    Not much help but
    Code:
    OSCCON = %01110000 'clock is 8 meg. turn on PLL for 32 meg clock
    DEFINE OSC 16 ' 32 meg not allowed according to book. be sure to double things that need this
    I think should be
    Code:
    OSCCON = %11110000 'clock is 8 meg. turn on PLL for 32 meg clock
    DEFINE OSC 32 ' 32 meg is allowed according to book. be sure to double things that need this
    ??
    But I could be wrong
    Dave
    Always wear safety glasses while programming.

  3. #43
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    A timer preload of 239 indicates you have only 16 CPU (or ASM) cycles available - looks like 24 cycles are consumed by overhead.

  4. #44
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    And I guess it makes sense that the overhead is in entering the interupt. Otherwise those cycles would be part of the "timer cycle" and not have to be adjusted for in the preload. I think at this point I have 2 options, either use pure ASM interupts and/or increase my timing to 8uS. Maybe I will look at how many instructions it takes to enter the interupt if using pure ASM. This will be the deciding factor I guess. Clearly there is some lag needed to enter the handler, but is it 24 cycles?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #45
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    @Dave, You know I would have bet my left pinky 32 was NOT in the list when I looked up DEFINE OSC, but low and behold it sure is. Thanks for making me look again. As for the bit 7 of OSCON, the way I read it is it is ignored if PLL is enabled in my config-which I think I did. Won't hurt to set it though.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default

    the way I read it is it is ignored if PLL is enabled in my config-which I think I did. Won't hurt to set it though.
    Yup, my mistake.
    Dave
    Always wear safety glasses while programming.

  7. #47
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Thanks Dave, Never hurts to have a second set of eyes on. specialy since I always forget my safty glasses.

    Maybe I should bring this interupt question up in its own thread? I would sure like some input to see if there is something I should be doing different or if I have found the "limit" for DT_INT speed?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  8. #48
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Darrel has a post in here somewhere that says how many instruction cycles an ASM type interrupt has, but I am having a heck of a time trying to find it. I remember it being substantially fewer than PBP type, but can't remember the number. I will try looking some more.
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  10. #50
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    70 cycles are mentioned.
    Yes, 70 instructions cycles to save the registers, and 70 instruction cycles to restore them, but that is for PBP type interrupts. But for ASM type interrupts it is much shorter. I think it is something like 12 or 22 instruction cycles. But then, I can't find it in here or my brain.
    Last edited by ScaleRobotics; - 2nd December 2010 at 22:44.
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  12. #52
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    For those following this thread, see thread split here for more information about assembly DT_INTS interrupts : http://www.picbasic.co.uk/forum/showthread.php?t=14063
    http://www.scalerobotics.com

  13. #53
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Thanks Walter, I was wanting to figure out how to include the other thread so to speak. There is heaps of good stuff in it, so I am glad its not buried in this one.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  14. #54
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default ADD in full swing here

    Well, not that I need to be thinking about this yet, but in anticpation of "phase III" Anybody have any ideas for ram? I think I will be looking for at least 2-4K. The more the merrier. I do have scads of DDR sticks, that would be cool. Or I was thinking about SD cards, they would be way convinent. But at this point I am still just thinking.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default

    SD is kind of slow, I here FRAM is fast.
    Dave
    Always wear safety glasses while programming.

  16. #56
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Pretty cool looking stuff that F-RAM. I ordered some samples of the 5V I2C 512Kb guys. From Mouser I can buy them (Ok, $11 each for these big guys) but free samples is free! I really doubt i need this big. The 64Kb (yes boys and girls - thats kilo-bit) are only $3.xx each in small numbers.

    Thanks Dave, now I can go back to finishing phase I
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  17. #57
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    ...FRAM is fast.
    And they never wear...

    Ioannis

  18. #58
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Things are working, kinda

    Here is my latest code. All this really does is check for switches and disable drives, and shift PORTa to PORTc every 5 uS. It also sends a servo pulse out every 20mS with a pulse time sweeping from 1-2 ms just for testing purposes.

    Right now, everything seems to work, but I need to remove the RED line from the interupt. When I comment it out, it seems to hang in the interupt and never leave. Uncomment and it works again. I have been struggling with this for a week, so I figured I would just ask and get the answer.
    Code:
    ' Name        : Interface card.pbp
    ' Compiler    : PICBASIC PRO Compiler 2.6A
    ' Assembler   : MPASM
    ' Target PIC  : 16F1947
    ' Hardware    : PIMill Interface 
    ' Oscillator  : internal
    ' Keywords    : 
    ' Description : PICBASIC PRO program to interface parallel port
    ' to 4 stepper drives and limit switches
    '
    
    '
    ' 
    '
    ' Configure ports
    ' 
    ' 
    ANSELA = %00000000  'port A all digital
    ANSELE = %00000000  'port E all digital
    ANSELF = %00000000  'port F all digital
    ANSELG = %00000000  'port G all digital
    
    CM1CON0 = %00000000  'No comparaters
    CM1CON1 = %00000000
    CM2CON0 = %00000000
    CM2CON1 = %00000000
    
    ' preload latches before setting direction
    LATB = %00000000
    LATC = %00000000
    LATD = %00010000 'LED's 0 for red, 1 FOR GREEN should start red
    LATF = %00001111 ' low nibble is drive enable. 1 disables
    LATG = %00000000
    
    ' I/O direction
    
    TRISA = %11111111'step and dir inputs
    TRISB = %11000001'7-0 icsp,icsp,h4o,h3o,h2o,h1o,estopO,enable In
    TRISC = %00000000'step and dir outputs
    TRISD = %00000000'led6,i2c,i2c,led5,led4,led3,led2,led1
    TRISE = %11111111'ls4,lsh4.ls3,lsh3,ls2,lsh2,ls1,lsh1
    TRISF = %00010000'spindle dir,servo out,dac out,flood input,4en,3en,2en,1en
    TRISG = %11100111'x,x,icsp/mclr,rly2,rly1,Rx2,Tx2,DI
    
    
    
    
    'REMOVE THIS LINE IF NOT SETTING THE CONFIGS IN CODE SPACE
    @ __config _CONFIG1,_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    @ __config _CONFIG2,_WRT_OFF & _VCAPEN_OFF & _PLLEN_ON & _STVREN_OFF & _BORV_25 & _LVP_OFF
    
    'Internal osc setup
    OSCCON = %11110000 'clock is 8 meg. turn on PLL for 32 meg clock
    DEFINE OSC 32
    
    'Variables
    LED0    VAR PORTD.0   ' Assign name "LED" to PORTD
    LED1	VAR PORTD.1
    LED2	VAR PORTD.2
    LED3    VAR PORTD.3
    LED4    VAR PORTD.4
    LED5	VAR PORTD.7
    
    SERVO   VAR PORTF.6
    CNT 	VAR BYTE
    
    MYFLAGS VAR BYTE
    COUNTUP VAR MYFLAGS.0
    COUNTDN VAR MYFLAGS.1
    MS      VAR MYFLAGS.2
    
    ENALL   VAR PORTB.0
    TEMPF   VAR BYTE
    FRAMECOUNT VAR BYTE
    POS     VAR BYTE
    EN1		VAR PORTF.0
    EN2     VAR PORTF.1
    EN3     VAR PORTF.2
    EN4     VAR PORTF.3
    
    COUNTUP = 1
    COUNTDN = 0
    POS = 1
    FRAMECOUNT = 0
    MS = 0
    CNT = 0
    
    '5.0 uSec OR 200,000 Hz INTERRUPTS
    'PRELOAD 39 PR = NUMBER OF CYCLES-1
    'INT HANDLER COMPLIMENTS OF DARREL TAYLOR 
    PRELOAD     VAR byte
    PRELOAD =  39 ' FROM TESTING TO FIND THE RIGHT NUMBER
    PR2 = PRELOAD
    PIE1.1 = 1        ; Enable Timer2 interrupts
    INTCON.6 = 1      ; enable PEIE
    INTCON.7 = 1      ; enable GIE
    T2CON = %00000100 ; Start Timer2
    
    DEFINE INTHAND _FiveMicroSec
    
    '---[TMR2 - interrupt handler]--------------------------------------------------
    FiveMicroSec:
        LATF = LATF ^ 1     ;  TOGGLE EN1
        CNT =CNT+1
    
        PORTC = PORTA
        PIR1.1 = 0          ; clear the interrupt flag
    @ NOP
    @ RETFIE
    
    
    Main:      'DO WHATEVER YOU WANT HERE
     
      IF ENALL = 0 THEN
       GOTO NOTREADY  
      ELSE  
       GOTO READY 
      ENDIF
    READYRETURN:
      IF CNT >= 200 THEN
    '	TOGGLE EN2
    	TOGGLE LED5
    	CNT=0
        FRAMECOUNT = FRAMECOUNT + 1
        MS = 1
      ENDIF
      IF FRAMECOUNT >=20 THEN
    	FRAMECOUNT = 0
        MS=0
    	HIGH SERVO
    	IF COUNTUP THEN POS = POS + 1
    	IF COUNTDN THEN POS = POS - 1
      ENDIF
       
    '  TOGGLE LED2
      IF PORTE != $FF THEN SWITCHHIT
      
      GOTO SERVOCHECK 
    GOTO Main
    
    SERVOCHECK:
       IF MS =1 THEN
        IF CNT >= POS THEN
         LOW SERVO
    	 MS =0
          
    	 IF (COUNTUP = 1) AND (POS=199) THEN
          COUNTUP = 0
    	  COUNTDN = 1
    	 ELSE 
           IF POS = 1 THEN
    	     COUNTUP = 1
    	     COUNTDN = 0
           ENDIF
         ENDIF
        ENDIF
       ENDIF
       GOTO MAIN	
    SWITCHHIT:
       PORTF = PORTF | $0F
       IF (PORTE = 253) OR (PORTE = 254) THEN LED0 = 0
       IF (PORTE = 247) OR (PORTE = 251) THEN LED1 = 0
       IF (PORTE = 223) OR (PORTE = 239)  THEN LED2 = 0
       IF (PORTE = 127) OR (PORTE = 191) THEN LED3 = 0
    '  ELSE PORTE = PORTE |$0F		
       GOTO MAIN
    
    NOTREADY:
       PORTD = PORTD & $F0
       PORTF = PORTF | $0F
       IF ENALL = 0 THEN NOTREADY
       PORTD = PORTD | $0F
       PORTF = PORTF & $F0
       GOTO MAIN
    READY:
       PORTF = PORTF & $F0
       PORTD = PORTD | $0F
       GOTO READYRETURN
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  19. #59
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default feeling a little lost

    I am used to using the "watch" part of MPLAB to step through a program and look at SFR's and variables. But with PBP program, I see 1 step seems to go several (I assume because of the number of instructions required for a line of code). So as I step through my program, PIE1.1 doesn't change when it clearly should.

    I just don't know HOW to debug using PBP. In this aspect, right now ASM seems easier. Someone PLEASE keep me from going back to the darkside!!
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default

    With Timer2 firing off every 5uS, you're not going to be able to do any meaningful single stepping.

    The interrupt flag will be set again while you are looking at the last "step".
    DT

  21. #61
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    well if Debug with ICD3 does not hold the timer to inc only on an instruction cycle, then that makes sense. Now to the real problem, any idea why I can't rem out the
    Code:
    LATF = LATF ^ 1
    line? With it in the int routine, all seems to work. but if I rem it, it doesn't work. I am checking with a scope and not by single stepping. Also led5 doesn't blink. So I am assuming CNT is not being incremented, which to me says it is not getting out of the int.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default

    In your code from post #58, execution will "Fall into" the ISR, never making it to the Main loop.

    Either put the handler after the main loop, or add a GOTO that jumps over the ISR.
    DT

  23. #63
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Well color me silly!! Ok, I will try that tonight when I get home, Thanks Darrel. I will post my success or failure, what ever the case may be.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  24. #64
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Well here is the modification:
    Code:
    DEFINE INTHAND _FiveMicroSec
    
    GOTO MAIN
    
    '---[TMR2 - interrupt handler]--------------------------------------------------
    FiveMicroSec:
        LATG = LATG ^ 4     ;  TOGGLE EN1
        CNT =CNT+1
    
        PORTC = PORTA
        PIR1.1 = 0          ; clear the interrupt flag
    @ RETFIE
    
    
    Main:      'DO WHATEVER YOU WANT HERE
    As you can see. the only change between last post and this is
    addition of goto main and changed LATF to LATG. The goto main does seem to make it start better, but still can't rem the LATG - LATG ^4.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default

    I do not see that problem here.
    It doesn't make any difference when the LAT line is commented.

    Please tell me that this 5uS doohicky is not running a hobby servo????
    DT

  26. #66
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I do not see that problem here.
    It doesn't make any difference when the LAT line is commented.
    Thats too bad. OK, I will keep struggling with it. The way I am deciding it doesn't work is like this. A) LED5 does not flash anymore, and B)even though you have pointed out I can't single step with TMR2, It does seem to when LAT is not remed. When it is remed, single step makes it appear to stay in the handler. But I have a few more ideas to try. Thanks for looking at it.

    Maybe I am not reming correct. I am putting a ' in the beginning of the line. such as this
    Code:
    '    LATG = LATG ^4
    Please tell me that this 5uS doohicky is not running a hobby servo????
    Would it be TOO much overkill?? No, The servo is just to check 1 output. The entire card is a 4 axis controller with a control for a brushless spindle motor driven from a hobby ESC. The 5uS int is to make sure no steps are missed from the controlling computer. When all is done, the machine is really a 6 axis machine with 2 of these cards running 3 axis each. All this just to cut foam airplanes!!
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  27. #67
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Update

    Well I have no idea whats wrong, and seemingly no way to figrue it out, so for now I will just leave the LAT in. I have re-defined what output it flips so as not to be in the way of my actual use. So far I have tried rem ('), and erasing the whole line. on both tests I just compile and program, board stays in interupt. (Or just sits somewhere). un rem or put the line back in and volia it runs again. I did this about 20 times just to be sure it wasn't something I was doing. I even replaced it with a @NOP just to see if it was some kind of memory placement hic-cup.

    One thing I didn't think to try was changing it to toggle a variable instead of an output. I will try that tonight.

    On the good news side of things, The board and program work as desired (as long as LAT line is there). Now for some cleanup things and add in the serial com to change things like spindle speed. I am sure there will be more issues when this is attempted, but hey, thats all the fun

    Phase 1 almost complete!
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by cncmachineguy View Post
    On the good news side of things, The board and program work as desired (as long as LAT line is there).
    That's too bad.
    I was going to suggest doing it a different way.

    If the inputs on PORTA were moved to PORTB, you could use the IOC interrupts to transfer everthing to PORTC.
    Then it only interrupts when the pins change, leaving much more time for the main program.

    Oh well, too late.
    DT

  29. #69
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    There was some reason I didn't want to use PORTB. Maybe cuz I like to leave the ICSP pins for just only that. In hindsight, and maybe moving forward, I may change it. For now it's just fine. In the current configuration there really is not much for the MAIN to do, and its not time critical. This phase is really just a stepping stone to the planned use for this. somewhere back in this thread, Walter had asked why move the step/dir through the chip at all. Short answer was as a stepping stone.

    When I get to phase 3 of this project, the 5uS interupt won't be needed at all. (post 39 shows my plans)

    Thank you for your help Darrel.
    Last edited by cncmachineguy; - 15th December 2010 at 18:12.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  30. #70
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default I think I found the problem

    I think I have found the problem with interupt. When the interupt hangs and won't leave, it seems BSR=5, when this happens PIR1.1 doesn't get cleared so it just re-enters the int. So the question is, why doesn't PBP make sure the BSR=0 before it tries to PIR1.1=0?

    Or the bigger question is why does it work for Darrel???

    I am posting the program as it is right now, I am using MPLAB, chooseing MPLAB SIM from the debugger menu. then choose the >> not > to animate the program. With this you can see it enter the interupt and leave. I left it running for about 30 min without issue. rem the LAT line and instant hang. sometimes it takes a few times through to get stuck.

    PLEASE, can I get a few people to try this so at least I will know I am not going crazy!!

    Code:
    ' Name        : Interface card.pbp
    ' Compiler    : PICBASIC PRO Compiler 2.6A
    ' Assembler   : MPASM
    ' Target PIC  : 16F1947
    ' Hardware    : PIMill Interface 
    ' Oscillator  : internal
    ' Keywords    : 
    ' Description : PICBASIC PRO program to interface parallel port
    ' to 4 stepper drives and limit switches
    '
    
    '
    ' 
    '
    ' Configure ports
    ' 
    ' 
    ANSELA = %00000000  'port A all digital
    ANSELE = %00000000  'port E all digital
    ANSELF = %00000000  'port F all digital
    ANSELG = %00000000  'port G all digital
    
    CM1CON0 = %00000000  'No comparaters
    CM1CON1 = %00000000
    CM2CON0 = %00000000
    CM2CON1 = %00000000
    
    ' preload latches before setting direction
    LATB = %00000000
    LATC = %00000000
    LATD = %00010000 'LED's 0 for red, 1 FOR GREEN should start red
    LATF = %00001111 ' low nibble is drive enable. 1 disables
    LATG = %00000000
    
    ' I/O direction
    
    TRISA = %11111111'step and dir inputs
    TRISB = %11000001'7-0 icsp,icsp,h4o,h3o,h2o,h1o,estopO,enable In
    TRISC = %00000000'step and dir outputs
    TRISD = %00000000'led6,i2c,i2c,led5,led4,led3,led2,led1
    TRISE = %11111111'ls4,lsh4.ls3,lsh3,ls2,lsh2,ls1,lsh1
    TRISF = %10010000'manual ready,servo out,dac out,flood input,4en,3en,2en,1en
    TRISG = %11100111'x,x,icsp/mclr,rly2,rly1,Rx2,Tx2,SPINDLE ON
    
    
    
    
    'REMOVE THIS LINE IF NOT SETTING THE CONFIGS IN CODE SPACE
    @ __config _CONFIG1,_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    @ __config _CONFIG2,_WRT_OFF & _VCAPEN_OFF & _PLLEN_ON & _STVREN_OFF & _BORV_25 & _LVP_OFF
    
    'Internal osc setup
    OSCCON = %11110000 'clock is 8 meg. turn on PLL for 32 meg clock
    DEFINE OSC 32
    DEFINE NO_CLRWDT 1
    
    'Variables
    'Port assignments
    '------------------port B
    ENALL   VAR PORTB.0
    ESTOPO  VAR PORTB.1
    HO1	    VAR PORTB.2
    HO2		VAR PORTB.3
    HO3		VAR PORTB.4
    HO4		VAR PORTB.5
    '------------------port D
    LED0    VAR PORTD.0   
    LED1	VAR PORTD.1
    LED2	VAR PORTD.2
    LED3    VAR PORTD.3
    LED4    VAR PORTD.4
    LED5	VAR PORTD.7
    '------------------port F
    EN1		VAR PORTF.0
    EN2     VAR PORTF.1
    EN3     VAR PORTF.2
    EN4     VAR PORTF.3
    DIGIN   VAR PORTF.5
    SERVO   VAR PORTF.6
    MANREADY VAR PORTF.7
    '------------------port G
    SPINON  VAR PORTG.0
    RLY1    VAR PORTG.3
    RLY2    VAR PORTG.4
    '---------------------Bytes 
    CNT 	VAR BYTE
    FRAMECT VAR BYTE
    POS     VAR BYTE
    MYFLAGS VAR BYTE
    PRELOAD VAR BYTE
    SPEED   VAR BYTE
    DUMRUN  VAR BYTE
    '---------------------Bits
    COUNTUP VAR MYFLAGS.0
    COUNTDN VAR MYFLAGS.1
    MS      VAR MYFLAGS.2
    LIMIT   VAR MYFLAGS.3
    DRIVEON VAR MYFLAGS.4
    HOMED   VAR MYFLAGS.5
    '---------------------INIT VARIABLE VALUE
    COUNTUP = 1
    COUNTDN = 0
    POS = 127
    FRAMECT = 0
    MS = 0
    HOMED = 0
    CNT = 0
    SPEED = 0
    PRELOAD =  39 'PRELOAD 39 PR = NUMBER OF CYCLES-1
    
    '5.0 uSec OR 200,000 Hz INTERRUPTS
    'INT HANDLER COMPLIMENTS OF DARREL TAYLOR 
    PR2 = PRELOAD
    PIE1.1 = 1        ; Enable Timer2 interrupts
    INTCON.6 = 1      ; enable PEIE
    INTCON.7 = 1      ; enable GIE
    T2CON = %00000100 ; Start Timer2
    
    DEFINE INTHAND _FiveMicroSec
    
    GOTO START
    
    START:
       GOSUB NOTREADY
    
    
    Main:      'DO WHATEVER YOU WANT HERE
       IF DRIVEON = 0 THEN
        GOSUB CHECKREADY
       ENDIF
       IF (ENALL = 0) AND (DRIVEON = 1) THEN
    	GOSUB NOTREADY
       ENDIF
       IF (MANREADY = 0) AND (DRIVEON = 1) THEN
    	GOSUB NOTREADY
       ENDIF
       IF (LIMIT = 1) AND (PORTE = $FF) THEN
        GOSUB READY
       ENDIF
       IF SPINON THEN
        SPEED=POS
        RLY1 = 1
       ELSE 
        SPEED = 0
    	RLY1 = 0
       ENDIF
       IF DIGIN THEN
    	RLY2 = 1
       ELSE
    	RLY2 = 0
       ENDIF
    
    READYRETURN:
      IF CNT >= 200 THEN
    	TOGGLE LED5
    	CNT=0
        FRAMECT = FRAMECT + 1
        MS = 1
      ENDIF
      IF FRAMECT >=20 THEN
    	FRAMECT = 0
        MS=0
    	HIGH SERVO
      ENDIF
       
      IF PORTE != $FF THEN 
       GOSUB SWITCHHIT
      ENDIF
      GOSUB SERVOCHECK 
    GOTO Main
    
    SERVOCHECK:
       IF MS =1 THEN
        IF CNT >= SPEED THEN
         LOW SERVO
    	 MS =0
        ENDIF
       ENDIF
       RETURN	
    
    SWITCHHIT:
       IF HOMED=0 THEN
        GOTO HOMESWITCH
       ENDIF
       ESTOPO = 1
       PORTF = PORTF | $0F
       IF (PORTE = 253) OR (PORTE = 254) THEN LED0 = 0
       IF (PORTE = 247) OR (PORTE = 251) THEN LED1 = 0
       IF (PORTE = 223) OR (PORTE = 239) THEN LED2 = 0
       IF (PORTE = 127) OR (PORTE = 191) THEN LED3 = 0
       LIMIT = 1
       DRIVEON = 0		
       RETURN
    
    HOMESWITCH:
       IF PORTE = 253 THEN HO1=1
       IF PORTE = 247 THEN HO2=1
       IF PORTE = 223 THEN HO3=1
       IF PORTE = 127 THEN HO4=1
       IF PORTE = 85 THEN HOMED = 1	
       RETURN
    NOTREADY:
       PORTD = PORTD & $F0
       PORTF = PORTF | $0F
       DRIVEON = 0
       HOMED = 0
       RETURN
    
    CHECKREADY:
       IF ENALL = 0 THEN RETURN
       IF MANREADY = 0 THEN RETURN
       IF LIMIT = 1 THEN RETURN
    
    READY:
       PORTD = PORTD | $0F
       PORTF = PORTF & $F0
       DRIVEON = 1
       LIMIT = 0
       RETURN
    
    '---[TMR2 - interrupt handler]--------------------------------------------------
    FiveMicroSec:
        LATF = LATF ^ 32     ;  TOGGLE DAC
        CNT =CNT+1
    
        PORTC = PORTA
        PIR1.1 = 0          ; clear the interrupt flag
    @ RETFIE
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  31. #71
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Don't know why I need it, but this works:

    Code:
    FiveMicroSec:
    '    LATF = LATF ^ 32     ;  TOGGLE DAC
        CNT =CNT+1
        BSR = 0
        PORTC = PORTA
        PIR1.1 = 0          ; clear the interrupt flag
    @ RETFIE
    I mean, I get why setting BSR=0 fixes it, just don't know why I need to.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default

    Just a shot in the dark....
    Code:
    CNT  VAR  BYTE  BANK 0
    Dave
    Always wear safety glasses while programming.

  33. #73
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    OHH, great idea!! Thanks Dave, I will try this now.

    So sad, got an error : Bad BANK number
    Last edited by cncmachineguy; - 21st December 2010 at 00:52.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default

    Have you tried any of this in real life? Or just SIM?
    Dave
    Always wear safety glasses while programming.

  35. #75
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    its all in real life. I only use the MPLAB SIM when I have a problem I can't reason out, like why does the int hang. for that i need to see registers. But it showed up in real life first by my LED not flashing.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default

    Further explanation after my reply in the "Bug" thread.

    When there was ...

    LATF = LATF ^ 1

    LATF is is BANK7, and since PBP thought it was in BANK0, it would have changed to BANK7 to access LATF, and at that point it knew it was in BANK7.
    So then it changed back to BANK0 to access CNT, PORTA, PORTC etc.

    When the LATF statement was commented, it thought it was still in BANK0, and didn't try to change the bank, not knowing what bank it was really in at the start of the interrupt.

    Remember that this type of ASM interrupt using PBP statements, goes against the standard rules of interrupts.

    I'm still embarrassed though.
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I'm still embarrassed though.
    Why???

    So
    BSR = 0
    at the beginning of the ISR will do what with LATF?

    I thought it had something to do with being in the wrong bank, but like you said CNT was already in BANK 0.
    Remember that this type of ASM interrupt using PBP statements, goes against the standard rules of interrupts.
    How should this be done? I am getting more confused than normal.
    Dave
    Always wear safety glasses while programming.

  38. #78
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    I think PBP assumes its in BANK0 unless it does something in a different bank. Since LATF is not in BANK0, PBP will clear the BSR after executing LATF line. When I comment LATF line, sometimes the Interupt occurs during an instruction where BSR !=0, so in the interupt PBP assumes BANK0 for the BANK0 stuff.

    Does this make sense? Setting BSR=0 upon entering the ISR will make sure PBP is not confused

    Thank you Darrel for letting me keep some of my hair so I can pull it out on the next problem.
    Last edited by cncmachineguy; - 21st December 2010 at 04:05. Reason: typo
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  39. #79
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Remember that this type of ASM interrupt using PBP statements, goes against the standard rules of interrupts.
    Well I am not too sure where the standard rules for interupts can be found, but in this instance, I am using PBP statements but ignoring all PBP context when entering and exiting the ISR. If I had actually written this in ASM, I MAY not have had this problem because I MIGHT have remembered to set BSR to what I needed. But at least I would NOT have thought it was a PBP issue.

    At the end of the day, it is really my lack of understanding how PBP thinks. Now that I realize PBP assumes BANK0 all the time (maybe I even read that in the manual), I see why this is broke and why it is my fault as the programmer.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  40. #80
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    When the LATF statement was commented, it thought it was still in BANK0, and didn't try to change the bank, not knowing what bank it was really in at the start of the interrupt.
    How did Protus make this work???
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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