Wednesday, July 27, 2011

LIN in Nutshell /LIN Tutorial

LIN [Local Interconnect Network] is used as an in-vehicle [Automotive] communication and networking serial bus between intelligent sensors and actuators operating at 12 volts. Other auto body electronics include air conditioning systems, doors, seats, column, climate control, switch panel, intelligent wipers, and sunroof actuators. The LIN specification covers the transmission protocol [Physical Layer and the Data Link Layer of LIN], and the transmission medium. The maximum communication speed on a LIN bus is 19200 baud [a 1K termination pull-up resistor is required]. The LIN Bus is a class A protocol operating at a maximum bus speed of 19200 baud over a maximum cable length of 40 meters. LIN nodes can send/receive a full 8 byte command every 10ms (or shorter commands every 5ms). The LIN specification will also handle 2400, and 9600 baud rates, and may be used as a sub-bus [sub-network] for a CANbus interface. The LIN bus uses a Master/Slave approach, having one Master and one or more Slaves. The LIN bus does not need to resolve bus collisions because only one message is allowed on the bus at a time. The LIN message protocol is defined by:


Master, Sync break [13 bits]: used to identify the start of the frame
Master, Sync field [alternate 1-0 sequences]: used by the slave node for clock synchronization
Master, Identifier [6-bit long message ID and a 2-bit long parity field]
Master, Message ID [2, 4 or 8 data bytes]: optional message length information
Slave transmission ~[1-8 data bytes]: data bytes
Slave transmission ~[8 bit]: checksum
Additional Automotive and Vehicle Buses. The different class of vehicle buses are also described.

LIN Bus Protocol

The automotive Local Interconnect Network is a UART based networking architecture. LIN uses one Bidirectional line that represents the single-wire bus transmitter and receiver.
Source : http://www.interfacebus.com/Design_Connector_LIN_Bus.html

For more Info :

and also 

http://www.esnips.com/doc/0bbf31ee-f5a3-4e4c-a866-9fe542103836/LINOVERVIEWPRESENT
 and from wikipedia:
http://en.wikipedia.org/wiki/Local_Interconnect_Network

The Clemson Vehicular Electronics Laboratory (CVEL)

This Link Consists of the details about automotive sensors, communication protocols, communication Bus standards ,EMC and other valuable information.

& for other domain like avionics
see 

http://www.cvel.clemson.edu/

A Brief Overview of Automotive Buses

CAN (Controller Area Network)

Brief Description: Can bus is a serial bus originally developed by Robert Bosch GmbH in 1986 for in-vehicle networks in cars. CAN buses employing twisted wire pairs were specifically designed to be robust in electromagnetically noisy environments. The applications of CAN bus in automobiles include window and seat operation (low speed), engine management (high speed), brake control (high speed) and many other systems. CAN buses can also be found in other embedded control applications such as factory automation, building automation, and aerospace systems.
Maximum Data Rates: 1Mbps at 40m, 125Kbps at 500m, 50kbps at 1000m
Circuit Type: Differential
Physical Layer: Twisted Wire Pair, 9 pin D-Sub
Transmission Format: Asynchronous
Drive Voltage: High: 2.75v ~ 4.5v; Low: 0.5v ~ 2.25v; Differential: 1.5v ~ 3.0v
Network Topology: Point to Point
Standards: ISO 11898/11519
More Information: http://www.interfacebus.com/Design_Connector_CAN.html



LIN (Local Interconnect Network)

Brief Description: LIN specifications are developed by the LIN consortium. Version 1.1 was released in 1999. The current version is 2.0. A primary advantage of this bus is that it can be implemented with a single wire (using the vehicle chassis as a current return path). A small and relatively slow in-vehicle communication and networking serial bus system, LIN bus is used to integrate intelligent sensors and actuators. LIN can also communicate over a vehicle's power distribution system with a DC-LIN transceiver.
Maximum Data Rates: 19.2Kbaud at 40m
Physical Layer: Single-Wire Implementation
Transmission Format: SCI (UART) Data Format
Operating Voltage: 12v over a Single Wire
Network Topology: Single Master / Multiple Slave (Up to 16 slaves)
Standards: Enhanced ISO 9141
More Information:
http://www.interfacebus.com/Design_Connector_LIN_Bus.html
http://www.lin-subbus.org/


