The 16f887 at 20mhx runs the motor control loop at about 1/3 the speed I need. The code space for map storage was chosen for speed of retrieval.
see the forward loop below. The map data comprises 12 maps each with 256 words. The code below is the minimum logic requirement per motor step and needs to execute 180 times for 1 motor revolution. (I am using a stepper driver that needs only single pulse to advance the motor 1/2 step with 90 step motor.). The acdin for position is continually changing and needs to be read on the fly every motor step to update destination as well as speed and current changes.
(serial commands below are comment out used for debug)
Code:
'--------------------------------------------------------------------------------------------------------
fowarddir: 'forward loop
ADCIN 0, freq ' Read channel 0 to freq 0 to 255
Readcode mappos + mapindexcs , cmpos
if (pos > cmpos) and (mappos > 5) then mappos = mappos - 4
'HSEROUT ["d ",dec mappos ,13]
if computercontrol=0 then
Readcode freq + mapindex , des 'read position data from progspace store des
Readcode mappos + spdaddress, speed 'get speed value from codespace
Readcode mappos + curraddress, current 'get current value from codespace
ELSE
SPEED = manspeed
current = mancurrent
endif
HPWM 1,current,200 'current control out
PORTD = 110000 'd4 enable d5 step d6 fwd rev d7 = reset
readcode accaddress , accvalue 'get acc value from code space
PORTD = 010000
pos=pos+1
if speed > ACCVALUE THEN
pauseus SPEED 'step delay to control motor speed
ELSE
pauseus accvalue
ENDIF
'HSEROUT ["sp ",dec SPEED ," ac ", dec ACCVALUE," cur ",dec current,13]
'HSEROUT ["Fwd Accvalue",dec accvalue," Accaddress ",dec accaddress-6928," Des ",dec des-5000," Pos ",dec pos-5000,13]
if pos + accaddress-mapadrs[7] < des and accaddress < mapadrs[8] then accaddress = accaddress + 1
if pos + accaddress-mapadrs[7] > des and accaddress > mapadrs[7] then accaddress = accaddress - 1
if accaddress = mapadrs[7] then goto stoppedstate 'main loop
goto fowarddir
'---------------------------------------------------------------------------------------------------------
Bookmarks