Search This Blog

Showing posts with label Peripheral Devices and interfacing with MPU. Show all posts
Showing posts with label Peripheral Devices and interfacing with MPU. Show all posts

Tuesday, October 22, 2013

What you need to know to interface stepper motor with a microcontroller?

General Description


Every revolution of the stepper motor is divided into a discrete number of steps, in many cases 200 steps, and the motor must be sent a separate pulse for each step. The stepper motor can only take one step at a time and each step is the same size. Since each pulse causes the motor to rotate a precise angle, typically 1.8°, the motor's position can be controlled without any feedback mechanism. As the digital pulses increase in frequency, the step movement changes into continuous rotation, with the speed of rotation directly proportional to the frequency of the pulses. Step motors are used every day in both industrial and commercial applications because of their low cost, high reliability, high torque at low speeds and a simple, rugged construction that operates in almost any environment. 


Motor instead of doing a single complete rotation on a single pulse does only a predefined rotation or rotates only one on a single applied pulse. So if a step angle is 1.8°, this means a motor can do 360/1.8 = 200 steps in a single rotation. Means one needs to provide 200 pulses to make the stepper motor cover 1 revolution. 

So for attaining a speed of 10 rpm one needs a square pulse train of frequency 10x200 cycles or 2000 cycles per minute or 33.33Hz. Here the speed of motor is directly proportional to frequency of applied pulse.


Step Modes
3 step modes. 

1) Full Step
Full step mode is achieved by energizing both windings while reversing the current alternately. Essentially one digital pulse from the driver is equivalent to one step.  
A normal 4 step sequence is like below.


Step #
Winding A
Winding B
Winding C
Winding D
1
1
0
0
1
2
1
1
0
0
3
0
1
1
0
4
0
0
1
1


Going from step 1 to 4 we rotate motor clockwise

Going from step 4 to 1 we rotate motor counter clockwise

 

2) Half Step
In this mode, one winding is energized and then two windings are energized alternately, causing the rotor to rotate at half the distance. Although it provides less torque, half-step mode produces a smoother motion than full-step mode.
Half Step Sequence


Step #
Winding A
Winding B
Winding C
Winding D
1
1
0
0
1
2
1
0
0
0
3
1
1
0
0
4
0
1
0
0
5
0
1
1
0
6
0
0
1
0
7
0
0
1
1
8
0
0
0
1
 
3) Micro Step
Out of Bounds. Will create a separate post for the same.



Choice of Stepper Motor
The choice depends on ones requirement of torque and speed in ones application. No one stepper motor is suitable for every application. But for prototyping purposes one can use any available stepper motor with required step angle that can be bought from nearby electronics store. There is also a confusion that stepper motor requires a completely new motor driver. This is usually not the case whatever variants you see are higher grade or lower grade variants of a classical motor controller like L293D. What changes is the number of channels, channel capacity and the switching frequency. Usually what i prefer is the mosfet based multi channel motor driver that is easily available everywhere and can be scaled up and down based on the needs and current capacity. 

Other thing that needs to be taken care in stepper motor is number of pole. The higher precision and torque you need the number of poles in the stepper motor will vary. So for same application you may come across 2pole, 4pole and even 8 pole stepper motor. With higher number of poles the only difference will be that you will require more channels in your motor driver. These are all general observation for free available stepper motor for generic applications. For more specific application one needs to dive deep into once requirement and find out a proper motor afterwards.



Advantages
  1. Energized winding at standstill provides full torque with no rotation.
  2. Provides precise positioning and repetability of the same position is very high and easy to attain.
  3. Very Responsive and reliable
  4. Responsd directly to digital pulses and provide open loop control, reducing cost of control and increases simplicity.
  5. A wide range of rotational speeds can be realized as the speed is proportional to the frequency of the input pulses.

Friday, April 13, 2012

Intel 8087 Internal Architecture

Intel 8087 Internal Architecture
The 8087 is divided into 2 sections CU and NEU. That’s is control unit and numeric execution unit.
The numeric execution unit executes all numeric processor instructions while control unit receives, decodes instructions, read and writes memory operands and executes 8087 control instructions.

These 2 units works asynchronously with each other. The control unit is majorly responsible for establishing communication between CPU and memory and also for coordinating internal coprocessor execution.

The NEU has 8 registers 80 bit wide stack that holds operands for arithmetic instructions and their result. The FSTSW AX; is the instructions used for communication between coprocessor and micro processor.

The control unit is used to synchronize operation between coprocessor and microprocessor.  The unit has a control word a status word and a data buffer. If the instruction is an ESCape (coprocessor) instruction the coprocessor executes it otherwise the microprocessor executes it. The status register reflects the overall operation of the coprocessor.

The 8087 is a numeric data processor. It is basically made to work along with the 8086 and 8088 processors. It is incapable of fetching the instructions on its own so it is just simply connected to respective buses of the processor. Its instructions are recognized by word F as each and every instructions starts with F. for example FADD, FSUB etc.

The BUSY pin of the coprocessor is connected to the main processor's TEST pin. This TEST pin is active low in nature. This is because the speed of operation of the coprocessor and the main processor is different.


Friday, December 23, 2011

Program for setting date in RTC DS12887

; TURNING ON RTC
MOV R0, #10    ; REGISTER A ADDRESS IN R0
MOV A, #20H    ; 010 TO TURN ON RTC
MOVX @RO,A    ; SEND IT TO REGISTER A OF RTC


; SETTING TIME MODE
; AS DECIDED WE SET BCD, 24 HRS, DAYLIGHT SAVING
; MEANING SENDING 83H TO REGISTER B OF RTC
MOV R0, #11    ; REGISTER B ADDRESS IN R0
MOV A, #83H    ; FOR REASONS SITED ABOVE
MOVX @R0, A    ; SEND IT TO REGISTER B OF RTC

; TURNING ON AND SETTING TIME MODE REMAINS SAME
; DURING ALL SETTING THINGS

; SETTING THE DATE
; LETS GET SOME THINGS CLEAR
; 07 - DAY OF MONTH
; 08 - MONTH
; 09 - YEAR
; FOR FULL TABLE SEE THE POST..

; SETTING DAY OF MONTH
MOV R0, #07    ; POINT TO THE DAY OF MONTH
MOV A, #20H    ; DAY = 20
MOVX @R0, A    ; SET DAY OF MONTH

; SETTING MONTH
MOV R0, #08    ; POINT TO MONTH
MOV A, #12H    ; MONTH = 12 = DECEMBER
MOVX @R0, A    ; SET THE MONTH

; SETTINH YEAR
MOV R0, #09    ; POINT TO YEAR
MOV A, #11H    ; FOR 2011
MOVX @R0, A    ; SET THE YEAR

; REGISTER B
MOV R0, #11    ; POINT TO REGISTER B
MOV A, #03    ; D7 = 0 TO ALLOW UPDATE
MOVX @R0, A    ; SEND IT TO REGISTER B


END

Program for Setting time in RTC DS12887

; TURNING ON RTC
MOV R0, #10    ; REGISTER A ADDRESS IN R0
MOV A, #20H    ; 010 TO TURN ON RTC
MOVX @RO,A    ; SEND IT TO REGISTER A OF RTC


; SETTING TIME MODE
; AS DECIDED WE SET BCD, 24 HRS, DAYLIGHT SAVING
; MEANING SENDING 83H TO REGISTER B OF RTC
MOV R0, #11    ; REGISTER B ADDRESS IN R0
MOV A, #83H    ; FOR REASONS SITED ABOVE
MOVX @R0, A    ; SEND IT TO REGISTER B OF RTC


; SETTING THE TIME
; LET GET ONE THING CLEAR
; 0 - SECONDS
; 2 - MINUTES
; 4 - HOURS
; FOR INFO RELATED ABOVE SEE THE POST...


; SETTING SECONDS
MOV R0, #0    ; POINT TO SECONDS ADDRESS
MOV A, #SSH    ; SECONDS = SS MEANS PUT ANY VALUE
; CAREFULL SECONDS 0 - 60 AND IN BCD
; SO SS = 00H,02H......09H,10H,11H,.......29H,30H,...,59H
; H IS MUST FOR BCD
MOVX @R0, A    ; SET SECONDS