FlexRay

Brief Description: FlexRay is a high-speed serial communication bus for in-vehicle networks. It is an extended protocol version of byteflight. The extended FlexRay has the performance features required for active safety, such as redundant transmission channels and a fault-tolerant synchronization mechanism. Applications for FlexRay include steer-by-wire and brake-by-wire systems.
Maximum Data Rates: 500 kbps ~ 10 Mbps
Communication Modes:Time-triggered, Event-triggered
Network Topology: Single-channel topologies, Dual-channel topologies
More Information: http://www.flexray.com



MOST (Media Oriented Systems Transport)

Brief Description: MOST was originally designed by Oasis SiliconSystems AG (now SMSC) in cooperation with BMW, Becker Radio, and DaimlerChrysler for multimedia applications in the automotive environment.  It was intended to be implemented on an optical fiber, so the bit rates of this bus system are much higher than previous automotive bus technologies. Since 1997, seventeen international automotive manufacturers and more than fifty key component suppliers including automotive electrical suppliers and audio-video manufacturers have contributed to this technology. MOST buses provide an optical solution for automotive peripherals like car radios, CD and DVD players, and GPS navigation systems.
Maximum Data Rates: 23 Mbaud
Layers: All Seven Layers of the ISO/OSI Reference Model for Data Communication
Network Topology: Point to Point via a Ring Topology but Star Configurations
Other Feature: Plug and Play; 60 Channels, 15 MPEG1 Channels for user configuration
Standards: ISO 7498-1 (OSI Model)
More Information:
http://www.mostcooperation.com/home/
http://www.telos.de/most/
http://www.answers.com/Media%20Oriented%20Systems%20Transport


Source: http://www.cvel.clemson.edu/auto/auto_buses01.html

Tuesday, July 26, 2011

ADC (Successive Approximation Techinque)

Block diagram


Algorithm

The successive approximation Analog to digital converter circuit typically consists of four chief subcircuits:
  1. A sample and hold circuit to acquire the input voltage (Vin).
  2. An analog voltage comparator that compares Vin to the output of the internal DAC and outputs the result of the comparison to the successive approximation register (SAR).
  3. A successive approximation register subcircuit designed to supply an approximate digital code of Vin to the internal DAC.
  4. An internal reference DAC that supplies the comparator with an analog voltage equivalent of the digital code output of the SAR for comparison with Vin.
The successive approximation register is initialized so that the most significant bit (MSB) is equal to a digital 1. This code is fed into the DAC, which then supplies the analog equivalent of this digital code (Vref/2) into the comparator circuit for comparison with the sampled input voltage. If this analog voltage exceeds Vin the comparator causes the SAR to reset this bit; otherwise, the bit is left a 1. Then the next bit is set to 1 and the same test is done, continuing this binary search until every bit in the SAR has been tested. The resulting code is the digital approximation of the sampled input voltage and is finally output by the DAC at the end of the conversion (EOC).

Souce: http://en.wikipedia.org/wiki/Successive_approximation_ADC

For a pratical ADC Chip..See the link
http://www.esnips.com/doc/ba12463b-13e8-4d01-abcc-4293761f9521/ADC_12b_ADCS7476
for its working see page no 17

CAN in Nutshell /CAN Tutorial

CAN - a brief tutorial


The CAN bus (Controller Area Networking) was defined in the late 1980 by Bosch, initially for use in automotive applications.  It has been found to be very useful in a wide variety distributed industrial systems as it has the following characteristics:
  • Uses  a single terminated twisted pair cable
  • Is multi master
  • Maximum Signal frequency used is 1 Mbit/sec
  • Length is typically 40M at 1Mbit/sec up to 10KM at 5Kbits/sec
  • Has high reliability with extensive error checking
  • Typical maximum data rate achievable is 40KBytes/sec
  • Maximum latency of high priority message <120 µsec at 1Mbit/sec
