HANcoder/Training Material/SmartCar

From OpenMBD
Jump to: navigation, search

Introduction

Smart car.jpg

The smart car developed in part by HAN-AR is an all-in-one solution for beginner automotive students. It has built-in support for an OLIMEXINO-STM32, which utilizes a 32-bit microcontroller from STMicroelectronics. additionally, the platform has support for the following modules/features:

  • Third party Arduino shields
  • Third party motor drivers
  • Inertial measurements unit (IMU)
  • It has room for implementing your own electronics with a prototyping pcb (5*7cm) & breadboard
  • Onboard speed sensor
  • LIPO battery with an XT60 connector
  • Current measurement functionality (±20A)
  • Wireless emergency stop functionality

Schematic & Board images

  • V1.1 Front render
  • V1.1 Back render


  • V1.1 schematic sheet 1
  • V1.1 schematic sheet 2
  • V1.1 schematic sheet 3

EAGLE files, parts list

Eagle files: File:Eagle Smart Car PCB.zip

Parts list: File:Parts list.zip

Assembly Instructions

Assembling the rotary encoder

The speed sensor consists of a rotary encoder that must be assembled in a particular way. The components that are needed are:

  • 3D printed files, found here : File:Speed sensor.zip
  • AMT103-V Rotary encoder
  • 8 M3 nuts
  • 5 M3x12 bolts
  • 1 M3x16 bolt
  • 1 M6x40 bolts
  • 2 ballbearings 6x13x5
  • 2 ballbearings 3x7x3

First, four M3 nuts must be inserted in the "ATM103 holder". See figure below. It is recommended not to utilize the two center wholes, since that is directly below the drive shaft. If the bolt is too long, then it could introduce friction and damage the driveshaft.

2019-03-06 15.05.16.jpg

Next, insert two bearings (6x13x5) in the housing. In both directions

2019-03-06 15.06.01.jpg

Also, insert the smaller bearings in the housing. Like so:

2019-03-06 15.07.11.jpg

Next, assemble the M6 bolt and 3D printed part.

2019-03-06 15.08.01.jpg

The next part must be performed in order to to push in the bearing into the housing. Use a regular M6 nut and thread it on the bolt. Rotate the bolt/gear until the M6 nut presses into the bearing. Keep rorating the M6 bolt untill the bearing cannot go further into the housing. When the bearing cannot go any further, then it is ok to remove the M6 nut. See image below.

2019-03-06 15.11.292.jpg

A lock nut must now be inserted. This can be difficult due to access being blocked by the housing. The first part of putting the lock nut in can be done with two wrenches. See image below.

2019-03-06 15.18.40.jpg

When you cannot longer use two wrenches, then it is recommended to use a tool to insert into the housing against the lock nut. Keep rotating the first wrench until there is a little bit of resistance. Make sure not to tighten it too much, so that the M6 bolt can still rotate freely. See figure below.

2019-03-06 15.19.22.jpg

Insert the smaller bearing into the 3D printed gearing.

2019-03-06 15.21.44.jpg

Use an M3x16 bolt to secure the smaller bearing to the larger housing. Do not tighten it too much. Make sure both gearings can rotate without too much friction.

2019-03-06 15.23.39.jpg

Next, the AMT103-V can be attached to the 3D printed part. Read the instruction manual that comes with the AMT103-V. Build it like so:

Rot01.jpg

Note: if you find that the red sleeve does not have enough grip to the shaft, increase the thickness of the shaft with a single piece of thin tape. Kapton tape is suitable.

Rot02.jpg

After you have programmed the resolution of the AMT103-V, attach the sensor to the base. Be carefull to aligh the notches on the sleeve with the notches on the AMT103-V.

Mechanical construction

The vehicle’s base frame

The vehicle consists of a basic frame that is manufactured by a company called “Reely”. This frame is pre-built and consists of the following components:

  • The chassis containing
  • Transmission
  • Drive shaft
  • Differential
  • Suspension

The frame comes without a motor and wheels. Therefore, these components must also be included in the construction of the vehicle. The wheels and the motor are thus separately ordered. The motor type is a brushed DC motor instead of the brushless alternative. This is because brushless DC motors are easier to drive, as this can be done with an H-bridge circuit. The dimensions of the vehicle are as follows:

  • Length : 365mm
  • Width : 190mm
  • Height : 122mm
  • Wheelbase : 260mm

VehicleFrame.png

Mounting frame

The mounting frame is the frame on which the electronics can be fastened to. This mounting frame can be fastened to the vehicle via four posts. Under normal circumstances, these posts are used to mount a cover in order to style the vehicle. This is now retrofitted in order to fasten a plate to the vehicle. See the figure below.

VehicleBaseFrame.png

The frame is made from 6mm thick birch plywood. Birch plywood has been chosen as the material because of the following reasons:

  • It can easily be cut by a laser cutter
  • It is cheap and widely available
  • It is not brittle compared to other materials such as acrylic

