Stepper motor lib

17 views
Skip to first unread message

Hans van Veldhuizen

unread,
Apr 9, 2021, 4:05:41 AM4/9/21
to jallist
Several years ago i have made a stepper program mysellf for bipolar types. It worked but in a (very!) simple way. 
Now I have to change to unipolar types and i have tried the great 16F630_stepper_unipolar_blocked.jal in a 16F648 and 16F877a 
This works great but ik use 3 steppers commanded bij one PIC. (working one by one). I have studied the libs but it's to compilicated for me. 
Have someone already an example how to use this in my need?
Thanks 
Hans

Hans van Veldhuizen

unread,
Apr 10, 2021, 7:37:02 AM4/10/21
to jallist
Here is an example of the old one i have used untill now..
--------------------------------------------------------------------------------------------
--1877aa_stepper_test_2
include 16f877a                     -- target PICmicro
--
-- This program assumes that a 20 MHz resonator or crystal
-- is connected to pins OSC1 and OSC2.
pragma target clock 20_000_000      -- oscillator frequency
--
pragma target OSC      HS                        -- crystal or resonator
pragma target WDT      DISABLED                  -- watchdog
pragma target DEBUG    DISABLED                  -- no debugging
pragma target BROWNOUT DISABLED                  -- no brownout reset
pragma target LVP      DISABLED---ENABLED                   -- low voltage programming
--
-- The configuration bit settings above are only a selection, sufficient
-- for this program. Other programs may need more or different settings.
--
--
enable_digital_io()                 -- make all pins digital I/O

-- library with delay procedures
include delay

--
portA_low_direction = all_output   -- is V_stapper
portB_high_direction = all_output  -- is H_stapper
portD_low_direction = all_output  -- is D_stapper


portA_low = 0 -- V stapper
portB_high= 0  -- H stapper
portD_low = 0 -- V stapper
 
var byte step ----- variabele stapgrootte bij vol en half stap
var byte V_stapper = 0B_0001
var byte H_stapper = 0B_0001
var byte D_stapper = 0B_0001

var word actual_V_pos = 1
var word target_V_pos
var word actual_H_pos
var word target_H_pos
var word actual_D_pos
var word target_D_pos

var byte wacht_V = 1
var byte wacht_H = 1
var byte wacht_D = 1



include STEP_ROUTER_TEST


forever loop
 for 200 loop full_stap_V_up end loop
  delay_1S(1)
   
 for 200 loop full_stap_V_down end loop
  delay_1S(1)

 for 200 loop half_stap_V_up end loop
  delay_1S(1)

 for 200 loop half_stap_V_down end loop
  delay_1S(1)

-- can be repeated for H_up/down and D_up/down
-- actual_.._pos shows position
-- target ... pos is not used here





 delay_1S(2)
end loop
===============================================================================
and this one :

-- steprouter test


procedure stepper_motor_full_backward( byte in out x ,byte out y) is
x = x & 0b_1111
y = 0
if x == 0b_0001 then -- 1
x = 0b_0011
y=1
return
end if
if x == 0b_0011 then  -- 2
x = 0b_0110
y = 2
return
end if
if x == 0b_0010 then   -- 3
x = 0b_0110
y = 1
return
end if
if x == 0b_0110 then   -- 4
x = 0b_1100
y = 2
return
end if
if x == 0b_0100 then    -- 5
x = 0b_1100
y = 1
return
end if
if x == 0b_1100 then     -- 6
x = 0b_1001
y = 2
return
end if
if x == 0b_1000 then      -- 7
x = 0b_1001
y = 1
return
end if
if x == 0b_1001 then
x = 0b_0011               -- 8
y = 2
return
end if
x = 0b_0011
y = 0

end procedure
  --
procedure stepper_motor_full_forward( byte in out x ,byte out y) is
x = x & 0b_1111
y = 0
if x == 0b_1000 then -- 1
x = 0b_1100
y = 1
return
end if
if x == 0b_1100 then  -- 2
x = 0b_0110
y = 2
return
end if
if x == 0b_0100 then   -- 3
x = 0b_0110
y = 1
return
end if
if x == 0b_0110 then    -- 4
x = 0b_0011
y = 2
return
end if
if x == 0b_0010 then     -- 5
x = 0b_0011
y = 1
return
end if
if x == 0b_0011 then      -- 6
x = 0b_1001
y =2
return
end if
if x == 0b_0001 then       -- 7
x = 0b_1001
y = 1
return
end if
if x == 0b_1001 then
x = 0b_1100                -- 8
y = 2
return
end if
x = 0b_1100
y = 2
end procedure

