My project is starting


Closed Thread
Results 1 to 40 of 92

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Ok, I found a scheme of the parallel port for EMC

    http://gramlich.net/projects/cnc/controller/index.html

    Oops, I see your answer now. Thanks Bert!
    Last edited by ScaleRobotics; - 28th November 2010 at 16:30.
    http://www.scalerobotics.com

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

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

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

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

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

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

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