Mainboard funtionalities

Olimexino support

The OLIMEXINO-STM32 is a development board that houses a 32-bit microcontroller within. With the help of the OLIMEXINO-STM32, it is possible to control the vehicle's actions. The vehicle has a mainboard with built-in support for the OLIMEXINO-STM32. The OLIMEXINO can be fitted to a dedicated slot. See figure below.

SmartCarOlimexino.png

There are several pins the user has access to when the OLIMEXINO-STM32 is utilized. The pins that are accessible are:

Analog pins Digital pins 0 Digital pins 1 Digital pins 2 Supply
A0 D0 D10 D28 Vin
A1 D1 D11 D29 5V
A2 D2 D12 D30 3.3V
A3 D3 D13 D31 GND
A4 D4 D14 D32
A5 D5 D23 D33
D6 D24 D34
D7 D25 D35
D8 D26 D36
D9 D27 D37

SmartCarOlimexinoPinout.png

Third party Arduino shield support

The mainboard on the vehicle has support for Arduino shields. Many different Arduino compatible shields can be fitted onto the mainboard in order to expand the functionality of the vehicle. A dedicated connector has been made to fit this purpose. See figure below.

SmartCarArduino.png

For more information about third party Arduino shields, click here.

Inertial Measurement Unit

An IMU stands for Inertial Measurement Unit, which can be used for measuring a body’s forces. The mainboard is designed in such a way so that the IMU is interchangeable with other modules in order to keep the system flexible. There are many IMU modules available on the market. A small list of popular IMUs is shown below.

SmartCarIMUTable.png

There are many more IMUs then are shown in the table above. Some IMUs have more features such as the ability to measure magnetic fields. Most use different ICs (Integrated Circuits), and depending on the IMU, it would also have a difference in communication protocols. This makes it so that the pinouts and even the physical sizes on many IMUs are different.

The mainboard has two methods of adding an IMU to the system. Method one consists of using a piece of prototyping board with two 10-pin male headers soldered on each side. The male headers interface with the two outer female headers that are present on the mainboard. By manually connecting each IO to the appropriate connector, it would be possible to connect a host of IMUs to the system. An example of how this would look like is shown in the figure below.

SmartCarIMU01.png

The second way of connecting an IMU to the system is by utilizing the middle connector on the mainboard. The IO on this connector is routed in order to be compatible to one IMU module. This bypasses the need to build a custom arrangement. The IMU module that is compatible is a generic board that uses a MPU-9250 IC. See the figures below for the implementation.

MPU-9250.pngSmartCarIMU02.jpg

Adding custom electronics

Breadboard

A breadboard is a device which can be used to quickly prototype custom electronics. The mainboard on the vehicle therefore has a breadboard. There are multiple headers placed on the sides of the breadboard. The different IOs on the OLIMEXINO and peripherals could be accessed through these headers. An image of the pinout is shown below.

Breadboard pinout.png

Most of the headers are routed back to the OLIMEXINO. A couple of others are routed to different places on the mainboard. These are mainly placed on the left side of the breadboard. One of these headers goes towards a quadrature (rotary) encoder. This is the three pin female header with the following naming:

  • ENC_B
  • ENC_A
  • ENC_I

This can be used to determine the speed of the vehicle. The other connector above starting with "MC0" is used in order to send signals to the motor driver. This will later be explained in another chapter.

The last connector on the top-right corner is dedicated to the power peripheral. This is connected to the LIPO battery. With this, it is possible to get access to the unregulated power of the LIPO battery. A couple of voltages that are accessible from here.

  • Vin: 11.1V nominal
  • VBAT0: Voltage accross the first cell in the LIPO battery
  • VBAT1: Voltage accross the second cell in the LIPO battery
  • VBAT2: Voltage accross the third cell in the LIPO battery

Prototyping board

A prototyping board, or perf board is used for prototyping electronic circuits. The mainboard also has headers specifically for the use of breadboards. The dimensions the mainboard is compatible with is : 5x7cm. See figure below for an example.

ProtoBoard.png

The pinout of the Proto PCB area:

BreadboardPinout.png

Motor driver

The mainboard doesn't have dedicated circuitry present to drive the motor of the vehicle. An external driver is therefore used to drive the vehicle's motor. The type of motor that is present on the vehicle is a brushed DC motor. This type of motor requires an H-bridge circuit in order to control the direction and speed of the motor. A recommended motor driver consists of two BTS7960B ICs that together comprise of a full H-bridge circuit. A prefabricated module is available that utilizes these ICs. This is shown in the figure below.

MotorDriver01.jpg

Be carefull in order to ensure that the module is wired correctly !

LIPO battery input & enabling the vehicle

Connect the LIPO battery and RF receiver as such:

LIPOconnected.jpg

Put the On/Off slide switch to the ON position. (Upwards direction in this setup)

OnOffButton.jpg

Click on the ON button on the remote control to enable the vehicle. Likewise, click on the OFF button on the remote to disable the vehicle.

