21EC52 - ARM Microcontrollers LAB - Programs
21EC52 - ARM Microcontrollers LAB - Programs
AREA DATA1,DATA,READWRITE
DVALUE DCD 0X00000000 ; ARRAY OF 32 BIT NUMBERS IN DATA REGION
END ; Mark end of file
Stepper motor:
A stepper motor or step motor or stepping motor is a brushless DC electric motor that divides
a full rotation into a number of equal steps. The motor's position can then be commanded to
move and hold at one of these steps without any position sensor for feedback (an open-loop
controller), as long as the motor is carefully sized to the application in respect to torque and
speed.
Unlike a brushless DC motor which rotates continuously when a fixed DC voltage is applied
to it, a step motor rotates in discrete step angles. The Stepper Motors therefore are
manufactured with steps per revolution of 12, 24, 72, 144, 180, and 200, resulting in stepping
angles of 30, 15, 5, 2.5, 2, and 1.8 degrees per step. The stepper motor can be controlled with
or without feedback.
How a stepper motor works?
Stepper motors work on the principle of electromagnetism. There is a soft iron or magnetic
rotor shaft surrounded by the electromagnetic stators. The rotor and stator have poles which
may be teethed or not depending upon the type of stepper. When the stators are energized the
rotor moves to align itself along with the stator (in case of a permanent magnet type stepper)
or moves to have a minimum gap with the stator (in case of a variable reluctance stepper).
This way the stators are energized in a sequence to rotate the stepper motor. Get more
information about working of stepper motors through interesting images at the stepper motor
Insight.
Stepper motors consist of a permanent magnetic rotating shaft, called the rotor, and
electromagnets on the stationary portion that surrounds the motor, called the stator. Figure 1
illustrates one complete rotation of a stepper motor. At position 1, we can see that the rotor is
beginning at the upper electromagnet, which is currently active (has voltage applied to it). To
move the rotor clockwise (CW), the upper electromagnet is deactivated and the right
electromagnet is activated, causing the rotor to move 90 degrees CW, aligning itself with the
active magnet. This process is repeated in the same manner at the south and west
electromagnets until we once again reach the starting position.
Figure 1
In the above example, we used a motor with a resolution of 90 degrees for demonstration
purposes. In reality, this would not be a very practical motor for most applications. The
average stepper motor's resolution (the amount of degrees rotated per pulse) is much higher
than this. For example, a motor with a resolution of 1.8 degrees would move its rotor 1.8
degrees per step, thereby requiring 200 pulses (steps) to complete a full 360 degree rotation.
Here we are using 200 pole stepper motor hence it gives 360degree/200 pole=1.8 degree per
step.
So for example if we need 120 degree rotation then we have to apply approximately 67
pulses to complete 120 degree rotation.
120/1.8=66.66==67 steps approximately.
So if we need 90 degree rotation then 90/1.8=50 steps. Here one cycle means 4 steps. So
50/4=12.5 =~ 13. So we need 13 cycles to rotate 90 degree. If we want to run 180 degree then
180/1.8=100. So 100/4=25 cycles would make a stepper motor to rotate 180 degree.
#include <LPC17xx.H>
void clock_wise(void);
void anti_clock_wise(void);
int main(void)
anti_clock_wise();
} //End of while(1)
} //End of main
void clock_wise(void)
{
var1 = 0x00000001; //For Clockwise
for(i=0;i<=3;i++) //for A B C D Stepping
{
LPC_GPIO2->FIOCLR = 0X0000000F;
LPC_GPIO2->FIOSET = var1;
var1 = var1<<1; //For Clockwise
for(k=0;k<15000;k++); //for step speed variation
}
}
void anti_clock_wise(void)
{
var1 = 0x00000008; //For Anticlockwise
for(i=0;i<=3;i++) //for A B C D Stepping
{
LPC_GPIO2->FIOCLR = 0X0000000F;
LPC_GPIO2->FIOSET = var1;
var1 = var1>>1; //For Anticlockwise
for(k=0;k<15000;k++); //for step speed variation
}
Result: A Stepper motor was interfaced with an ARM CORTEX M3 evaluation board and was
rotated in clockwise and anti-clockwise direction.
Viva Questions:
DAC0800:
DAC0800 is used to convert the digital data into analog signals. Digital data from specified port
lines is given to DAC input. Amplitude of output waveform can be varied by varying POT3 (5K)
that is by varying the reference voltage of DAC0800. JP11 (1,2) closed output is uni-polar and
JP11(1,2) open output is bi-polar. Port lines used for DAC are P0.4 – P0.11. Connect FRC cable
from CN7 to CN8 to use this block.
DAC Interface
while(1)
{
for(i=0;i!=0xFF;i++) //output 0 to FE
{
temp=i;
temp = temp << 4;
LPC_GPIO0->FIOPIN = temp;
}
{
temp=i;
temp = temp << 4;
LPC_GPIO0->FIOPIN = temp;
}
}
void delay(void)
{
unsigned int i=0;
for(i=0;i<=9500;i++);
}
Result: A DAC was interfaced with an ARM CORTEX M3 evaluation board; Triangular and
Square waveforms were generated using DAC0800.
Viva Questions:
Block Diagram:
There are two multiplexed 7-segment display units (U8, U9) on the board. Each display has
8-inputs SEG_A (Pin-7), SEG_B (Pin-6), SEG_C (Pin-4), SEG_D (Pin-2), SEG_E (Pin-1),
SEG_F (Pin-9), SEG_G (Pin-10) and SEG_H (Pin-5) and the remaining pins pin-3 & pin-8
are Common Cathode CC. These segments are common cathode type hence active high
devices.
At power on enable of all the segments are pulled up. A two bits input through SW5 is used
for multiplexing operation. A high level on these lines enables the corresponding display.
Connection of these enable lines are shown below.
The Common Cathode (CC) – In the common cathode display, all the cathode connections
of the LED segments are joined together to logic “0” or ground. The individual segments are
illuminated by application of a “HIGH”, or logic “1” signal via a current limiting resistor to
forward bias the individual Anode terminals (a-g).
The Common Anode (CA) – In the common anode display, all the anode connections of the
LED segments are joined together to logic “1”. The individual segments are illuminated by
applying a ground, logic “0” or “LOW” signal via a suitable current limiting resistor to the
Cathode of the particular segment (a-g).
Table: hexadecimal equivalent values for each digit to be displayed
Program:
LPC_GPIO0->FIODIR = 0x00180ff0;
while(1)
{
LPC_GPIO0->FIOSET |= ALLDISP;
for(j=0;j<3;j++)
for(delay=0;delay<30000;delay++); // 1s delay
Switchcount++;
LPC_GPIO0->FIOCLR = 0x00180ff0;
}
}
}
Result: The Hex digits „0‟ to „F‟ were displayed on a 7-segment LED interface, with an
appropriate delay in between, on an ARM CORTEX M3 evaluation board
Viva Questions:
1. Explain the fundamentals of Seven Segment Display.
2. How do you configure seven segment LED‟s to display hex numbers.
3. Explain the keywords ALLDISP and DATAPORT.
4. How do you configure PINSEL and GPIO?
12.Interface a simple Switch and display its status through Relay, Buzzer
and LED.
Aim: To interface a simple Switch and display its status through Relay, Buzzer and LED on
an ARM CORTEX M3 evaluation board using evaluation version of Embedded 'C' & Keil
uVision-4 tool.
Block Diagram
Program:
#include <LPC17xx.H>
unsigned int count=0;
int main(void)
{
unsigned int i;
while(1)
{
if(!(LPC_GPIO2->FIOPIN & 0x00000800))//FIOPIN-P2.12
{
for(i=0;i<10;i++)
{
LPC_GPIO0->FIOSET = 0x03000000; //relay on
for(i=0;i<10000;i++);
}
}
else
{
LPC_GPIO0->FIOCLR = 0x03000000; //relay off
for(i=0;i<100000;i++);
}
}
} //end int main(void)
Result: A simple Switch was interfaced with an ARM CORTEX M3 evaluation board and its
status was displayed through Relay, Buzzer and LED.
VIVA Questions: