Module 2 Embedded
Module 2 Embedded
SYSTEMS
■ STEPPER MOTOR
■ INTERFACING DIAGRAM
■ 4 STEP SEQUENCE
■ CODE
■ ANOTHER CODE
■ PROTEUS CONNECTION DIAGRAM
■ Stepper motor divides the full rotation angle of 360° into number of equal steps.
■ Total no. of steps = Total rotational angle / step angle.
■ Take step angle =1.8 so, 360/1.8 = 200 steps are required to complete one
rotation.
■ Total no. of repeated steps = Total no. of steps / Step sequence
■ 200 / 4 = 50 = 32H
■ There are 4 stepper motor coils.
0 0 1 1 03
0 1 1 0 06 Sequence for
1 1 0 0 0C Anti-clockwise rotation
1 0 0 1 09
ORG 0000H
HERE: MOV A, #99H
MOV R0, #200
BACK : MOV P1, A
ACALL DELAY
RR A
DJNZ R0, BACK
SJMP HERE
clr p2.2
setb p2.3
acall delay
clr p2.3
sjmp back
delay: mov r7,#64h
back1: mov tmod,#01h
mov th0,#0dbh
mov tl0,#0ffh
setb tr1
l1: jnb tf1,l1
clr tr1
clr tf1
djnz r7,back1
ret
end
back:mov a,#0ffh
mov p0,a
acall delay
mov a,#00h
mov p0,a
acall delay
sjmp back
delay:mov r7,#64h
4 RS Register selection
6 E Enable
7 DB0 Data
8 DB1 Data
9 DB2 Data
10 DB3 Data
11 DB4 Data
12 DB5 Data
13 DB6 Data
14 DB7 Data
01 Clear screen
02 Return home
04 Decrement cursor
06 Increment cursor
CLR P3.3
CLR P3.4
RET
END
13-10-2020 EC 1503 Embedded Systems Gayathri R 19
MODULE II (lecture 14)
EMBEDDED SYSTEMS
Contents
• Frequency Counter Using 8051
• Frequency Counter Program
• Temperature Measurement Using 8051
• INTERFACE LM35 TEMPERATURE SENSOR WITH 8051 (AT89C51)
• Interfacing diagram
• PROGRAM
ORG 00H
Start: MOV TMOD,#15H; timer 1 as timer and Timer0 as counter
SETB P3.4; set P3.4 as input pin
MOV TL0,#00H; clear TL0
MOV THO,#00H; CLEAR TH0
SETB TR0; Start counter
MOV R0,#28; R0=28,for time=1 sec
Again: MOV TL1,#00H;
MOV TH1,#00H;
SETB TR1; Start timer 1
The device must be able to sense the logic level on these pins No fixed length of transfer
SCL SCL
Start Stop
Dr Binu paul , EMB 9 of 40 Condition Dr Binu paul , EMB Condition 10 of 40
ACK – Generated by the slave whose address has been output. Acknowledgement
from receiver
A A A A A A
Writing
Byte Write
Page Write
Write time 10mS maximum
Write acknowledge Polling After the STOP bit is receive the device internally programs
Reading the EEPROM with the received data byte.
Immediate/Current address reading The programming can take up to 10ms (max.). The device
Selective/Random Read will be busy during this period and will not respond to its
Sequential Read slave address.
SPI protocol
SPI Module
The data transfer using SPI can be considered as a large shift register
4 interface pins:
3 registers:
-MOSI master out slave in shared between master and slaves.
-SPCR control register
-MIOS master in slave out Data is clocked IN at the same time as it is clocked OUT of the devices-
-SPSR status register
-SCK serial clock
-SPDR data register the CLK being shared
-SS_n slave select –Active low
Dr Binu paul , EMB 29 of 40 Dr Binu paul , EMB 30 of 40
Tx and Rx has Buffers also
Whenever the MASTER sends a byte to SLAVE , SLAVE sends one back - swapping
bits either way on every clk.. FULL DUPLEX
If shift registers are 8 bit long, after 8 clocks the data in Master and Slave gets
exchanged
SO On every SCK, Master sends a bit on MOSI line (SDO) and slaves reads it & SLAVE
Data is shifted OUT of the master's MOSI (SDO) pin and IN through its MISO sends a bit on MISO line and Master reads it
(SDI) pin
Data transfer is initiated by simply writing data to the SPI data register.
reserved bits
interrupt enable: if set, interrupt interrupt flag: set when serial
occurs when SPI interrupt flag transfer is complete
(in SPSR) clock rate
and global interrupt enable are set write collision: set if SPDR is
spi enable: if set, SPI interface written during a receive transfer
is enabled SPI2X SPR1 SPR0 SCLK 2x clock rate: if set, doubles
0 0 0 fosc/4 clock rate in master mode
data order: if set, LSB is 0 0 1 fosc/16
transmitted first 0 1 0 fosc/64 SPI Data Register (SPDR)
master/slave select: if set, 0 1 1 fosc/128
SPI in master mode 1 0 0 fosc/2
clock polarity: 1 0 1 fosc/8
'0' SCK low in idle 1 1 0 fosc/32
'1' SCK high in idle 1 1 1 fosc/64 SPDR is a read/write register used for data transfer. Writing to SPDR sends data
clock phase: out MOSI. Reading from SPDR gets the data that was clocked into MISO.
'0' leading edge sample, trailing edge setup
'1' leading edge setup, trailing edge sample 33 of 40 34 of 40
Dr Binu paul , EMB Dr Binu paul , EMB
No of pins: 3+n*CS 2
Upto 10 MHz supported – high date rate Low data rate support
Good for single master, single slave – short Efficient for multimaster multislave models –
distance short distance
Less over head for point to point transfer More overhead
Best suited for data flow applications Suited best for communication on board
Low cost
Message oriented communication CAN bus © 2005 Microchip Technology Incorporated. All Rights Reserved.
Cheap CAN controller – CPU could get overrun with CAN Bus line Interface
messages even if it didn’t need them. Basic Configuration
Newer version use hardware filters to reorganise the Application layer: interacts with operating system or with CAN device
Data Link layer : involved in actual data transfer as per the protocol.. like
received data Send/receive/validate etc
Physical layer : denotes the required hardware
Dr Binu paul , EMB 47 of 40 Dr Binu paul , EMB 48 of 40
27-09-2018
CAN – Data frame message Format CAN Data frame Message Format
Each message has an ID(11 bit or 29 bit) , Data and
overhead.
The physical layer uses differential transmission on a twisted
Data –8 bytes max
pair wire. The bus uses Non-Return To Zero (NRZ) with bit-
Overhead – start, end, CRC, ACK
stuffing (see bit encoding slide)
Message Format – with standard identifier CAN - Data frame Message Format - continued
Field name Length(bits) Purpose
Transmitter sends recessive (1) and any receiver can assert a RTR: “1” when information is
ACK slot 1 dominant (0)
ACK delimiter 1 Must be recessive (1)
needed from another node. But
End-of-frame (EOF) 7 Must be recessive (1) only that node whose identifier
matches takes the data
Only if all nodes transmit recessive If any one node transmits a dominant
bits (ones), the Bus is in the recessive bit (zero), the bus is in the dominant
state. state.
The CAN Standard - message types The CAN Standard - message types
The CAN standard defines four message types
(Data,Remote,Error,Overload frames) Overload Frame
Data Frame – the predominantly used message type (discussed earlier) It is very similar to the Error Frame with regard to the format and it is
Remote Frame transmitted by a node that becomes too busy.
The Remote Frame is just like the Data Frame, with two important differences: At present obsolete
the RTR bit in the Arbitration Field is recessive value “1” Today's CAN controllers are clever enough not to use it
there is no Data Field.
The CAN standard also defines an elaborate scheme for error
Error Frame
handling and confinement.
Error Frame is a special message that violates the framing rules of a CAN
message CAN -number of different connector types in use.
The Error Frame consists of an Error Flag, which is 6 bits of the same value
(thus violating the bit-stuffing rule) and an Error Delimiter, which is 8 recessive
bits( “1”)
END of presentation
1. The Data Frame
Summary: "Hello everyone, here's some data
labeled X, hope you like it!"
The Data Frame is the most common message type.
It has
the Arbitration Field, which determines the priority of the message when
two or more nodes are contending for the bus. The Arbitration Field
contains:
For CAN 2.0A, an 11-bit Identifier and one bit, the RTR bit, which is dominant
for data frames.
For CAN 2.0B, a 29-bit Identifier (which also contains two recessive bits: SRR
and IDE) and the RTR bit.
the Data Field, which contains zero to eight bytes of data.
the CRC Field, which contains a 15-bit checksum calculated on most
parts of the message. This checksum is used for error detection.
an Acknowledgement Slot; any CAN controller that has been able to
correctly receive the message sends an Acknowledgement bit at the end
of each message. The transmitter checks for the presence of the
Acknowledge bit and retransmits the message if no acknowledge was
detected.
Dr Binu paul , EMB 65 of 40 Dr Binu paul , EMB 66 of 40
• We use Analogue to digital convertor (ADC) to convert the analogue signal into digital form.
Analogue signal can be the output of some sensor. And then the data in digital format can then be
used for further processing by the digital processors.
• 8 bit resolution
• Differential analogue voltage inputs
• 0-5V input voltage range
• No zero adjustment
• Built-in clock generator
• Voltage at Vref/2 (pin9) can be externally adjusted to convert smaller input voltage
spans to full 8 bit resolution.
Steps for converting the analog input and reading the output from ADC0804.
• Make CS=0 and send a low to high pulse to WR pin to start the conversion.
• Now keep checking the INTR pin. INTR will be 1 if conversion is not finished
and INTR will be 0 if conversion is finished.
• If conversion is not finished (INTR=1) , poll until it is finished.
• If conversion is finished (INTR=0), go to the next step.
• Make CS=0 and send a high to low pulse to RD pin to read the data from the
ADC.
Interfacing
Algorithm and Flowchart
Interfacing Diagram