Remote.jpg

Make sure to disconnect the LIPO battery entirely when you are done using the vehicle. Don't just put the ON/OFF slide switch in the OFF position. The vehicle still uses a small amount of current if you don't use it. If left for a prolonged amount if time, this could unnecessarily drain the battery and possibly damage it!

Steering

The component that is used for steering the vehicle is called a servo. The servo is a motor that is connected to an arm that can manipulate the steering angle of the two front wheels. The servo of the vehicle is shown in the figure below. The servo is encompassed by a red box.

SmartCarFrame1.png

The steering mechanism itself follows the Ackermann steering geometry. The Ackermann steering geometry is a geometry that controls the angle of both wheels in such a way so that the tires don’t slip when the vehicle turns a corner. This is achieved by having a central point at which all tires rotate around. If you draw two lines perpendicularly through both wheels, then they will meet near or at the rear axle line. See Figure below for an illustration.

Ackermann.png

Servo motors are generally constructed using a train of reduction gears with a potentiometer connected to the output shaft. These features of a servo make it possible to precisely control the position of the output shaft, and thus precisely control the steering position. The positioning of the servo arm is measured with a potentiometer that is continually compared to the commanded position that is sent. The difference between the commanded position and the actual position generates an error signal which drives the motor either forwards or backwards. When the servo reaches the commanded position, then the error signal reduces and eventually becomes zero. The servo will then cease to move. The connection of an RC servo uses a standard 0.1” or 2.54mm spacing. The connector is usually a three pin Dupont female connector. An image of the connector of the servo is shown below.

ServoPinout.png

The connector has three wires. The brown lead equals to the ground potential or 0V. The red lead is meant for the positive supply voltage. 5 Volts would normally be enough, but the datasheet of the servo motor contains the exact specifications. So, the datasheet must first be consulted before powering up the servo motor. The last lead is the orange wire. The orange wire controls the position of the servo. The way the positioning of the servo motor is controlled is through a process of varying a duty cycle of a square wave. Most generic microcontroller including the one present on the OLIMEXINO-STM32 support hardware based PWM signal generation. Click this link for more information. The connector for the servo can be hooked via the bottom of the mainboard. See figure below.

ServoConnector.png

Wireless communication

Communication between the vehicle and a PC is crucial in order to receive live diagnostic data. The operator could receive data such as:

  • Current speed
  • Wheel angle
  • IMU data
  • Live voltage monitoring of the battery
  • Get data from third-party sensors or modules

Other useful aspects for the operator is to adjust several parameters of the vehicle while it is in operation. The operator could, for example, tune Proportional Integral Differential (PID) control systems. The possibilities are up to the user or operator to decide. The vehicle would always stay within sight and indoors in normal circumstances. Therefore, distance of 10 meters is established as the minimum distance that the operator could still receive data from the vehicle. The data is transmitted by an Xbee module that is connected to an Arduino sensor shield. The individual components and the combined solution is shown in the figure below.


Xbee shield.png

Two Xbee modules are necessary in order to establish communication between two systems. One Xbee module is connected to the host PC via USB and the other system is connected to the OLIMEXINO-STM32 on the miniature vehicle. See the figure below for the block diagram.

Xbee block diagram.png

Both Xbee modules are programmed beforehand, so that only two modules can communicate with each other without interfering with other Xbees. Parameters such as the destination address, identifier, broadcasting modes (unicast & broadcast), transmission power and serial interfacing (baud rate, parity, stop bits) must all be set. See Programming the Xbee to see how to accomplish this.

Software

Programming the Xbee

First, connect two Xbee modules via a USB adapter to the computer.

Xbee programming jig.jpg

If you have not already done so, download and install XCTU. Detect and add these two Xbee modules in XCTU. It is handy if you the program opened in two instances and have it side by side. Configure both like this. (Note that the blue triangle next to the parameters indicate that the value is different than the default value. It is those parameters that must be changed)

Xbee01.png

Change the Destination Address High and Destination Address Low to match the other Serial Number High/Low. This makes these two modules only communicate with each other.

Xbee02.png

Finally, change the COM port settings. Do this for both modules

Xbee03.png

You can test if it has worked by opening two Terminal programs like Realterm. Configure the COM port settings for both modules and transmit some text. If you send data in terminal 1, then you should see the same data in terminal 2.

[example 1] Wireless communication & driving the motor

Setting up the code w/ HANcoder

Global settings

The vehicle's actions can be controlled with the OLIMEXINO-STM32. This chapter will discuss in detail how the vehicle could be set in motion, and how to communicate wirelessly with the vehicle. The image below shows the main view. First, the peripherals of the OLIMEXINO must be initialized. The vehicle utilizes three timers and the USART.

  • The USART is used for communication purposes
  • Three timers are used to control the vehicle's steering and forward/backward direction
    • D24 is used for steering left or right
    • D36 is used for moving the vehicle backwards
    • D37 is used for moving the vehicle forwards

This will later be shown in detail. The figure below shows the global architecture.

Comm02.png

Configure the settings for the UART & PWM channels as follows:

Comm03.jpg

  • On the PWM block that has a frequency of 100Hz, enable channel 4 (D24)
  • On the PWM block that has a frequency of 1004Hz, enable channel 2 & 3 (D36, D37)

Inputs

The vehicle receives data via the serial input. This therefore belongs at the input stage. This looks as shown below:

Comm04.png

The subsystem (on the bottom right in the image above) sends the received data right back. It echo's the data back. This is done in order to test the functionality of the wireless transceiver. In order to duplicate the system, copy this as follows:

Comm05.png

Algorithm

The algorithm processes the data that is received from the Xbee module. Depening on the input data, the vehicle would be able to perform different feats. See figure below.


Comm06.png

First, the data is compared to a constant. This constant represents pressed keys on a keyboard following the ascii code. When for example a certain character is received, then the 8-bit code equals a value between 0 and 255. See http://www.asciitable.com/ to see which characters equals which integer value. If the received data equals the predetermined constant, then this will cause it to toggle a switch. The output of the switch will go towards a PWM peripheral on the microcontroller.

Outputs

The final part is the outputs. Here, all the signals will be ported through to the actual IO of the microcontroller. Copy it as shown below.

Comm07.png

Testing the wireless communication

Connect a Sensor shield with an Xbee module attached to it to the mainboard of the vehicle. Make sure that the Xbee module is pre-programmed and pre-paired before doing so. See figure below:

XbeeMainboard.jpg

Connect a pre-programmed and pre-paired Xbee module to the computer. In order to communicate with the Xbee module that is connected to the computer, it is nescecarry to utilize a program that can send and transmit data with the correct protocol. A program called realterm is used to do this. It is also possible to do this with other software packages such as:

  • Arduino IDE w/ a built-in COM terminal
  • PuTTy
  • Hyperterminal (windows xp)

Select Ansi in the Display As window

Afbeelding.png

  • Select the Baud to equal 115200
  • Select the appropiate port on which the Xbee is connected to
  • Click change
  • Click Open

Comm08.png

Enable the power on the vehicle. If you are a beginner, make sure nothing else on the vehicle is connected. Including the motor driver. That comes next !

Click on the black area in the program and type in some characters. If you see the exact same characters appear on the main window, as you type them in, then it means that you succeeded with communicating with the vehicle.

Comm09.png

Connecting the wires to the mainboard

Make sure that the power on the vehicle is not yet enabled !

This example assumes that you are using the BTS7960B motor driver. Connect the motor and supply wires via the terminal blocks. Next, connect the following signal wires.

BTS7960B Mainboard
5V VCC
GND GND
R_EN MC0
L_EN MC1
LPWM MC2
RPWM MC3

MotorConnections.jpg

Connecting the wires on the mainboard

Make sure that the power on the vehicle is not yet enabled !

A couple of IOs were reserved for the purpose of controlling the vehicle. The following IOs will be utilized:

  • D24 (steering)
  • D36 (PWM forwards)
  • D37 (PWM backwards)
  • D4 (Enable)
  • D5 (Enable)

The control signals of the motor driver is also connected to the mainboard via MC headers. These are:

  • MC0 (R_EN)
  • MC1 (L_EN)
  • MC2 (LPWM)
  • MC3 (RPWM)

Connect the relevant MC headers to the relevant IO of the OLIMEXINO. See figure below. MotorConnections1.jpg

Powering up the vehicle and testing it

Make sure that the switch on the vehicle is in the OFF position. Enable it when instructed so.

If the OLIMEXINO has been flashed with the correct firmware, and if the wires on the vehicles has been connected. Then it can be tested. Perform the following steps:

  • Put something (e.g. a small box) between the chassis of the vehicle and the ground surface. So that the wheels do not contact the ground.

LiftedSmartCar.jpg

  • Turn the vehicle on.
  • On Realterm or other similar program, test if the vehicle will turn its wheels if you transmit '1', '2' or '3'.
    • transmitting '1' will cause the vehicle to turn its wheels left
    • transmitting '2' will cause the vehicle to turn its wheels to the center
    • transmitting '3' will cause the vehicle to turn its wheels right
  • Next, the motor can be controlled. Test if the vehicle will move forwards or backwards if you transmit 'w' or 's'.
    • Transmitting 'w' will cause the vehicle to move forward
    • Transmitting 's' will cause the vehicle to turn backwards

Theory of Operation

Bidirectional level shifting and input protection for digital signals

The OLIMEXINO-STM32 utilizes an STM32F103RBT6 microcontroller, which is a 3.3V microcontroller. This means that many 5V devices are not compatible with the OLIMEXINO. The development board also doesn’t have any protection circuitry in place for the IO’s. This means that the microcontroller could easily be damaged in the case a student accidentally connects 5 Volts instead of 3.3 Volts to some IOs. These requirements can be divided into two parts. Namely:

  • Convert the 3.3 Volt signals to 5 Volts and vice versa
  • Protect the IO’s against overvoltage conditions

