My project is starting


Closed Thread
Results 1 to 40 of 92

Hybrid View

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

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

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

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

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

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

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

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