CAN is unusual in that the entities on the network, called nodes, are not given specific addresses.  Instead, it is the messages themselves that have an identifier which also determines the messages' priority.  For this reason there is no theoretical limit to the number of nodes although in practice it is ~64.
Two specifications are in use:
  • 2.0A sometimes known as Basic or Standard CAN with 11 bit message identifiers which was originally specified to  operated at a maximum frequency of 250Kbit/sec - ISO11519.
  • 2.0B known as Full CAN or extended frame CAN with 29 bit message identifier which can be used at up to 1Mbit/sec - ISO 11898.

Nuts and Bolts

From the systems and design viewpoint the detailed management of sending and receiving CAN messages will normally be done by dedicated hardware, on or off chip, (e.g. SJA1000) but an overview of these functions will be useful in order to design, setup and control a CAN system.

Signal Characteristics

CAN may be implemented over a number of physical media so long as the drivers are open-collector and each node can hear itself and others while transmitting (this is necessary for its message priority and error handling mechanisms).  The most common media is a twisted pair 5v differential signal which will allow operations in high noise environments and with the right drivers will work even if one of the wires is open circuit. A number of transceiver chips are available the most popular probably being the Philips 82C251 as well as the TJA1040.
When running Full CAN (ISO 11898-2) at its higher speeds it is necessary to terminate the bus at both ends with 120 Ohms.  The resistors are not only there to prevent reflections but also to unload the open collector transceiver drivers. We recommend that you terminate the bus correctly in all circumstances.

                                              

Message formats

The CAN protocol uses a modified version of the Carrier Sense Multiple Access/Collision Avoidance (CSMA/CA) technique used on Ethernet.  Should two messages determine that they are both trying to send at the same time then instead of both backing off and re-trying later as is done with Ethernet, in the CAN scheme, the transmitters detect which message has the highest priority and only the lower priority message gets delayed.  This means that a high priority message is sure of getting through.
             

Data Frames

These are the normal message frames used to carry data.  They contain the following fields -- this is a simplified description as the controller takes care of the detail which is only of interest to those designing controllers (who should consult the spec)
Start of frame   (SOF)
Message Identifier  (MID)     the Lower the value the Higher the priority of the message
                 its length is either 11 or 29 bits long depending on the standard being used
Remote Transmission Request (RTR) = 0  ----- see "Remote Frames" para below for non zero value
Control field  (CONTROL)  this specifies the number of bytes of data to follow (0-8)
Data Field (DATA) length 0 to 8 bytes
CRC field  containing a fifteen bit cyclic redundancy check code
Acknowledge field  (ACK)   an empty slot which will be filled by any and every node that receives the frame
                 it does NOT say that the node you intended the data for got it, just that at least one node on the whole network got it.
End of Frame   (EOF)
The way in which message collision is avoided is that each node as it transmits its MID looks on the bus to see what everyone else is seeing.  If it is in conflict with a higher priority message identifier (one with a lower number) then the higher priority messages bit will hold the signal down (a zero bit is said to be dominant) and the lower priority node will stop transmitting. 
If you are writing diagnostic code and wish to not "exist" on the network as a node, just to spy on what is happening, then you will need to ensure that the interface you use can be set to a mode where it does not automatically set the ACK bit.  The Peak interfaces and their Explorer diagnostic package can be set into such a mode.

Remote Frames