The first part; convert the 3.3 Volt signals to 5 Volts can be done using level converters. Level converters are used to interface different systems that run on different voltages. For example: a 3.3V microcontroller communicating with a 5.0V microcontroller. Usually, the 5.0V microcontroller can receive and interpret signals from the 3.3V microcontroller just fine, but this would not be possible in the other way around. Since the voltage potential on the 5.0V microcontroller would be higher than the 3.3V microcontroller. In other words, if the 3.3V microcontroller receives any voltages that is higher than its own operating voltage, then the chance of damaging the microcontroller is high. Because the digital IO’s are bidirectional, that would mean that the level shifter should also be bidirectional. This is because an IO of a microcontroller could both act as an input or output. Hence the name; IO, which stands for Input Output. This would especially be applicable if the microcontroller would use a bidirectional communication protocol such as I2C or one-wire communication. So careful considerations should be made in choosing the type of level shifter so that it would be compatible with all the communication protocols the OLIMEXINO is compatible with, as well as the bandwidth. The second part of the requirement is the protection aspects of the digital IO. If a level shifter is in between the microcontroller and the circuits the user would add, then it is the level shifters that needs protection. The layout of the system should then look like as shown below.

DigitalLevelShiftingBlockDiagram.png

Level shifting

This chapter details the methods that are used to shift the lower voltages of 3.3V to 5.0V and vice versa. The OLIMEXINO STM-32 development board utilizes an STM32F103RBT6 as the main microcontroller. This microcontroller operates at a voltage of 3.3V, which means that the signals that are put on the IO generally cannot exceed the base operating voltage of 3.3V. The word generally is applied here because this is not always true. The STM32F103RBT6 is somewhat tolerant with 5V signals. As some pins are 5V tolerant. For a full list of all the pins that are 5V compatible on the OLIMEXINO, see below.

  • 5V tolerant pins

Because not all the pins are 5V tolerant, this has caused the need to use an external level shifter. The requirements for the level shifter are as follows:

  • Must be able to convert 3.3V signals to 5.0V and vice versa.
  • Must be bidirectional without specifically switching the direction of the signals. E.g. directionless control.
  • Can handle I2C.

The IC that has been chosen to fulfill this task is the TXS0108E. This chip is an 8-bit bidirectional level shifter that meets all the requirements that were mentioned before. The Implementation of this chip is shown in the figure below. Here, there are several pins that need to be connected in the correct way. The OE or “Output Enable”- pin has a pullup resistor to the 3.3V rail. When this pin is pulled low, then all the outputs are placed in a high-impedance state. When the OE pin is high, then the output follows that state of the input. The VCCA and VCCB pins are connected to the 3.3V and 5V rail respectively. The rest of the pins are connected to the different IO’s of the microcontroller.

Implementation of the TXS0108E.png

There is a total of 30 digital pins on the OLIMEXINO-STM32. These are as follows:

D0 D1 D2 D3 D4 D5
D6 D7 D8 D9 D10 D11
D12 D13 D14 D23 D24 D25
D26 D27 D28 D29 D30 D31
D32 D33 D34 D35 D36 D37

One TXS0108E can handle 8 IO at a time. Therefore, there are four TXS0108E IC’s necessary. See the figure below for the implementation of these ICs on all available digital IOs.

Implementation of the TXS0108E on all the IOs.png

Input protection

An TXS0108E is situated in between the IOs of the microcontroller and the user’s input. Therefore, it is the TXS0108E that needs additional protection. See the schematics, sheet 1. The B-port of the TXS0108E is susceptible to whatever the user may provide. Under normal operations, this would be a voltage level that would be equal to or lower than 5 Volts. The absolute maximum Ratings of the TXS0108E is shown in the figure below. Here, it is shown that the input to the B-port is specified to 6.5 Volts. This means that if a voltage of over 6.5 volts is introduced to the B-Port, then the device could become damaged. This must be prevented.

Absolute maximum ratings of the TXS0108E.png

A current limiting resistor and clamping diode is used in conjunction with a TL431. The schematic is shown in the figure below.

IO protection circuit.png

In the schematic above, Vin is the input voltage that a student or user could supply. Under normal circumstances, the voltage would be between 0 and 5 Volts. If the user puts too much voltage on this terminal, then the current limiting resistor R1 and Schottky diode D2 will funnel the excess energy away from the input of the TXS0108E. The protection for the IO on the right in the figure above can be repeated a number of times depending on the number of IOs and the maximum allowable current that the TL431 can handle. The diode that will be used is a BAT54S. The BAT54S has two Schottky diodes within the same package. Schottky diodes have a small forward voltage (VF) depending on the current that goes through the diode. It can be between 240mV and 500mV. If we consider that the forward voltage of diode D2 equals 300mV and the input voltage is much higher than the clamping voltage: Vclamp_5.1V, then the output voltage Vout would equal: Vclamp + the VF of D2. The Vclamp voltage is set at 5.1 volts by the TL431. The output voltage is then: 5.1V + 0.3V = 5.4 Volts. This is still within the tolerances of the TXS0108E, since the maximum tolerable input voltage at Port B is 6.5 Volts. The power consumption is also an important factor. A compact design is required. Therefore, resistor R1 is supplied in a 0805 SMD chip package. These 0805 resistors can dissipate at up to 125mW of power. If the output voltage equals around 5.4 Volts, and the resistance of R1 equals 1K Ohms, then following calculations can be performed in order to ascertain the maximum allowable input voltage. First, the current through the resistor when the resistor is dissipating 125mW:

Math1.png

Taking the previous calculation in mind and noting that the output voltage would equal around 5.4 Volts, then the maximum allowable input voltage would equal:

Math2.png

Around 16.76 Volts is the maximum voltage that can be safely put on any IO that has those clamping diodes present. Any higher and the resistor could overheat and damage the PCB. The maximum allowable input voltage can be increased by two ways. One way is to use a resistor in another package that can dissipate more power. The resistor is the real limiting factor since the BAT54 diode has a forward continuous current of 200mA. The disadvantage of using another resistor type that can dissipate more power is that the size of the resistor also increases. This would limit the usable space when designing the PCB. The second method is by increasing the resistance value of the resistor. If the resistance value is doubled to 2k, then half the current could flow through the resistor. This can theoretically double the maximum allowable input voltage of 16.76V to 33,34V. However, this also increases the impedance of the system, which generally limits the bandwidth. The chosen resistance of 1000 ohms is a good value because the vehicle would be outfitted with a 3 cell LIPO battery. The maximum voltage the LIPO can offer would be 12.6 Volts if the battery is fully charged. Because the maximum voltage of the LIPO is around 12.6 Volts, then the chance that a voltage higher than the battery voltage is introduced to any IO port is low.

The TXS0108E has an input leakage current of around 1uA according to the datasheet. Therefore, most of the current that goes through the resistor will be funneled through diode D2 and finally through the TL431 programmable reference voltage. The TL431 can be used as a replacement of a Zener diode and can handle a maximum of 100mA. The TXS0108E has eight IOs. In the most extreme case; if all eight IOs have an overvoltage condition, then the sum total of all the currents will go to the TL431. See the figure below for the simulation.

Simulation with multiple IOs using protection circuitry.png

The maximum current through the TL431 would then equal around 88mA if all the inputs have an input voltage of 16.76 Volts. This falls below the maximum current of 100mA that the TL431 can handle.

Input protection for analog signals

The input protection for the analogue inputs of the OLIMEXINO is very similar to the methods shown in chapter 3.2.1.2: Input protection. There are a couple of variables that must be considered when doing the component selection. Since the signals are analogue, the signals must not be affected by any circuitry that comes between the user’s input and the microcontroller. The protection circuitry is shown below.

Analogue input protection circuit.png

The protection circuitry shown above is very similar to the methods described in the previous chapter: Input protection. Some differences and extra considerations do apply. First, the resistor R1 is 1000 Ohms. This serves to limit the current that can go through the system. The second resistor R2 is user for additional Electro Static Discharge (ESD) protection. Resistor R2 must therefore be put as closely as possible to the IO of the microcontroller. The clamping diodes have changed from BAT54 Schottky diodes to BAV199 P-N junction diodes. There are two big differences between the BAT54S and BAV199 diodes. Those are the forward voltage and leakage current. First, the forward voltage is the voltage potential between the anode and cathode of the diode before the diode will conduct. The forward voltages of the BAT54S and the BAV199 is included in the table below.

Device Current (mA) Forward Voltage (mV)
BAT54S 1 320
10 400
BAV199 1 900
10 1000

The microcontroller operates on 3.3 Volts and the clamping voltage is set at 3.4 Volts. All the analogue inputs are not 5 Volt tolerant pins. Because all the analogue inputs are not 5V tolerant, according to the datasheet of the microcontroller, the maximum allowable voltage for any analogue input is 4 Volts. Taking the forward voltage of the BAV199 into account, this means that the diode will start conducting if the input voltage is: VF + Vclamp. The resistor R1 is the same type as used in chapter 3.2.1.2 Input protection. Therefore, the calculations for determining the maximum current that can go through the resistor is the same. This was calculated to be 11mA before the resistor would overheat. This will be rounded down to 10mA to make some calculations easier. If 10mA goes through resistor R1, then the forward voltage of the BAV199 diode will be about 900mV. The maximum voltage the microcontroller pin would see at 10mA of current would equal: 900mV + 3.4V = 4.3V. This is higher than the maximum allowable voltage and could theoretically damage the microcontroller. However, there are two current limiting resistors present in order to limit the current that goes to the microcontroller. The total resistance equals: 1000 Ohms + 470 Ohms = 1470 Ohms. The injection current would need to be looked at in order to see how much current can flow into the microcontroller at an overvoltage condition. The absolute maximum ratings for the STM32F103x shows the allowable limits for the injection current. The maximum injection current the microcontroller can handle is 5mA. Therefore, if 5mA goes through the resistors, then the input voltage, according to Ohm’s law would equal: U=I∙R=5mA∙1470Ω=7.35V. So, the input must equal 7.35 Volts before the injected current exceeds the maximum allowable limit of 5mA. As previously stated, the BAV199 diode will start conducting if the input voltage equals 4.3 Volts. Most of the current will therefore be rerouted through the diodes instead of the microcontroller. Therefore, it is safe to put a voltage higher than the maximum allowable input voltage as long as the injected current is less than 5mA. The solution is therefore viable.

