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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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 osc=int ;use internal clock
;----- Constants
;----- 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
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.
This line is the cluprit. The first enty has too many single quotes ...
Use this instead..
Or this .... and get rid of the quote marks completely
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
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?
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:
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
This gives undefined variable error but in help #define var1 8 works. Below above array code in help.
'Stan where? Where does it say this?'
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.
from help/syntax/arrays
Last edit: stan cartwright 2017-12-08