--------------------
 procedure stepper_motor_half_backward( byte in out x,byte out y ) is
y = 1
x = x & 0b_1111
if x == 0b_0001 then --1
x = 0b_0011
return
end if
if x == 0b_0011 then -- 2
x = 0b_0010
return
end if
if x == 0b_0010 then  -- 3
x = 0b_0110
return
end if
if x == 0b_0110 then   -- 4
x = 0b_0100
return
end if
if x == 0b_0100 then    -- 5
x = 0b_1100
return
end if
if x == 0b_1100 then     -- 6
x = 0b_1000
return
end if
if x == 0b_1000 then      -- 7
x = 0b_1001
return
end if
if x == 1001 then
x = 0b_0001
return
end if
x = 0b_0001


end procedure
  --
procedure stepper_motor_half_forward( byte in out x,byte out y ) is
y = 1
x = x & 0b_1111
if x == 0b_1000 then  -- 1
x = 0b_1100
return
end if
if x == 0b_1100 then  -- 2
x = 0b_0100
return
end if
if x == 0b_0100 then  -- 3
x = 0b_0110
return
end if
if x == 0b_0110 then  -- 4
x = 0b_0010
return
end if
if x == 0b_0010 then  -- 5
x = 0b_0011
return
end if
if x == 0b_0011 then  -- 6
x = 0b_0001
return
end if
if x == 0b_0001 then  -- 7
x = 0b_1001
return
end if
if x == 0b_1001 then   -- 8
x = 0b_1000
return
end if
x = 0b_1000
end procedure
------------------
procedure full_stap_V_up is
Stepper_Motor_full_Forward (V_stapper, step)
portA_low = V_stapper
delay_1mS(wacht_V*2)
actual_V_pos = actual_V_pos + step
end procedure

procedure full_stap_V_down is
Stepper_Motor_full_Backward (V_stapper, step)
portA_low = V_stapper
actual_V_pos = actual_V_pos - step
delay_1mS(wacht_V*2)
end procedure

procedure full_stap_H_up is
Stepper_Motor_full_Backward (H_stapper,step)
portB_high = H_stapper
actual_H_pos = actual_H_pos + step
delay_1mS(wacht_H*2)
end procedure

procedure full_stap_H_down is
Stepper_Motor_full_Forward (H_stapper, step)
portB_high = H_stapper
actual_H_pos = actual_H_pos - step
delay_1mS(wacht_H*2)
end procedure

procedure full_stap_D_up is
Stepper_Motor_full_Backward (D_stapper,step)
portD_low = D_stapper
actual_D_pos = actual_D_pos + step
delay_1mS(wacht_D*2)
end procedure

procedure full_stap_D_down is
Stepper_Motor_full_Forward (D_stapper, step)
portD_low = D_stapper
actual_D_pos = actual_D_pos - step
delay_1mS(wacht_D*2)
end procedure


----------------------------------
procedure half_stap_V_up is
Stepper_Motor_half_Forward (V_stapper, step)
portA_low = V_stapper
actual_V_pos = actual_V_pos + step
delay_1mS(wacht_V)
end procedure

procedure half_stap_V_down is
Stepper_Motor_half_Backward (V_stapper,step)
portA_low = V_stapper
actual_V_pos = actual_V_pos - step
delay_1mS(wacht_V)
end procedure

procedure half_stap_H_up is
Stepper_Motor_half_Backward (H_stapper, step)
portB_high = H_stapper
actual_H_pos = actual_H_pos + step
delay_1mS(wacht_H)
end procedure

procedure half_stap_H_down is
Stepper_Motor_half_Forward (H_stapper, step)
portB_high = H_stapper
actual_H_pos = actual_H_pos -step
delay_1mS(wacht_H)
end procedure

procedure half_stap_D_up is
Stepper_Motor_half_Backward (D_stapper,step)
portD_low = D_stapper
actual_D_pos = actual_D_pos + step
delay_1mS(wacht_D)
end procedure

procedure half_stap_D_down is
Stepper_Motor_half_Forward (D_stapper, step)
portD_low = D_stapper
actual_D_pos = actual_D_pos - step
delay_1mS(wacht_D)
end procedure
Reply all
Reply to author
Forward
0 new messages