My project is starting


Closed Thread
Results 1 to 40 of 92

Hybrid View

  1. #1
    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!

  2. #2
    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!

  3. #3
    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

  4. #4
    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!

  5. #5
    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

  6. #6
    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!

  7. #7
    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!

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