Question:program on Interfacing of stepper motor with 4500 micro microstepping driver using pic16f877A in mplab ide with hitech c compiler
Interfacing Stepper Motor with PIC Microcontroller:-
Stepper Motor is a specially designed motor which rotates in steps. Speed of stepper motor depends on the rate of electrical signal applied to it. Different patterns can control stepper motor’s direction and rotation type. Mainly two types of stepper motors are available, Unipolar and Bipolar. Unipolar is easier to operate, control and also easier to get. Here in this tutorial we are interfacing Stepper Motor with PIC Microcontroller PIC16F877A.
28BYJ-48 stepper motor(Which we are using)
. It is 5V DC unipolar stepper motor. We are also using a Module available with this motor which consist ULN2003 Stepper Motor Driver IC. ULN2003 is a Darlington pair array, which is useful to drive this motor, since PIC microcontroller couldn’t provide enough current to drive. ULN2003A is capable to drive 500mA of load with 600mA of peak current.
Specification of 28BYJ-48 Stepper Motor from the datasheet.:-
Inside the motor there are two center tapped coils available. Red wire is the common for both which will be connected at VCC or 5V.
Other 4 wires pink, red, yellow and blue will control the rotation depending on the electrical signal. Also, depending on the movement, this motor can be controlled using 3 steps. Full drive mode, Half Drive mode and Wave drive mode.
Three Driving Modes of Stepper Motor:
Full Drive: If two stator electromagnets are energized at a time, the motor will run at full torque referred as full-drive sequence mode.
Stepper motor can also be controlled without any Microcontroller,
see this Stepper Motor Driver Circuit.Wave Drive:
In this mode, one stator electromagnet is turned on. Its follows 4
steps same as Full-drive mode. It consumes low power with low
torque.
Step |
Blue |
Pink |
Yellow |
Orange |
1 |
1 |
0 |
0 |
0 |
2 |
0 |
1 |
0 |
0 |
3 |
0 |
0 |
1 |
0 |
4 |
0 |
0 |
0 |
1 |
We have previously interfaced Stepper Motor with other Microcontrollers:
These are the macros for configuration bits of the microcontroller unit and the library header files.
#define _XTAL_FREQ 200000000 //Crystal Frequency, used in delay #define speed 1 // Speed Range 10 to 1 10 = lowest , 1 = highest #define steps 250 // how much step it will take #define clockwise 0 // clockwise direction macro #define anti_clockwise 1 // anti clockwise direction macro
In the first line we defined crystal frequency which is needed for the delay routine. Other macros are used to define user related options.
If you see the code, there are three functions defined for driving the motor in three modes with clock-wise and anti-clockwise direction. Here are the three functions:
1.void full_drive (char direction)
2.void half_drive (char direction)
3.void wave_drive (char direction)
Now in void main function, we are driving the motor clockwise using full-drive mode depending on the steps and after few seconds delay we again rotate the motor anti-clockwise using wave drive mode.
void main(void) { system_init(); while(1){ /* Drive the motor in full drive mode clockwise */ for(int i=0;i<steps;i++) { full_drive(clockwise); } ms_delay(1000); /* Drive the motor in wave drive mode anti-clockwise */ for(int i=0;i<steps;i++) { wave_drive(anti_clockwise); //full_drive(anti_clockwise); } ms_delay(1000); } }
//You can set the delay according to yourself
//Constants value change depend upon you
Full Code:-
// PIC16F877A Configuration Bit Settings
// 'C' source line config statements
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
#include <stdio.h>
/*
Hardware related definition
*/
#define _XTAL_FREQ 200000000 //Crystal Frequency, used in delay
#define speed 1 // Speed Range 10 to 1 10 = lowest , 1 = highest
#define steps 250 // how much step it will take
#define clockwise 0 // clockwise direction macro
#define anti_clockwise 1 // anti clockwise direction macro
/*
*Application related function and definition
*/
void system_init (void); // This function will initialise the ports.
void full_drive (char direction); // This function will drive the motor in full drive mode
void half_drive (char direction); // This function will drive the motor in full drive mode
void wave_drive (char direction); // This function will drive the motor in full drive mode
void ms_delay(unsigned int val);
/*
* main function starts here
*/
void main(void)
{
system_init();
while(1){
/* Drive the motor in full drive mode clockwise */
for(int i=0;i<steps;i++)
{
full_drive(clockwise);
}
ms_delay(1000);
/* Drive the motor in wave drive mode anti-clockwise */
for(int i=0;i<steps;i++)
{
wave_drive(anti_clockwise);
//full_drive(anti_clockwise);
}
ms_delay(1000);
}
}
/*System Initialising function to set the pin direction Input or Output*/
void system_init (void){
TRISB = 0x00; // PORT B as output port
PORTB = 0x0F;
}
/*This will drive the motor in full drive mode depending on the direction*/
void full_drive (char direction){
if (direction == anti_clockwise){
PORTB = 0b00000011;
ms_delay(speed);
PORTB = 0b00000110;
ms_delay(speed);
PORTB = 0b00001100;
ms_delay(speed);
PORTB = 0b00001001;
ms_delay(speed);
PORTB = 0b00000011;
ms_delay(speed);
}
if (direction == clockwise){
PORTB = 0b00001001;
ms_delay(speed);
PORTB = 0b00001100;
ms_delay(speed);
PORTB = 0b00000110;
ms_delay(speed);
PORTB = 0b00000011;
ms_delay(speed);
PORTB = 0b00001001;
ms_delay(speed);
}
}
/* This method will drive the motor in half-drive mode using direction input */
void half_drive (char direction){
if (direction == anti_clockwise){
PORTB = 0b00000001;
ms_delay(speed);
PORTB = 0b00000011;
ms_delay(speed);
PORTB = 0b00000010;
ms_delay(speed);
PORTB = 0b00000110;
ms_delay(speed);
PORTB = 0b00000100;
ms_delay(speed);
PORTB = 0b00001100;
ms_delay(speed);
PORTB = 0b00001000;
ms_delay(speed);
PORTB = 0b00001001;
ms_delay(speed);
}
if (direction == clockwise){
PORTB = 0b00001001;
ms_delay(speed);
PORTB = 0b00001000;
ms_delay(speed);
PORTB = 0b00001100;
ms_delay(speed);
PORTB = 0b00000100;
ms_delay(speed);
PORTB = 0b00000110;
ms_delay(speed);
PORTB = 0b00000010;
ms_delay(speed);
PORTB = 0b00000011;
ms_delay(speed);
PORTB = 0b00000001;
ms_delay(speed);
}
}
/* This function will drive the the motor in wave drive mode with direction input*/
void wave_drive (char direction){
if (direction == anti_clockwise){
PORTB = 0b00000001;
ms_delay(speed);
PORTB = 0b00000010;
ms_delay(speed);
PORTB = 0b00000100;
ms_delay(speed);
PORTB = 0b00001000;
ms_delay(speed);
}
if (direction == clockwise){
PORTB = 0b00001000;
ms_delay(speed);
PORTB = 0b00000100;
ms_delay(speed);
PORTB = 0b00000010;
ms_delay(speed);
PORTB = 0b00000001;
ms_delay(speed);
}
}
/*This method will create required delay*/
void ms_delay(unsigned int val)
{
unsigned int i,j;
for(i=0;i<val;i++)
for(j=0;j<1650;j++);
}
Question:program on Interfacing of stepper motor with 4500 micro microstepping driver using pic16f877A in mplab ide...
2. Is it advisable to connect a stepper motor driver to PLC relay output? Why? Design a LAD program to control a Lamp (Q 124.0) on/off operation by using only one Push Button (I 126.0).
Q1/ATV antenna is to be controlled by a 4-phase stepper motor with a step 5 degrees and reduction gearbox of 1:50. The stepper motor is controlled using Arduino UNO and must scan angular displacement starting from (10) degrees and ending at (170) degrees and repeat, in order to search active working TV-channels. Sketch the controlling cct. and write the computer program that drives the interfacing cct Q2/Say WHY?: 1-Measuring temperature using thermistor needs power supply. 2-7410 and 7404 1Cs can...
Mitch is designing a motor driver for a wheeled mobile robot. The motor driver is designed as an inverting amplifier (using the circuit shown in Figure 1) to drive the motor in the opposite direction of the input voltage. Mitch would like to select the components of the amplifier based on specific design requirements. Mitch has installed a switch to disconnect the motor driver input signal to the system and a motor protection switch to disconnect the motor from the...
Using pic 16f877a and Micro C languge Design a system (hardware and software) which consists of a servo motor and two sun detector and pic 16f877a to track the sun. servo motor
answere Please mark only one of the four choices Q1. Controlling the speed of a DC motor by using a micro-controller, is what type of control? b. Digital C. Analog d. All of the above Q2. When current flow is interrupted in a DC motor, which motor property causes a reverse voltage spike? a. Resistance b. Capacitance C. Inductance d. None of the above Q3. Which Arduino internal circuit is used to control motor speed? a. Digital to Analog Converter...
Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve breaking the problem down into multiple classes that can be tied together into a single solution. In this project, you are given the task of writing some classes that would work together for providing a solution to a problem involving some basic computations. Learning Objectives The focus of this assignment is on the following learning objectives: • Be able to identify the contents of...