Besser so

Code: Alles auswählen
DAT
Servos org 'Assembles the next command to the first cell (cell 0) in the new cog's RAM
Loop mov dira,ServoPin1 'Set the direction of the "ServoPin1" to be an output (and all others to be inputs)
rdlong HighTime,p1 'Read the "position1" variable from Main RAM and store it as "HighTime"
mov counter,cnt 'Store the current system clock count in the "counter" cell's address
mov outa,AllOn 'Set all pins on this cog high (really only sets ServoPin1 high b/c rest are inputs)
add counter,HighTime 'Add "HighTime" value to "counter" value
waitcnt counter,0 'Wait until cnt matches counter (adds 0 to "counter" afterwards)
mov outa,#0 'Set all pins on this cog low (really only sets ServoPin1 low b/c rest are inputs)
mov dira,ServoPin2 'Set the direction of the "ServoPin2" to be an output (and all others to be inputs)
rdlong HighTime,p2 'Read the "position2" variable from Main RAM and store it as "HighTime"
mov counter,cnt 'Store the current system clock count in the "counter" cell's address
mov outa,AllOn 'Set all pins on this cog high (really only sets ServoPin2 high b/c rest are inputs)
add counter,HighTime 'Add "HighTime" value to "counter" value
waitcnt counter,0 'Wait until cnt matches counter (adds 0 to "counter" afterwards)
mov outa,#0 'Set all pins on this cog low (really only sets ServoPin2 low b/c rest are inputs)
mov dira,ServoPin3 'Set the direction of the "ServoPin3" to be an output (and all others to be inputs)
rdlong HighTime,p3 'Read the "position3" variable from Main RAM and store it as "HighTime"
mov counter,cnt 'Store the current system clock count in the "counter" cell's address
mov outa,AllOn 'Set all pins on this cog high (really only sets ServoPin3 high b/c rest are inputs)
add counter,HighTime 'Add "HighTime" value to "counter" value
waitcnt counter,0 'Wait until cnt matches counter (adds 0 to "counter" afterwards)
mov outa,#0 'Set all pins on this cog low (really only sets ServoPin3 low b/c rest are inputs)
mov dira,ServoPin4 'Set the direction of the "ServoPin4" to be an output (and all others to be inputs)
rdlong HighTime,p4 'Read the "position4" variable from Main RAM and store it as "HighTime"
mov counter,cnt 'Store the current system clock count in the "counter" cell's address
mov outa,AllOn 'Set all pins on this cog high (really only sets ServoPin3 high b/c rest are inputs)
add counter,HighTime 'Add "HighTime" value to "counter" value
waitcnt counter,LowTime 'Wait until "cnt" matches "counter" then add a 10ms delay to "counter" value
mov outa,#0 'Set all pins on this cog low (really only sets ServoPin4 low b/c rest are inputs)
waitcnt counter,0 'Wait until cnt matches counter (adds 0 to "counter" afterwards)
jmp #Loop 'Jump back up to the cell labled "Loop"
'Constants and Variables:
ServoPin1 long |< 4 '<------- This sets the pin that outputs the first servo signal (which is sent to the white
' wire on most servomotors). Here, this "6" indicates Pin 6. Simply change the "6"
' to another number to specify another pin (0-31).
ServoPin2 long |< 5 '<------- This sets the pin that outputs the second servo signal (could be 0-31).
ServoPin3 long |< 6 '<------- This sets the pin that outputs the third servo signal (could be 0-31).
ServoPin4 long |< 7 '<------- This sets the pin that outputs the third servo signal (could be 0-31).
p1 long 0 'Used to store the address of the "position1" variable in the main RAM
p2 long 0 'Used to store the address of the "position2" variable in the main RAM
p3 long 0 'Used to store the address of the "position2" variable in the main RAM
p4 long 0 'Used to store the address of the "position2" variable in the main RAM
AllOn long $FFFFFFFF 'This will be used to set all of the pins high (this number is 32 ones in binary)
LowTime long 800_000 'This works out to be a 10ms pause time with an 80MHz system clock. If the
' servo behaves erratically, this value can be changed to 1_600_000 (20ms pause)
counter res 'Reserve one long of cog RAM for this "counter" variable
HighTime res 'Reserve one long of cog RAM for this "HighTime" variable
fit 'Makes sure the preceding code fits within cells 0-495 of the cog's RAM