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

    Default My project is starting

    and I have a need for some advice/suggestions

    First let me say if this should be in a different topic, PLEASE move it.

    Heres the overview:
    I have been working on a machine to cut foam for R/C planes. I am working on this with another guy in Ohio, so not close to me. We have our machines ready now, and of course I am behind on the electronics.

    We will be using EMC2 as our machine controller. Using 2 parallel ports, we will be controlling 6 steppers, 1 spindle, and 1 hot wire. The machine also has travel limits on each end of each axis.

    I have 2 interface cards based around a 16f1947, 1 for each parallel port. these are identical. each card will be responsible for passing step/dir signals through for up to 4 motors(only 3 needed in our app), enable all 4 drives independantly from a single enable output from EMC2. All the limit switches for the 4 axis will be monitored by the card. disable a drive if a limit is hit and pass the home switches back to EMC2.

    Ok, enough of the basics, if anyone is intrested in more detail, just ask.

    On to the problem.
    Talking to a PIC from a serial port will be new to me. Bootloaders are new to me.

    I can write the basic program to just do the above without any problem, but I have much more in store for this card. So I need to get the basic part done and send 2 cards to Ohio. My buddy has no need for a programmer so to get him updates I really want to send him cards pre loaded with a bootloader able to work from rs232 port.

    I don't really know how to get started is my problem. Should I first play with a bootloader and get the LED blinky to work? Should I start with a serial comm program and get that to work? What bootloader should I use? If I need to change any config stuff, will I be able to do that with a bootloader?
    Last edited by cncmachineguy; - 19th November 2010 at 01:20.
    -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
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    I looked to my favorite bootloader, Tiny Pic Bootloader http://www.etc.ugal.ro/cchiculita/so...bootloader.htm, but it does not cover your chip. So I looked around, and found a Microchip Ap Note AN1302. It talks about programming multiple chips through the I2C port. I have not had a chance to read it yet, but this might be good for you. Specially since you need to program two or three chips. It has the hex files, and the PC program here: http://www.microchip.com/stellent/id...pnote=en546181

    With the PIC18 devices you can do a run-time config http://www.picbasic.co.uk/forum/showthread.php?t=4093

    But not with PIC16 devices. So your configs need to be right the first time. But worst case, you could fedex new programmed PICs to your friend in Ohio, if you needed to change configs. (Well at least if it's not surface mount).

    Edit: By the way, sounds like a very cool project. I am going to have to read more about EMC2. I hadn't even heard about it. What is the largest span you can hot wire? Can you post any pictures?
    Last edited by ScaleRobotics; - 19th November 2010 at 02:16.
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default

    Thanks Walter, I will look into the APP note. But I will only have 1 chip per card. I did put an I2C port on board

    As for sending chips back and forth, they are TQFP's. So that option is out. Worse case is I buy a pickit2 and send him to use while I get things going as I want them. Then He can send it back and I will be part of the PK2 club.

    But A bootloader would be too cool, just email program and presto magic.
    -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
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scalerobotics View Post
    Edit: By the way, sounds like a very cool project. I am going to have to read more about EMC2. I hadn't even heard about it. What is the largest span you can hot wire? Can you post any pictures?
    EMC2

    We have designed it to be able to process a 24 x 48 inch piece of foam with the mill or the wire, No pics just yet, but we are about a week out with those. We jumped the gun back in july/aug with pics of our first prototype. so now he is gunshy. Also we completly redesigned it from the first 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!

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


    Did you find this post helpful? Yes | No

    Default

    Sorry, that won't work

    "We can, however, use PC software if we use a device that will act as a master I2C device controlled by PC software. We used the PICkit™ Serial analyzer configured as an I2C master device."


    Since you need a Pickit serial analyzer to make it work, it kind of defeats the purpose. Maybe this one, AN1310: http://www.microchip.com/stellent/id...pnote=en546974
    Last edited by ScaleRobotics; - 19th November 2010 at 02:44.
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default So close

    Just skimed over AN1310. It sounds awesome, but of course it says it uses USART1 and of course I am setup for USART2

    Maybe the firmware can be modified? I will also look at the alternatives listed at the end of the note.
    -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

    Maybe the best choice here is to skip the bootloader for now. It may be I am just a bit overwhelmed with the choices, but getting it to work is really more important then being able to upgrade the firmware in the field. Maybe on the next board rev I will look at changing the usart's but I think I wanted the pins to make something else easy. I don't remember right now.
    -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. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    EMC2...
    Have you tried the new version using Ubunu 10 yet?

    JDM
    I do not normally sugest them but I have bult them into a board for cases like this. Being built in and tweaked for one chip helps their short comings.
    Then use PikLab to squirt the hex.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Haven't tried the new version yet, but I have managed to get the live install on a USB drive and ready to install so I don't need a cd player. I imagine I will have it running over the holiday.

    Jdm- I had never even heard about this programmer until I joined this forum. Building it onto the card is a cool idea, but it missed this rev. I guess I could just build one, but will it really be cost effective when a pickit2 is only $35 for just the programmer?

    As an extra bonus, if I could do all this with ubuntu 10 from the machine controller, now that would be something.

    Alas, I think it's prolly best to leave the field upgrade out of the equation for just now. And if I do that, I don't even need serial comm. Now I can just focus on getting the basic function done so the machines will 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!

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

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


    Did you find this post helpful? Yes | No

    Default

    EDIT: OOPS, you are correct, you would need IOC for portA ... Sorry...
    __________________________________________________ _______________
    RAC_INT is for portA.

    (from http://darreltaylor.com/DT_INTS-14/intro.html )
    RAC_INT -- RA Port Change (for port A)
    RBC_INT -- RB Port Change Interrupt (for port B)
    RABC_INT -- RAB Port Change (for port A or B)

    Here is a small example for RAC_INT , but it's just for a push button.

    http://www.picbasic.co.uk/forum/show...2818#post82818
    Last edited by ScaleRobotics; - 27th November 2010 at 16:53.
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default

    thats OK Walter, you had me thinking for the last hour or 2! (Now have to reset all the smoke alarms)

    But back to it, any thoughts on my timing? Anyone? My brain is still locked about this. I want to draw me some timing diagrams, but it seems I have become so dependent on puters, I don't have any suitable graph paper to do so with. I am somewhat of a stickler when it comes to these things.
    -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!

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


    Did you find this post helpful? Yes | No

    Default

    Doin' what I can
    Attached Images Attached Images
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Inspired by Daves wonderful gift, I worked out some timing in my schmatic program (with snaps). It looks to me with 5uS interupts, I will not miss a single step. I will strech them sometimes and shrink them sometimes, but thats no problem. And I still have 40 instructions between interupts. Well prolly more like 30 when you account for the interupt handler itself.

    So I think I am off to the races now!!
    -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. #15
    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 15:30.
    http://www.scalerobotics.com

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

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

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

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

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