Now, the most important reason why the BAV199 diode was chosen over the BAT54S diode is because the leakage current is much lower. The leakage current is the current that the diode will let through from the cathode to the anode. See the figure below for an illustration of the problem. The leakage current can disturb sensitive analog measurements and influence ADC readings. Therefore, the lower the leakage current is, the more accurate the analogue voltage measurements will be.

Leakage current illustration.png

For illustrating the differences of the reserve currents of both these diodes, we will assume the reverse voltage equals 10V. Normally, the maximum reverse voltage would equal 3.4V, since that is the clamping voltage that is set on the cathode of the diode. The table below shows the leakage currents of both diodes.

Device Reverse voltage (V) Leakage current (uA)
BAT54S 10 0.1
BAV199 10 0.000 140

On-board 5V power

The OLIMEXINO-STM32 has an onboard buck converter to convert the battery voltage down to 5 Volts. See the figure below for the circuit.

Buck converter of the OLIMEXINO.png

The OLIMEXINO-STM32 uses an MC33063ADR buck/boost switching regulator. The MC33063ADR is configured as a buck (step-down) converter. The MC33063ADR has a feature where it can limit the output current. This current is mainly determined by the R16 and R17 resistors. The formula to calculate the output current limit is pulled from the datasheet of the MC33063ADR. The relevant formulae is shown below.

MC33063ADR formulae.png

RSC is equal to the equivalent resistance of R16 and R17. These two resistors are connected parallel to each other and have the same resistance. Therefore, the equivalent resistance is 0.47 Ω / 2 = 0.235 Ω. If this value is known, then IPK can be calculated. This is:

Math3.png

Next, IOUT can be calculated. IOUT is the desired output current. This is:

Math4.png

This means that the maximum current the OLIMEXINO could supply is little more than 600mA. 600mA is insufficient for the vehicle’s purposes. Therefore, the mainboard will obtain another buck converter that can deliver more than 600mA.

The circuit for the mainboard’s buck converter is shown below.

Buck converter circuit.png

The buck converter utilizes TPS565208DDCR from Texas Instruments. This IC can deliver 0.76V to 7V at 5 Amperes. The allowable input range is 4.5V to 17V. The vehicle has support for two kinds of LIPO batteries. 2S and 3S LIPO’s. This means that the input voltage can vary from 7.4V to 11.1V nominal. The absolute minimum and maximum input voltage could be in between 6.4V and 12.6V. The lowest voltage of 6.4 Volts comes from a nearly depleted 2-cell battery, assuming that the individual cell voltages are 3.2 Volts. The maximum voltage of 12.6 Volts comes from the assumption that a 3-cell battery that is fully charged. The individual cell voltages at a fully charged battery would be around 4.2 Volts. Taking this wide range of inputs into account, this would make the TPS565208DDCR suitable. The circuit shown in the figure above is designed to output 5 Volts at 4.5 Amperes. The output voltage is determined by two resistors. These are R53 and R54. The formula to get the output voltage is:

Math5.png

The peak current of the inductor uses the following equation:

Math6.png

Here, LO equals the inductance of the output inductor, and FSW equals the switching frequency. This is 550Khz. When the formula is filled in, then the output peak-to-peak current equals:

Math7.png

The output peak current equals:

Math8.png

The RMS output current equals:

Math9.png

Current measuring

Measuring the current draw off a battery is necessary in order to determine the state of the battery. The current that is supplied by the battery is therefore a parameter that a battery management system needs. The measurement device must be able to measure the current that is supplied from the battery, as well as the current that goes towards the battery. So it must be a bidirectional measurement device. The circuit implementation is shown in the figure below.

CurrentMeasuringSchematic.png

As seen in the figure above. The power comes in from the left and exits on the right. As explained in the previous chapter: 3.2.4 Input power from the LIPO and protection features, the power first goes through a fuse (F1). Right after, it goes to a power switch in order to enable and disable the power. It is in between the power switch and output (Vbat out) where the current sensor is situated. The chosen current sensor is the ACS712ELCTR-20B. The current sensor can measure up to 20 Amperes in two directions. This IC is made by Allegro Microsystems and is one version of a lineup of current measuring devices. There are several IC’s available that can measure different currents. The versions that are available are:

  • ACS712ELCTR-05B-T
  • ACS712ELCTR-20B-T
  • ACS712ELCTR-30B-T