These are frames that are used to request that a particular message be put on the network - of course a node somewhere on the network has to be set up to recognise the request, get the data and put out a Message frame. This mechanism is used in polled networks.  The fields are ....
Start of frame   (SOF)
Message Identifier  (MID)  either 11 or 29 bits long depending on the chosen mode.
Remote Transmission Request (RTR)  = 1
Control field  (CTRL)  this specifies the number of bytes of data expected to be returned (0-8).
CRC field  containing a fifteen bit cyclic redundancy check code.
Acknowledge field  (ACK)   an empty slot which will be filled by any and every node that receives the frame
                  it does NOT say that the node you intended the data for got it, just that at least one node on the whole network got it.
End of Frame   (EOF)

Error checking

CAN is a very reliable system with multiple error checks
Stuffing error  -  a transmitting node inserts a high after five consecutive low bits (and a low after five consecutive high). A receiving node that detects violation will flag a bit stuffing error.
Bit error  -  A transmitting node always reads back the message as it is sending. If it detects a different bit value on the bus than the one it sent, and the bit is not part of the arbitration field or in the acknowledgement field, an error is detected.
Checksum error - each receiving node checks CAN messages for checksum errors.
Frame error - There are certain predefined bit values that must be transmitted at certain points within any CAN Message Frame. If a receiver detects an invalid bit in one of these positions a Form Error (sometimes also known as a Format Error) will be flagged.
Acknowledgement Error - If a transmitter determines that a message has not been ACKnowledged then an ACK Error is flagged.

Source: http://www.computer-solutions.co.uk/info/Embedded_tutorials/can_tutorial.htm

RS 232 in Nutshell /RS 232 tutorial

RS-232 Serial Protocol

The RS-232 serial communication protocol is a standard protocol used in asynchronous serial communication. It is the primary protocol used over modem lines. It is the protocol used by the MicroStamp11 when it communicates with a host PC.
Figure 23 shows the relationship between the various components in a serial ink. These components are the UART, the serial channel, and the interface logic. An interface chip known as the universal asynchronous receiver/transmitter or UART is used to implement serial data transmission. The UART sits between the host computer and the serial channel. The serial channel is the collection of wires over which the bits are transmitted. The output from the UART is a standard TTL/CMOS logic level of 0 or 5 volts. In order to improve bandwidth, remove noise, and increase range, this TTL logical level is converted to an RS-232 logic level of $-12$ or $+12$ volts before being sent out on the serial channel. This conversion is done by the interface logic shown in figure 23. In your system the interface logic is implemented by the comm stamp.

Figure 23: Asynchronous (RS-232) serial link
\begin{figure}\centerline{\psfig{file=figs/serial-link.eps,width=4in}} \end{figure}
A frame is a complete and nondivisible packet of bits. A frame includes both information (e.g., data and characters) and overhead (e.g., start bit, error checking and stop bits). In asynchronous serial protocols such as RS-232, the frame consists of one start bit, seven or eight data bits, parity bits, and stop bits. A timing diagram for an RS-232 frame consisting of one start bit, 7 data bits, one parity bits and two stop bits is shown below in figure 24. Note that the exact structure of the frame must be agreed upon by both transmitter and receiver before the comm-link must be opened.

Figure 24: RS-232 Frame (1 start bit, 7 data bits, 1 parity bits, and 2 stop bits)
\begin{figure}\centerline{\psfig{file=figs/rs232-frame.eps,width=4in}} \end{figure}
Most of the bits in a frame are self-explanatory. The start bit is used to signal the beginning of a frame and the stop bit is used to signal the end of a frame. The only bit that probably needs a bit of explanation is the parity bit. Parity is used to detect transmission errors. For even parity checking, the number of 1's in the data plus the parity bit must equal an even number. For odd parity, this sum must be an odd number. Parity bits are used to detect errors in transmitted data. Before sending out a frame, the transmitter sets the parity bit so that the frame has either even or odd parity. The receiver and transmitter have already agreed upon which type of parity check (even or odd) is being used. When the frame is received, then the receiver checks the parity of the received frame. If the parity is wrong, then the receiver knows an error occurred in transmission and the receiver can request that the transmitter re-send the frame.
In cases where the probability of error is extremely small, then it is customary to ignore the parity bit. For communication between the MicroStamp11 and the host computer, this is usually the case and so we ignore the parity bit.
The bit time is the basic unit of time used in serial communication. It is the time between each bit. The transmitter outputs a bit, waits one bit time and then outputs the next bit. The start bit is used to synchronize the transmitter and receiver. After the receiver senses the true-false transition in the start bit, it waits one half bit time and then starts reading the serial line once every bit time after that. The baud rate is the total number of bits (information, overhead, and idle) per time that is transmitted over the serial link. So we can compute the baud rate as the reciprocal of the bit time.