; SETTING MINUTES
MOV R0, #02    ; POINT TO MINUTES ADDRESS
MOV A, #MM    ; MINUTES = MM MEANS PUT ANY VALUE
; CAREFULL MINUTES 0 - 60 AND IN BCD
; SO MM = 00H,02H......09H,10H,11H,.......29H,30H,...,59H
; H IS MUST FOR BCD
MOVX @R0, A    ; SET MINUTES


; SETTING HOURS
MOV R0, #04    ; POINT TO HOURS ADDRESS
MOV A, #HH    ; HOURS = HH
; CAREFULL HOURS HERE IS IN 24 HOURS FORMAT
; SO HH CAN BE 1,2,...., 14,15......,23 NOT OUTSIDE THIS
; H IS MUST FOR BCD
MOVX @R0, A    ; SET HOURS


; REGISTER B
MOV R0, #11    ; POINT TO REGISTER B ADDRESS
MOV A, #03    ; D7 = 0 TO ALLOW UPDATE
MOVX @R0, A    ; SEND IT TO REGISTER B OF RTC

END

RTC address map

The address map of DS12887
  • This has total of 128 bytes of RAM space with addresses 00-7Fh.
  • The first 10 i.e. 00-09 are kept aside for RTC values of time, calendar and alarm data.
  • The next 4 are control and status registers.
  • The next 114 bytes from address 0E-7F are available for data storage.
  • Register C and D are read only.
  • The D7 of register A is read only.
  • The high order bits of seconds byte are read only.

Address map
0 – 00h
Seconds
1 – 01h
Seconds alarm
2 – 02h
Minutes
3 – 03h
Minutes alarm
4 – 04h
Hours
5 – 05h
Hours alarm
6 – 06h
Day of week
7 – 07h
Day of month
8 – 08h
Month
9 – 09h
Year
10 – 0Ah
Register A
11 – 0Bh
Register B
12 – 0Ch
Register C
13 – 0Dh
Register D


Register A
UIP
DV2
DV1
DV0
RS3
RS2
RS1
RS0

UIP update in progress. This is a read only bit.

DV2 – 0
DV1 – 1
DV0 – 0
Will turn the oscillator on.

RS3,RS2,RS1,RS0 provides 14 different frequencies at the SQW pin.
Value of register a will remain as..
0
0
1
0
0
0
0
0
A = 20h


Register B
SET
PIE
AIE
UIE
SQWE
DM
24/12
DSE

SET
SET =0; clock is counting once per second and times and dates are updated.
SET =1; update is inhibited(during initialization we must set SET=1)
PIE
Periodic interrupt enable
AIE
Alarm interrupt enable. The AIE=1 will allow the IRQ to be asserted, when all 3 bytes of time equals alarm bytes. In short will raise an interrupt when time equals alarm time.
UIE
Don’t know so see the datasheet.
SQWE
Square wave enable.
DM
Data mode.
DM=0; for BCD data format.
DM=1; for binary(hex) data format.
24/12
1 for 24 hour mode
0 for 12 hour mode
DSE
Daylight saving enable.
1 enables daylight saving(first Sunday in april and last Sunday in October)
0 disables daylight saving
 So we will keep the setting BCD data format. 24 hrs time, and daylight saving on.
Giving us the value of register.
1
0
0
0
0
0
1
1
B = 83h.


RTC DS12887 address location for time, calendar and alarm.
Address Location
Function
Decimal range
Binary(hex)
BCD
0
Seconds
0-59
00-3B
00-59
1
Seconds alarm
0-59
00-3B
00-59
2
Minutes
0-59
00-3B
00-59
3
Minutes alarm
0-59
00-3B
00-59
4
Hours, 12 hour mode
1-12
01-0C AM
01-12 AM

Hours, 12 hour mode
1-12
81-8C PM
81-92 PM

Hours, 24 hour mode
0-23
0-17
0-23
5
Hours alarm, 12 hour
1-12
01-0C AM
01-12 AM

Hours alarm, 12 hour
1-12
81-8C PM
81-92 PM

Hours alarm, 24 hour
0-23
0-17
0-23
6
Days of the week SUN=1
1-7
01-07
01-07
7
Day of the month
1-31
01-1F
01-31
8
Month
1-12
01-0C
01-12
9
Year
0-99
00-63
00-99
 one needs to remember above tables to write a program for RTC interfacing with 8051.