Menu

Error: Duplicate, confliciting definitions ???????

Help
Paul Haug
2017-12-06
2017-12-08
  • Paul Haug

    Paul Haug - 2017-12-06

    This is a simple stepper motor program I lifted from examples here. I only changed the PIC type but I get this error:
    "Error: Duplicate, conflicting definition for COILS"
    I am using Ver 0.98.01 (the latest I hope) but can't see why this is flagging this as an error on the statements:
    dim coils(8) as byte.
    ;
    Code as follows.
    .
    ;----- Configuration
    'PicChip Settings.
    #chip 18f27k40, 32
    #config FEXTOSC = OFF, RSTOSC = HFINTOSC_64MHZ, LVP = ON
    #option Explicit
    ;#startup InitPPS, 85

              #config mclr=on          ;reset handled internally
    

    ;#config osc=int ;use internal clock

    ;----- Constants

          #define delay 1200 uS     ;1.2 mS between each pulse
          #define fwd true          ;forward flag
          #define rev false         ;reverse flag
    

    ;----- Variables

    dim i as byte
    dim j as word

    ;----- Arrays

    dim coils(8) as byte
    coils = b'1000'', b'1100', b'0100', b'0110', b'0010', b'0011', b'0001', b'1001'

    ;----- Program

    dir PortB out ;only B.0 through B.3 used
    do
    repeat 2 ;do the cardinal points twice
    repeat 4 ;step off all four cardinal points
    cardinal(fwd) ;go forward
    wait 1 S ;wait a second
    end repeat ;do next cardinal point
    end repeat

    repeat 2 ;do the cardinal points twice
    repeat 4 ;step off all four cardinal points
    cardinal(rev) ;but in reverse this time
    wait 1 S ;wait a second
    end repeat ;do next cardinal point
    end repeat

    revolution(fwd) ;complete revolution forward
    revolution(rev) ;complete revolution backward
    wait 1 S
    loop ;and start over again

    ;----- Subroutines

    sub clockwise ;one step clockwise
    for i = 8 to 1 step -1
    PortB = coils(i)
    wait delay
    next i
    end sub

    sub counterclockwise ;one step counterclockwise
    for i = 1 to 8
    PortB = coils(i)
    wait delay
    next i
    end sub

    sub cardinal(direct as byte)
    repeat 128 ;128 times 0.703125 degrees is 90 degrees
    if direct = fwd then
    clockwise
    else
    counterclockwise
    end if
    end repeat
    end sub

    sub revolution(direct as byte)
    for j = 1 to 512 ;512 times 0.703125 degrees is 360 degrees
    if direct = fwd then
    clockwise
    else
    counterclockwise
    end if
    next j
    end sub

     
  • stan cartwright

    stan cartwright - 2017-12-06

    I think dim coils(8) as byte
    coils = b'1000'', b'1100', b'0100', b'0110', b'0010', b'0011', b'0001', b'1001'
    should be- coils(1)=b'1000:coils(2)=b'1100 etc
    You could read the values to the coils array from a table in a loop.

     
  • William Roth

    William Roth - 2017-12-06

    This line is the cluprit. The first enty has too many single quotes ...

    coils = b'1000'', b'1100', b'0100', b'0110', b'0010', b'0011', b'0001', b'1001'
    

    Use this instead..

    coils = b'1000', b'1100', b'0100', b'0110', b'0010', b'0011', b'0001', b'1001'
    

    Or this .... and get rid of the quote marks completely

    coils = 0b1000, 0b1100, 0b0100, 0b0110, 0b0010, 0b0011, 0b0001, 0b1001
    
     
  • Paul Haug

    Paul Haug - 2017-12-07

    Thanks for the input. I must be going blind not to see the double quote error.
    I eliminated the qoutes as suggested and all asm correctly.

     

    Last edit: Paul Haug 2017-12-07
  • stan cartwright

    stan cartwright - 2017-12-07

    I didn't know vars in arrays could declared like - coils = b'1000', b'1100', b'0100', or I would used that method. Where is it shown in help?

     
    • William Roth

      William Roth - 2017-12-07

      Help > Syntax > Arrays

      =============================
      Setting an entire array at once

      It is possible to set several elements of an array with a single line of code. This short example shows how:

      Dim TestVar(10)
      TestVar = 1, 2, 3, 4, 5, 6, 7, 8, 9
      

      When using the method above element 0 of the array TestVar will be set to the number of items in the list, which in this case is 9. Each element of the array will then be loaded with the corresponding value in the list - so in the example, TestVar(1) will be set to 1, TestVar(2) to 2, and so on. Element 0 will only be set to number of items in the array when using this method up to 48 data elements.

      ==================================

      Stan, this is what Paul did, excpet that he used binary format for the numbers. Typically this method is used when the data in the array remains static. So int the case of Pauls application the array is read sequentially in a loop to drive a stepper motor

       

      Last edit: William Roth 2017-12-07
  • stan cartwright

    stan cartwright - 2017-12-07

    This gives undefined variable error but in help #define var1 8 works. Below above array code in help.

    dim var1 as byte
    var1=8
    dim var2(var1) as byte
    
     
    • Anobium

      Anobium - 2017-12-07

      'Stan where? Where does it say this?'

       
  • stan cartwright

    stan cartwright - 2017-12-08

    I meant my code I posted Nov22 doesn't work. You said "use a constant" by which I thought you meant a number not a defined var value as in help. Sorry for confusion.

    dim var1 as byte
    var1=8
    dim var2(var1) as byte ;thinks gives error
    

    from help/syntax/arrays

        #Define ArraySizeConstant 500
        Dim TestVar( ArraySizeConstant )
    
     

    Last edit: stan cartwright 2017-12-08

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.