Embedded Communication Protocol and Motor Control

i2c


I2C specifications defined maximum clock frequency of 100 kHz. This was later increased to 400 kHz as Fast mode. There is also a High speed mode which can go up to 3.4 MHz and there is also a 5 MHz ultra-fast mode.


I2C Interface

I2C uses only two wires: SCL (serial clock) and SDA (serial data). 

I2C Addresses

Basic I2C communication is using transfers of 8 bits or bytes. Each I2C slave device has a 7-bit address that needs to be unique on the bus.
7-bit address represents bits 7 to 1 while bit 0 is used to signal reading from or writing to the device. If bit 0 (in the address byte) is set to 1 then the master device will read from the slave I2C device.


I2C Protocol

In normal state both lines (SCL and SDA) are high.  Both need to be pulled up with a resistor to +Vdd.

With I2C, data is transferred in messages. Messages are broken up into frames of data. Each message has an address frame that contains the binary address of the slave, and one or more data frames that contain the data being transmitted. The message also includes start and stop conditions, read/write bits, and ACK/NACK bits between each data frame




Start Condition: The SDA line switches from a high voltage level to a low voltage level before the SCL line switches from high to low.
Stop Condition: The SDA line switches from a low voltage level to a high voltage level after the SCL line switches from low to high.
Address Frame: A 7 or 10 bit sequence unique to each slave that identifies the slave when the master wants to talk to it.
Address Frame: A 7 or 10 bit sequence unique to each slave that identifies the slave when the master wants to talk to it.

Read/Write Bit: A single bit specifying whether the master is sending data to the slave (low voltage level) or requesting data from it (high voltage level).
ACK/NACK Bit: Each frame in a message is followed by an acknowledge/no-acknowledge bit. If an address frame or data frame was successfully received, an ACK bit is returned to the sender from the receiving device.


The Data Frame: After the master detects the ACK bit from the slave, the first data frame is ready to be sent. Data bit cannot be changed when clock bit is in high otherwise it will be assumed as start/stop pulse.
The data frame is always 8 bits long, and sent with the most significant bit first. Each data frame is immediately followed by an ACK/NACK bit to verify that the frame has been received successfully. The ACK bit must be received by either the master or the slave (depending on who is sending the data) before the next data frame can be sent.
Multiple Masters with multiple slaves:
Multiple masters can be connected to a single slave or multiple slaves. The problem with multiple masters in the same system comes when two masters try to send or receive data at the same time over the SDA line. To solve this problem, each master needs to detect if the SDA line is low or high before transmitting a message. If the SDA line is low, this means that another master has control of the bus, and the master should wait to send the message.
http://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/
https://www.avrfreaks.net/forum/i2c-twi-library
UART

UART = Universal Asynchronous Receiver Transmitter
USART = Universal Synchronous Asynchronous Receiver Transmitter (uses clock pin)

UARTs transmit data asynchronously, which means there is no clock signal to synchronize the output of bits from the transmitting UART to the sampling of bits by the receiving UART. Instead of a clock signal, the transmitting UART adds start and stop bits to the data packet being transferred.

When the receiving UART detects a start bit, it starts to read the incoming bits at a specific frequency known as the baud rate. Baud rate is a measure of the speed of data transfer, expressed in bits per second (bps). Both UARTs must operate at about the same baud rate. 

UART transmitted data is organized into packets. Each packet contains 1 start bit, 5 to 9 data bits (depending on the UART), an optional parity bit, and 1 or 2 stop bits.


START BIT
The UART data transmission line is normally held at a high voltage level when it’s not transmitting data. To start the transfer of data, the transmitting UART pulls the transmission line from high to low for one clock cycle. When the receiving UART detects the high to low voltage transition, it begins reading the bits in the data frame at the frequency of the baud rate.
DATA FRAME
The data frame contains the actual data being transferred. It can be 5 bits up to 8 bits long if a parity bit is used. If no parity bit is used, the data frame can be 9 bits long. In most cases, the data is sent with the least significant bit first.
PARITY
Parity describes the evenness or oddness of a number. If the parity bit is a 0 (even parity), the 1 bits in the data frame should total to an even number. If the parity bit is a 1 (odd parity), the 1 bits in the data frame should total to an odd number. 
STOP BITS
To signal the end of the data packet, the sending UART drives the data transmission line from a low voltage to a high voltage for at least two-bit durations.
http://maxembedded.com/2013/09/the-usart-of-the-avr/

SPI


One unique benefit of SPI is the fact that data can be transferred without interruption. Any number of bits can be sent or received in a continuous stream. 

Devices communicating via SPI are in a master-slave relationship. The master is the controlling device, while the slave  takes instruction from the master. The simplest configuration of SPI is a single master, single slave system, but one master can control more than one slave


