Posted on Leave a comment

How to use S109AFTG Microstep Driver with ATmega328PB Programmed using Microchip Studio

When I opened the case. I found a PCB which is screwed to a big heatsink. I unscrewed the bolts and saw that there is S109AFTG. The IC is sandwiched between the PCB and the heatsink. A small aluminum block is also used for heat transfer between the IC and the heatsink.

It has a different step size which can be selected by the DIP switches.
The motor driver has a maximum of 1/32 step size.

which means 1.8°/ 32 = 0.05625°

360°/ 0.05625° = 6400 steps

So a full rotation will be in 6400 steps.

You will need a power source such as a Switched Mode Power Supply which can supply at least 2 Amps.

If your application needs more torque you will need a power source that can provide a high current without dropping the voltage.

Or you can use the battery for a short duration.

Schematic Diagram

Code

/*
* main.c
*
* Created: 7/4/2023 5:51:21 PM
*  Author: abhay
*/
#define F_CPU 16000000
#include <xc.h>
#include <util/delay.h>
int PUL=PIND6; //define Pulse pin
int DIR=PINB1; //define Direction pin
int ENA=PIND2; //define Enable Pin
#define DirLow PORTB &= ~(1<<DIR)
#define DirHigh PORTB |= (1<<DIR)
#define PulLow PORTD &= ~(1<<PUL)
#define PulHigh PORTD |= (1<<PUL)
#define EnaLow PORTD &= ~(1<<ENA)
#define EnaHigh PORTD |= (1<<ENA)
#define delayus50 _delay_us(50)
int main(void)
{
	DDRB |= (1<<DIR);
	DDRD |= (1<<PUL)|(1<<ENA);
	while(1)
	{
		//TODO:: Please write your application code
		for (int i=0; i<6400; i++)    //Forward 6400 steps
		{
			DirLow;
			EnaHigh;
			PulHigh;
			delayus50;
			PulLow;
			delayus50;
		}
		_delay_ms(5000);
		for (int i=0; i<6400; i++)   //Backward 6400 steps
		{
			DirHigh;
			EnaHigh;
			PulHigh;
			delayus50;
			PulLow;
			delayus50;
		}
		_delay_ms(2000);
	}
}
Posted on Leave a comment

How to use bipolar stepper motor using l298n module and raspberry pi pico w

The stepper motor that i have is a bipolar stepper motor.

On it one side there is information about it.

TYPE: 17PM-k310-33VS
NO.   T4508-03
    Minebea-Matsushita
    Motor Corporation
     Made in Thailand

It is a NEMA 17
17 stands for 1.7inches

Raspberry Pi Pico WL298N Module
GNDGND
GP0IN1
GP1IN2
GP2IN3
GP3IN4

The two coils pair are found using the multimeter in resistance mode.

Since I am using a regular motor driver. I cannot do the micro stepping.
But even with micro stepping, it can do a lot of stuff.

So there are two coil pair.
step angle of 1.8o degrees.

So to make a 360o
we need 360o / 1.8o = 200 steps

So we can make a full rotation with 200 steps of 1.8 degrees each.
This is what is known as the full step.
In full step, we only excite 1 pole at a time. There are two poles per coil.

We can excite two poles at a time. Which will half the step angle to 0.9 degrees.
The following is the table I have made to see how many steps I will be made by employing a 0.9 deg angle. It is only up to 300 steps or 270 deg. You can calculate from then on.

Micropython Code

from machine import Pin
import utime
motor_pins = [Pin(0, Pin.OUT), Pin(1, Pin.OUT), Pin(2, Pin.OUT), Pin(3, Pin.OUT)]
step_sequence = [
    [1,0,0,0],#1
    [1,0,1,0],#13
    [0,0,1,0],#3
    [0,1,1,0],#23
    [0,1,0,0],#2
    [0,1,0,1],#24
    [0,0,0,1],#4
    [1,0,0,1]#41  
]
off_seq = [(0,0,0,0)]
length_step_sequence = len(step_sequence)
one_rotation_length = 400/length_step_sequence
step_delay = (1/1000)*10 #ms
def step_off():
    #print("step off")
    motor_pins[0].value(0)
    motor_pins[1].value(0)
    motor_pins[2].value(0)
    motor_pins[3].value(0)
    utime.sleep(step_delay)
'''
Function Name: move_step
Description:
It takes the step sequence and assigns the motor pins to the value
according to the step sequence.
It moves one step seqence at a time.
For a half step sequence
each step will be 0.9 degrees.
For a full step sequence
each step will be 1.8 degrees.
'''
def move_step(seq):
    ygh = seq
    #print(ygh)
    for step1,pins in zip(ygh,motor_pins):
        pins.value(step1)
'''
Function Name: move one step
Description:
It moves all the steps in the sequence.
For a half wave steps => 8 * 0.9 = 7.2 deg
For a full wave steps => 4 * 1.8 = 7.2 deg
'''
def move_one_step(forward,reverse):
    for i in range(0,length_step_sequence,1):
        if forward == 1:
            move_step((step_sequence[i]))
        elif reverse == 1:
            move_step(reversed(step_sequence[i]))
        utime.sleep(step_delay)
def rotation(steps,forward,reverse):
    
    if forward == 1:
        for i in range(steps):
            move_one_step(1,0)
            print("Forward steps: ",steps)
    elif reverse == 1:
        for i in range(steps):
            move_one_step(0,1)
            print("Reverse steps: ",steps)
    
        #step_off()

'''
Half step calculations
8 Steps of 0.9 deg each.
total degree of 8 steps => 8 * 0.9 = 7.2
(8 step sequence) * (50 repeated steps) * 0.9 deg = 360
So, a total of 400 steps are required to make 360 degree.
7.2 deg x (50 repeated steps) = 360 degrees
7.2 deg x 25 = 180 degree
'''
while True:
    rotation(25,1,0) # move 180 forward(CW) 
    utime.sleep(1)
    rotation(50,0,1) # move 366 reverse (CCW)
    utime.sleep(1)