Source: http://controls.ame.nd.edu/microcontroller/main/node24.html

Some other good resources :
http://www.winpicprog.co.uk/pic_tutorial7.html
http://www.commfront.com/RS232_Protocol_Analyzer_Monitor/RS232_Analyzer_Monitor_Tester_TUTORIAL2.HTM
http://www.lammertbies.nl/comm/info/RS-232_specs.html

Friday, July 22, 2011

List Of Embedded Systesm E Books

Here is a collection of Ebooks Related to Embedded Systems.

Some of the Books are Listed below

Embedded_C_Michael_J_Pont
  
O'Reilly - Understanding The Linux Kernel


 The MicrochipPICand basic electronics.CRC press

The_C_Programming_Language,denis ritchie

beginners_The_PIC_Microcontroller_Book_for beginners

OReilly - Programming Embedded Systems in C and C++

& The Link to download is
http://www.esnips.com/web/sivakumarebooks 

I2C In NutShell (I2C Tutorial)

History

When connecting multiple devices to a microcontroller, the address and data lines of each device were conventionally connected individually. This would take up precious pins on the microcontroller, result in a lot of traces on the PCB, and require more components to connect everything together. This made these systems expensive to produce and susceptible to interference and noise.
To solve this problem, Philips developed Inter-IC bus, or I2C, in the 1980s. I2C is a low-bandwidth, short distance protocol for on board communications. All devices are connected through two wires: serial data (SDA) and serial clock (SCL).

Sample I2C Implementation

Figure 1: Sample I2C Implementation.
Sample I2C Implementation
Regardless of how many slave units are attached to the I2C bus, there are only two signals connected to all of them. Consequently, there is additional overhead because an addressing mechanism is required for the master device to communicate with a specific slave device.
Because all communication takes place on only two wires, all devices must have a unique address to identify it on the bus. Slave devices have a predefined address, but the lower bits of the address can be assigned to allow for multiples of the same devices on the bus.

Theory of Operation

I2C has a master/slave protocol. The master initiates the communication. The sequence of events are:
  1. The Master device issues a start condition. This condition informs all the slave devices to listen on the serial data line for instructions.
  2. The Master device sends the address of the target slave device and a read/write flag.
  3. The Slave device with the matching address responds with an acknowledgement signal.
  4. Communcation proceeds between the Master and the Slave on the data bus. Both the master and slave can receive or transmit data depending on whether the communcation is a read or write. The transmitter sends 8-bits of data to the receiver which replies with a 1-bit acknowledgement.
  5. When the communication is complete, the master issues a stop condition indicating that everything is done.

I2C Communication Protocol

Figure 2: I2C Communication Protocol
I2C Communication Protocol
Since there are only two wires, this protocol includes the extra overhead of an addressing mechanism and an acknowledgement mechanism

Features>

I2C has many important features worth mentioning. It supports multiple data speeds: standard (100 kbps), fast (400 kbps) and high speed (3.4 Mbps) communications.
Other features include:
  • Built in collision detection
  • 10-bit Addressing
  • Multi-master support
  • Data broadcast (general call).
For more information about other features, take a look at the references at the end of this article.

Benefits and Drawbacks

Since only two wires are required, I2C is well suited for boards with many devices connected on the bus. This helps reduce the cost and complexity of the circuit as additional devices are added to the system.
Due to the presence of only two wires, there is additional complexity in handling the overhead of addressing and acknowledgments. This can be inefficient in simple configurations and a direct-link interface such as SPI might be preferred.