MOSI (Master Output/Slave Input) – Line for the master to send data to the slave.
MISO (Master Input/Slave Output) – Line for the slave to send data to the master.


SCLK (Clock) – Line for the clock signal.
SS/CS (Slave Select/Chip Select) – Line for the master to select which slave to send data to.
Multiple Slaves


SPI can be set up with multiple slaves controlled by a single master. There are two ways to connect multiple slaves to the master. If the master has multiple slave select pins, the slaves can be wired in parallel. If only one slave select pin is available, the slaves can be daisy-chained.
SPI Communication steps:
  1. 1. The master outputs the clock signal.
  2. 2. The master switches the SS/CS pin to a low voltage state, which activates the slave.
  3. 3. The master sends the data one bit at a time to the slave along the MOSI line. The slave reads the bits as they are received.
  4. 4. If a response is needed, the slave returns data one bit at a time to the master along the MISO line. The master reads the bits as they are received.

http://www.circuitbasics.com/basics-of-the-spi-communication-protocol
http://maxembedded.com/2013/11/the-spi-of-the-avr/



Stepper Motor



Two types: Unipolar Stepper Motor, Bipolar Stepper Motor. 




The unipolar stepper motor can be rotated by energizing the stator coils in a sequence. The sequence of these voltage signals applied across the motor coils or leads is enough to drive the motor and hence, no driver circuit is required for controlling the direction of the current in the stator coils.

The two-phase-stepper motor consists of four end wires connected to the coils and two common wires connected to the two end leads to form two phases. The common points and end points of the two phases are connected to the ground or Vcc and the microcontroller pins, respectively. For rotating the motor, the endpoints of the two phases are to be energized. Primarily a voltage is applied to the first end point of the phase1, and further voltage is applied to the first end point of the phase2, and so on.


The stepper motor can be operated in different modes such as Wave Drive Stepping Mode, Full Drive Stepping Mode and Half Drive Stepping Mode.




Wave Drive Stepping Mode
By repeating the above sequence, the motor can be rotated in wave-drive- stepping mode either in a clockwise or anticlockwise direction based on the selection of end points. The table below shows the signal phase sequence for wave-drive-stepping mode.

Full Drive Stepping Mode
Energizing the two endpoints of different phases simultaneously achieves a full-drive-stepping mode. The table shows the signal phase sequence for full-drive -stepping mode.

Half Drive Stepping Mode
The combination of the steps of the wave and full-drive-stepping modes achieves a half-drive-stepping mode. Thus, in this mode, stepping angle is divided into half. The table shows the signal phase sequence of a half-drive-stepping mode.

In general, the stepping angle depends on the resolution of the stepper motor. The size of thesteps and the direction of rotation are directly proportional to the number and order of the input sequence. The rotating speed of the shaft depends on the frequency of the input sequence. The torque and the number of magnets magnetized at a time are proportional.

https://www.elprocus.com/stepper-motor-control-using-avr-microcontroller/

Servo Motor
  1. RED -> VCC
  2. BLACK -> GND
  3. WHITE -> Control Signal.
Servo motors are a type of electromechanical actuators that do not rotate continuously like DC/AC or stepper motors, rather they used to position and hold some object.

Control

Controlling a servo is easy by using a microcontroller, no external driver like h-bridge etc are required. Just a control signal is needed to be feed to the servo to position it in any specified angle. The frequency of the control signal is 50hz (i.e. the period is 20ms) and the width of positive pulse controls the angle.


BLDC MOTOR

working principle is same as induction motor
three phase a,b,c

current cycles: a—>b, a->c, b->c, b->a, c->a, c->b

ESC(Electronic speed controller) control bldc motor speed.
It has three output pin for motor three phase connection. two pins for battery input.
And another three pins for ground,power, and pwm. power and ground can be left open but pwm pin should get pwm input from mcu.

four motor needs four ESC so four pwm is needed for connecting with four ESC.
So we need min four PWM pin micro controller.

ESC current rating should be greater than motor current and it is expensive as motor

a—>b means (a is 1, c is 0, b is -1)


total 360 degree, so each (1/360)*6t=(1/60)*t sec


QuadCopter

Pusher propeller means CW —> drag the copter down (“R” marked in the body)
Normal Propeller means CCW  —> lift the copter up 


Flight Control

4 rotors 2 cw, 2 ccw
stable- 4 motors in same speed
forward- front motor of ccw will be higher than back motor of ccw and total of ccw = total of cw
rotate- both of ccw motors in higher speed than cw motor, total of ccw > total of cw
up-  speed up 4 motors equally

Comments

Popular posts from this blog

Thread & Locks

Opengl-es Buffer

Opengl Stages of Vertex Transformation