As the name hints to, the last value indicates how much current the device could handle. The output voltage is linear with the current that goes through the sensor. The output voltage is 2.5 volts when there is no current going through the sensor. The output voltage gradually increases as the current increases and decreases if the current flows in the opposite direction. See figure below for the graph showing the behavior of the current sensor.

CurrentSensorGraph.png

As seen in the figure above, the output voltage varies from 0.5 volt to 4.5 volt. The microcontroller of the OLIMEXINO can only measure up to 3.3 volts. Therefore, the output voltage must be converted to a more suitable range for the microcontroller’s ADC. This can be done with two resistors that form a voltage divider. The voltage divider circuit is also shown in the schematic, where the circuit is connected to pin 7 of U11. The formula for determining the output voltage is:

Math001.png

If the output voltage of the current sensor is 0.5 volts, then the output voltage of the voltage divider following the formula above would be:

Math002.png

The same approach can be used when the current sensor outputs 4.5 Volts. The voltage that would go to the microcontroller would then be:

Math003.png

The microcontroller can read a voltage up to 3.3 Volts. Therefore, the voltage divider is a suitable option for scaling the voltage to a manageable level.

We can also determine the sensitivity of the current sensor by approximation. The current sensor can measure a current from -20A to +20A. The difference or ΔI equals 40 Amps. The output voltage also swings from 0.5V to 4.5V. Here, the difference or ΔV is 4V. The sensitivity of the current sensor is then: 4V/40A=0.1V_A. So, for every ampere that goes through the current sensor, an equivalent 100mV comes out of the sensor. The sensor then goes to a voltage divider. The output voltage after the voltage divider, and the voltage that the microcontroller sees would then equal:

Math004.png

The microcontroller has a 12-bit analogue to digital (ADC) converter. The full range of the ADC is up to 3.3V. Therefore, the resolution the microcontroller can measure equals:

Math005.png

Which means that the microcontroller can measure voltages in 805uV increments. We already determined that the output voltage at 1A would equal 70.58mV. Dividing 70.58mV by 805uV would give us the number of bits the ADC would output if we had one Ampere flowing through the current sensor. This would then be:

Math006.png

If we know that the microcontroller would output 87 bits for every one Ampere that goes through the sensor, then the resolution of the microcontroller to the current would be:

Math007.png

So, under ideal circumstances, the microcontroller could measure the current at 11mA increments. However, this is not the case. The microcontroller would introduce an inherent error because the ADC is not 100% accurate. A couple of Least Significant Bits (LSB) are lost because of different variables. Such as noise caused by the microcontrollers core. A well-adjusted and calibrated ADC would still have an error of a couple of LSBs. See figure below for the ADC accuracy of the STM32F103RBT6 microcontroller.

AdcAccuracy.png

Moreover, the current sensor also suffers from noise. The total output error of the ACS712ELCTR-20B-T is about ±1.5% according to the datasheet. If we assume that a current of 10 amps is flowing through the current sensor, then the output voltage of the sensor would be 1V. When a potential error of ±1.5% is present, then the output voltage could be between 0.985V to 1.015V. This voltage then goes to a voltage divider using resistors that are accurate to within 0.05%. We will disregard the error that are introduced by the resistors since this is negligible. After the voltage divider, the voltage would range between 0.695V to 0.716V. If we assume that the ADC has a positive error of 5 LSBs, then the voltage could deviate at up to +4mV (805uV * 5). Taking the deviation from the ADC into account, then the microcontroller could measure anywhere from 0.699V to 0.720V when a current of 10 Amperes is flowing through the current sensor. If the microcontroller only uses ideal values, then the microcontroller would also assume that every bit that the ADC returns equals 11mA. Calculating the minimum current can be done by using the following equation:

Math008.png

The same can be done for calculating the maximum current draw:

Math009.png

So, when 10 Amperes goes through the current sensor, the microcontroller could determine any current flowing between 9.86A and 10.16A. This is an error of 160mA. So, taking these factors into account when determining the current flow is important when measuring the current. Also, it must be mentioned that the numbers above are very heavily rounded up to two decimals after the comma. Therefore, the calculations you see here are not completely accurate. The differences between the minimum and maximum current deviation would get closer to each other as you take more values after the comma in consideration when doing the calculations. Of Couse, there are diminishing returns when you take more values after the comma into account, but a good approximation could be made using the approach that is shown above.

Enabling current measuring

In order to utilize the current sensing functionality, a jumper must be set. This can be seen in the image below.

FrontEdited.png

Use a bit of solder to short circuit these two pads circled in red. The analogue voltage will be available at port A3.