Originally, bus defined by Philips providing a simple way to talk between IC’s by using a minimum number of pins.


For More Info On How to Use I2C & the Communication formats ,please see the following link 

I feel This is the Best Tutorial available on net.  

http://www.robot-electronics.co.uk/acatalog/I2C_Tutorial.html

SOFTWARE TECHNIQUES FOR IMPROVING EMC PERFORMANCE

1) USING THE WATCHDOG CORRECTLY
1.1 ) Enable the watchdog as soon as possible after reset, or use the Hardware Watchdog option
if its available.
1.2) Never refresh the watchdog in an interrupt routine.

2) SECURING THE UNUSED PROGRAM MEMORY AREA
fill the unused memory locations with code that forces a watchdog reset or jumps to a known program
location if you do not want to generate a reset.

3) INPUT FILTERING
Check Consistency of a PORT Pin by reading it several times before proceeding with its value in any calculation.

4) MANAGEMENT OF UNUSED INTERRUPT VECTORS

To avoid problems caused by unexpected interrupt occurrences (whatever the source) it is
recommended to manage all the possible interrupt sources by putting a valid interrupt routine
address in the corresponding vector.

5) AVERAGING THE A/D CONVERTER RESULTS

6) REGISTER REPROGRAMMING
It rarely happens that EMC disturbances alter the content of the registers. Generally the registers
concerned are clock control registers or I/O configuration and data registers because
they are close to the chip output pads.
In such cases a good security measure is to refresh these registers frequently.

Source : Application notes from ST  -can be downloaded from :
http://www.esnips.com/doc/195bcc71-1eb6-4cf3-80d1-ebd3cf3d1ad9/Software-Techniques-for-Improving-Microcontroller-EMC-Performance-5833

Thursday, July 21, 2011

Pointer to functions Explained

A good explanation of Pointer to functions

#include

int sum(int x, int y)
{
return x + y;
}

int product(int x, int y)
{
return x * y;
}


int main()
{
int a = 13;
int b = 5;
int result = 0;
int (*pfun)(int, int);

pfun = sum;
result = pfun(a, b);
printf("\npfun = sum result = %d", result);

pfun = product;
result = pfun(a, b);
printf("\npfun = product result = %d", result);

}

Source: http://www.java2s.com/Code/C/Function/Pointingtofunctions.htm

Eighteen Hints to Reduce Code Size

This info is a part of the AVR ATMEL document.
But the points given here applies for almost all the microcontroller.

1. Compile with full size optimization.
2. Use local variables whenever possible.
3. Use the smallest applicable data type. Use unsigned if applicable.
4. If a non-local variable is only referenced within one function, it should be
declared static.
5. Collect non-local data in structures whenever natural. This increases the possibility
of indirect addressing without pointer reload.
6. Use pointers with offset or declare structures to access memory mapped I/O.
7. Use for(;;) { } for eternal loops.
8. Use do { } while(expression) if applicable.
9. Use descending loop counters and pre-decrement if applicable.
10. Access I/O memory directly (i.e., do not use pointers).
11. Declare main as C_task if not called from anywhere in the program.
12. Use macros instead of functions for tasks that generates less than 2-3 lines
assembly code.
13. Reduce the size of the Interrupt Vector segment (INTVEC) to what is actually
needed by the application. Alternatively, concatenate all the CODE segments
into one declaration and it will be done automatically.
14. Code reuse is intra-modular. Collect several functions in one module (i.e., in one
file) to increase code reuse factor.

15. In some cases, full speed optimization results in lower code size than full size
optimization. Compile on a module by module basis to investigate what gives the
best result.
16. Optimize C_startup to not initialize unused segments (i.e., IDATA0 or IDATA1 if all
variables are tiny or small).
17. If possible, avoid calling functions from inside the interrupt routine.
18. Use the smallest possible memory model.