Intelligent Energy Management And Distribution System In Motorsport

– PROIECT DE DIPLOMĂ –

Intelligent energy management and distribution system in motorsport

– DIPLOMA PROJECT –

1. Introduction

2. Product Specification

2.1 Microcontroller

2.2 Can Transceiver

2.3 Transistors

2.4 Analog to Digital Converter

2.5 UART to USB Transceiver

3. Implementation

3.1 Microcontroller

3.2. In-system Programming Connector

3.3 Shift Registers

3.4 CAN Transceiver

3.5 Power Circuitry

3.6 Smart High-Side Power Switch

3.7 UART to USB Transceiver

3.8 Analog to Digital Converter

3.9 PCB Design

3.9.1 Top Layer

3.9.2 Bottom Layer

3.9.3 Other Layers

3.9.4 Assembly Top Layer

3.10 Firmware Development

3.10.1 Initialization

3.10.1.1 Fuse Bits And Clock Generation

3.10.1.2 Ports

3.10.1.3 SPI

3.10.1.4 CAN

3.10.2 Functions

3.10.2.1 SPI Functions

3.10.2.2 CAN Functions

3.10.2.3 Other Functions

3.10.3 Main Program

4.Conclusion

Acronyms

ACK Acknowledgement

ASCII American Standard Code for Information Interchange

BiCMOS Technology that integrates both the bipolar junction transistor and the CMOS transistor

CAD Computer-aided design

CAN Controller Area Network

CRC Cyclic Redundancy Check

DC Direct current

DSP Digital signal processor

EEPROM Electrically Erasable Programmalbe Read-Only Memory

EOF End of Frame

ISP In-System Programming

LCD Liquid-crystal display

LED Light-emitting diode

LSB Least significant bit

MISO Master-in Slave-out

MOSI Master-out Slave-in

MSB Most significant bit

PCB Printed circuit board

PWM Pulse-width modulation

SCK Serial clock

SMD Surface-mount device

SOF Start of Frame

SPI Serial Peripheral Interface

THT Through Hole Technology

TTL Transistor-transistor logic

1. Introduction

„Auto racing, bull fighting, and mountain climbing are the only real sports… all the others are games.”

– Ernest Hemingway

The sport of motor racing has thrilled thousands ever since it first began. It wasn’t long after the first ‘horseless carriages’ had been invented and improved upon that the idea of pitting the strengths of different designs, and the skills of drivers, against one another in a race was conceived. The first organized racing event was in actual fact a Reliability Trial run which took place between Paris and Rouen in 1894. The winning vehicle had to, not only cross the finish line first, but had to be safe, easy to control and reasonably economical to run. The first over the line was Count de Dion, but his vehicle was deemed impractical and the prizes were awarded to the next two cars instead. The winning average speed was only 17km/h but the event gave birth to a new craze – motor racing.

As designs continued to be improved upon, the new sport saw a continued increase in cylinders and engine size. The addition of the pneumatic tire was impractical at first but soon gained popularity. Chassis design changed radically and new brake and tire designs struggled to keep up. And as soon as one design became the winning standard, other car manufacturers would strive to improve upon these to bring their own names into the lime-light. By the early 1900s car speeds were approaching 100mph and races where held on open roads, where both drivers and spectators where often involved in bad accidents. Eventually in 1906 the very first Grand Prix for manufacturers was held by the French. The race took place on a 64-mile course, which was lapped six times a day for two days.

It did not take long for other countries to follow. Germany became a popular place for racing and their Mercedes motorcars often dominated the scene. The Alfa of Italy and the Fiat and Peugeot of France rose to the challenge, and soon they claimed supremacy for themselves. Because of the dangers involved in racing on public roads, wealthy enthusiasts soon started building oval racing circuits, which became very popular. An attempt was made to counteract the dangers of the sport by increasing the rules and regulations surrounding the event. Eventually a recognized and standardized racing sport emerged and much of these standards are still maintained in the motor racing sporting events of today.

Auto racing is one of the most attractive sports around the world and it has been this way since the invention of the combustion engine. Nowadays, this industry has greatly evolved and current racecars are the top of the line in regards of engineering and technological advances, becoming more and more competitive and complex. A lot of technological breakthroughs in the electronics industry have been successfully implemented in the automotive and racing industries making the two of them more inseparable than ever.

Figure 1 – Formula One race competition

In the last 2 years I had the honor and privilege of being a member of the BlueStreamline racing team of the Transilvania University of Brasov, a group of students that build and race their own designed cars in the Formula Student competition. Participating in this competition gave us the opportunity to learn and to experiment and most importantly it gave us a huge experience in this domain in particular and in the entire concept of industrial engineering, taking us from the design phases all the way to production, assembly and finally testing and usage. This project put us face to face to all sorts of problems and situations that engineers worldwide are faced with on a daily basis, making this an invaluable source of learning and experience gathering for any engineering student.

Even from the beginning of my childhood, cars have been one of my most passionate hobbies. I also have dreamed of becoming a driver in a racecar and now, with the help of BlueStreamline racing team of the Transilvania University of Brasov my dream came true. This is the reason why I decided to choose this subject for my diploma project. Moreover, with the implementation of the power module our team is better and stronger and most important much more efficient for the future competitions.

The subject of this diploma project has been chosen to be the power module of the race car due to its significant importance in the car and due to the need and will to implement a new and complex electronic system. It is inspired by the power modules solution found in the modern race cars in which the racing engineer can analyze all the electrical components. Besides de obvious function of supplying the car with electrical power, the power module also has the role of monitoring all the power that the electrical components absorb from the battery. This is very useful when diagnosing faulty power lines or damaged ventilation fans or fuel pumps. The challenge of this project was to design and build a final product that has a large number of features and functions, and also remain as small, light and stiff as possible.

On this occasion, I would like to thank my project advisor, Conf. univ. dr. ing Carmen Gerigan for her support and guidance along the way in the making the project and also in the writing of this diploma project.

I would also like to thank the Bluestreamline team for giving me the chance to work on this amazing project that is call Formula student.

This diploma project is structured in such a way that it presents the actual flow of the design process with all the phases involved. Chapter 2 presents the project description and the block diagram that stands at the foundation of the project design and implementation. Chapter3 contains the implementation and the schematics of all the components used in manufacturing the design, it also contains the PCB Design and the programming that stands at base of the microcontroller. Chapter 4 contains conclusion about the project and personal impressions that were made during the realization of this diploma project.

2. Product Specification

This project was chosen because its increasing importance in modern society, a society where the need of electrical power increases every day.

Electronics were introduced in automotive industry from the need to better control the engine and optimize fuel consumption. The first electronics that were used were referred to as Engine Control Units (ECU). From then till now the automobile has evolved dramatically and almost all its components are controlled or monitored by some type of microcontroller.

A car’s power module is the most important part in delivering electric power to all the electrical components of the car. Basically it is the heart of all the electrical system and it is in charge of delivering current to all the components of the car. Nowadays, modern cars tend to eliminate traditional relays and fuses in favor of modern semiconductors that are faster and easier to operate by the main processing unit.

In dedicated racecars like the ones in Formula 1 or Rally cars, the step in the fully automated power module has been made due to the need of a centralized distribution system but most important due to its simplified wiring and diagnostic capabilities. The complex wiring is replaced by a more compact unit, which can communicate with the cars Engine Control Unit (ECU) and thus acting on more precise information given by means of Controller Area Network (CAN). Because of this factor, all modern racing cars have a dedicated power distribution module that can be customized by the needs of the user. For example we can observe in Figure 2.1 [1] a custom power module sold by a UK manufacturer named Ole Buhl Racing that is currently used in World Rally Championship (WRC).

Figure 2 – Ole Buhl Racing Power Module2

In order to create and implement the project, a block diagram has been made that illustrates the entire block functions needed for the designing of the power module.

Taking in consideration the main components that need electrical power, the following Bloch Diagram was designed.

Figure 3 Power Module Block Diagram

Figure 3 presents the communication and data lines of the microcontroller in report to all the other components of the Power Module.

As seen, the input of the microcontroller are the data it receives from the CAN network and the data gathered from the transistors and translated by the Analog to Digital converter. Based on this data, it controls the transistors via the control line. Besides controlling the transistors, the microcontroller also sends data to the UART to USB transceiver and after that via USB lines to a WIFI module that communicates with the operator. The data sent to the operator will be used in telemetry and logging purposes so that we can ensure the correct operation of all the devices on the Formula [anonimizat].

The following lines will present in depth the logic of the block diagram and will further details the main features of the final product.

2.1 Microcontroller

The brain of all the modern devices is the microcontroller witch operates all the function of the device. It is the one that takes the decisions in function of different inputs or sensors. In the power module, the microcontroller is the one that controls the transistors and thus, it is responsible of deciding when to give power to different modules.

For example, the microcontroller knows when the brake pedal of the car is pressed and then it immediately give a signal to the transistor in order to the break light to glow. In the case of the break light the information is received via a sensor but for more complex operations like turning on the fan at a certain temperature of the cooling fluid, the microcontroller receives data through a CAN communication line.

2.2 Can Transceiver

The CAN transceiver is the device that serves as the interface between the microcontroller can protocol and the physical bus. This device acts as a decoder and its main function is to convert the digital signals given by the microcontroller to signals suitable for transmission over the bus cabling.

The CAN communication is very important and it was designed to mple, the microcontroller knows when the brake pedal of the car is pressed and then it immediately give a signal to the transistor in order to the break light to glow. In the case of the break light the information is received via a sensor but for more complex operations like turning on the fan at a certain temperature of the cooling fluid, the microcontroller receives data through a CAN communication line.

2.2 Can Transceiver

The CAN transceiver is the device that serves as the interface between the microcontroller can protocol and the physical bus. This device acts as a decoder and its main function is to convert the digital signals given by the microcontroller to signals suitable for transmission over the bus cabling.

The CAN communication is very important and it was designed to allow multiple microcontrollers and devices to communicate between each other within a vehicle without the need of a host computer. It was developed by Robert Bosch GmbH and was first used in 1987 and since then it is the standard protocol that is used in the automotive industry.

Because it is used as a standard in every ECU, we can connect to this network and receive data and logs given by the main processing unit. Using data given by the ECU and decoded by the CAN Transceiver, the microcontroller reacts and operates the transistors.

2.3 Transistors

The transistors are the fundamental building blocks of the power module. The transistors allow a relatively large amount of current to be switched by a much smaller current. This characteristic of the transistor allows a small current generated by the microcontroller to control a greater current provided by the battery. The transistor basically acts as a relay switch but with much faster operation and few other benefits.

The most important benefits of the transistors used in the power module is the capability of providing the analog sense signal of load current and provides fault current signal in case of overload, over temperature and short circuit. This is very important because a single transistor replaces electromechanical relays, fuses and discreet circuits.

The feedback given by the transistors is transmitted to the analog to digital converter and then it is received by the microcontroller, which can react and adjust its operation in function of this data.

2.4 Analog to Digital Converter

The analog to digital converter (ADC) is the device that converts continuous physical quantity, in this case voltage, to a digital number that represents the quantity’s amplitude. In the power module, the transistors have the capability of reporting the power consumption.

Because power consumption is very important in monitoring the correct function off all the devices that the power module control, it is very important to have data regarding the correct consumptions of the devices an more then that, to know if we have a short circuit.

2.5 UART to USB Transceiver

The microcontroller uses for communication the UART (Universal Asynchronous Receiver / Transmitter) protocol in order for it to communicate with a pc or other devices. In order to transmit data from the microcontroller to the external operator via a WIFI communication line, the UART had to be converted to standard USB protocol that is present nowadays on every PC or Laptop.

The UART to USB transceiver is a single chip that doesn’t require any specific firmware programming and this makes the data transmitted by the microcontroller much more easily readable.

All the data gathered by the microcontroller will be sent to the UART to USB transceiver and from there to the end operator. This device is responsible of transmitting telemetry data not only from the transistors, but also data gathered from the ECU via CAN communication.

3. Implementation

The current project has been designed based on a list of custom features specifically chosen for the BlueStreamline BS13 racecar. This list has been updated to enable the motorization and modification of all the implemented features on the car, which include ignition, fans, clutch actuation, fuel pump, dashboard and others based on the team’s six year racing experience. The layout of all the power module components has been made so that it will enable the easiest access to all vital functions and information.

Knowing that the car is a prototype and most of its systems are innovative solutions for different tasks, the power module has been designed to support a large number of units so that a large amount of information can be processed on it. This information is gathered through the help of a large array of sensor monitored by the ECU and sent over the CAN network to the power module and this allows the technician to know how each system is functioning and if everything is in working parameters. For the team to monitor all the electrical components of the car, the power module will have a FT232 controller so that all the information that is gathered by the microcontroller will be sent to a wireless USB adapter that will communicate with a computer over wireless technology.

All this effort of collecting data is made in order for us to gather as much telemetry data so that small adjustments to be made to the car in order for better performance and a greater weight reduction. By knowing how much power we use in an endurance event we can dimension the required battery in order to save weight.

Another important role of the power module is that monitoring the power consumption of every component we can easily detect any faults in the electrical system, such as short circuits, imperfect connections, jammed motors or any other electrical problem that can occur in the electrical system. All this data received makes the job of identifying a problem much easier for us and thus improves the quality and maintainability of the final racecar.

Table 1 contains the list of main features that the power module needs to fulfill in order to supply and control all the electrical components of the racecar.

Table 1 Power Module Required Features

3.1 Microcontroller

A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small amount of RAM. Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications.

Microcontrollers are used in automatically controlled products and devices, such as automobile engine control systems, implantable medical devices, remote controls, office machines, appliances, power tools, toys and other embedded systems. By reducing the size and cost compared to a design that uses a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to digitally control even more devices and processes. Mixed signal microcontrollers are common, integrating analog components needed to control non-digital electronic systems.

In automotive industries, the microcontrollers have a huge role, and nowadays they are used in controlling every part of the car. They are used as the brain of the car in the ECU where high performance microcontrollers control the motor, injectors and all the parts that make an engine run and even in less complex tasks like operating the lights, sensing if the doors are open or adjusting the seat position.

In this project I used the AT90CAN32 microcontroller because it is a high-performance, low-power Atmel 8-bit AVR RISC-based microcontroller and fulfills all the required tasks. The AT90CAN microcontroller is best suited for the task at hand as it has native support for the CAN communication protocol, it has a large number of programmable input/outputs ports, numerous external interrupt pins and a very high operating frequency (16 MHz) for a general purpose microcontroller. Other important features that are worth mentioning are the hardware PWM capability and the hardware SPI interface that will all be used for different tasks. The next section presents a more detailed view of the AT90CAN.

Table 2 presents the electrical ratings that the microcontroller has been designed to work with. It is directly connected to the board’s 5 Volts DC power supply and has decoupling capacitors on each of it’s three power input pins. Right next to the AT90CAN is placed a 16 MHz SMD quartz oscillator that is responsible for generating the stable frequency at which the system is working.

Table 2 – AT90CAN Electrical maximum rating

Notice: Stresses beyond those listed under “Absolute Maximum Ratings” may cause permanent damage to the device. This is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability.

The pinout of the microcontroller is presented in the Figure 4 (taken from its datasheet). Three ground and power input pin pairs can be observed, placed on opposite sides of the package is that the power supply is evenly distributed inside the chip. The large number of general-purpose pins can be seen as well as their alternate functions (written in parenthesis).

Figure 4 – AT90CAN pin layout

3.2. In-system Programming Connector

Programming the microcontroller is done using the In-System programming utility of the chip. It consists of multiple instructions and data messages being sent through the SPI serial interface port. The AT90CAN’s datasheet explains that „both the Flash and EEPROM memory arrays can be programmed using the serial SPI bus while RESET is pulled to GND. The serial interface consists of pins SCK, MOSI (input) and MISO (output). After RESET is set low, the Programming Enable instruction needs to be executed first before program/erase operations can be executed.

Table 3 – AT90CAN Pin mapping serial programming

The appropriate pins needed for the ISP programming interface have been wired to a six pin connector for ease of access. The layout of the connector has been chosen to be compatible with the AVRISP mkII USB programming device that was used to perform all programming related tasks for the AT90CAN.

Figure 5 – AT90CAN Programming connector schematic section

This USB programming device has been chosen due to its small size and price. It is the best solution for low complexity, prototype projects that do not require advanced functionalities like JTAG debug interface or a high-speed parallel programming interface. Following is a list of features of the AVRISP mkII device, taken from its presentation datasheet [11]:

 Atmel Studio compatible

 Supports all Atmel® AVR® devices with ISP, PDI or TPI interface

 Programs both flash and EEPROM

 Supports fuses and lock bit programming

 Upgradeable to support future devices

 Support target voltages from 1.6V to 5.5V

 Adjustable ISP programming speed (50Hz to 8MHz SCK frequency)

 USB 2.0 compliant (full speed, 12Mbps)

 Powered from USB, does not require external power supply

 Target interface protection

 Short-circuit protection

Figure 6 – AVRISP MkII USB Programmer

3.3 Shift Registers

In order to simplify the final PCB layout, I chose to use the 74HC4094D 8-bit serial-in/serial or parallel-out shift register with a storage register and 3-state outputs. This shift registers will control the command input for the smart high-side power switch of the fuel pump, fan 1 and 2, ECU, Logger, Dashboard, Lambda, Brake light and Wi-Fi communication module. Both the shift and storage register have separate clocks. The device features a serial input (D) and two serial outputs (QS1 and QS2) to enable cascading. Data is shifted on the LOW-to-HIGH transitions of the CP input. Data is available at QS1 on the LOW-to-HIGH transitions of the CP input to allow cascading when clock edges are fast. The same data is available at QS2 on the next HIGH-to-LOW transition of the CP input to allow cascading when clock edges are slow. The data in the shift register is transferred to the storage register when the STR input is HIGH. Data in the storage register appears at the outputs whenever the output enable input (OE) is HIGH. A LOW on OE causes the outputs to assume a high-impedance OFF-state. Operation of the OE input does not affect the state of the registers. Inputs include clamp diodes. This enables the use of current limiting resistors to interface inputs to voltages in excess of VCC.

Figure 7 presents a section of the schematic containing the two power shift registers (U20, U21) and an example of how they are connected to the high side power switches.

Figure 7 – 74HC4094D shift registers connected to the fuel pump

3.4 CAN Transceiver

While the transfer layer of the CAN protocol is being handled by the AT90CAN’s internal hardware CAN module, the physical layer is controlled by a Microchip MCP2551 CAN transceiver. In it’s datasheet, it is described as: „a high-speed CAN, fault-tolerant device that serves as the interface between a CAN protocol controller and the physical bus. The MCP2551 device provides differential transmit and receive capability for the CAN protocol controller, and is fully compatible with the ISO- 11898 standard, including 24V requirements. It will operate at speeds of up to 1 Mb/s.”[12]

The main features of the MCP2551 are presented in the figure 8 The high-speed transceiver is used as voltage level shifter, providing the +12 Volts required for the CAN transmission, while being supplied at the circuit board’s 5 Volts DC power supply. The operating frequency of the network has been set to the highest possible value permitted by the transceiver, microcontroller and engine ECU so that data transfer can be done as fast as possible.

Other Features:

Supports 1 Mb/s operation;

Implements ISO-11898 standard physical layer requirements;

Suitable for 12V and 24V systems;

Externally-controlled slope for reduced RFI emissions;

Detection of ground fault (permanent Dominant) on TXD input;

Power-on Reset and voltage brown-out protection;

An unpowered node or brown-out event will not disturb the CAN bus;

Low current standby operation;

Protection against damage due to short-circuit conditions (positive or negative battery voltage);

Protection against high-voltage transients;

Automatic thermal shutdown protection;

Up to 112 nodes can be connected;

High-noise immunity due to differential bus implementation;

Temperature ranges:

– Industrial (I): -40°C to +85°C;

– Extended (E): -40°C to +125°C.

Figure 8 – MCP2551 Internal Block Diagram

Figure 9 displays the section of the circuit schematic in which the MCP2551 transceiver is connected to the CAN port. The two devices are connected by simply putting together the Transmit and Receive pins of their TTL level connection ports. The CAN output pin of the CAN transceiver are directly connected to the network signal wires.

Figure 9 – MCP2551 connection to the CAN port of the AT90CAN – section taken from the schematic circuit

3.5 Power Circuitry

To generate the 5 Volt DC voltage supply needed to power all devices on the board from the car’s 12-14 Volt variable DC voltage supply, a 7805 positive voltage regulator has been used as depicted in Figure. This regulator has been chosen due to it’s proven versatility, small package size and relative small price. Two decoupling capacitors (C17, C18) have been added to the schematic to maintain a steady voltage level even when all digital devices are changing states. Their values have been chosen after analyzing the 7805’s datasheet.

A 47 μH inductor has been on the +12 Volt input power line to filter out all voltage spikes and inherent noise generated by the car’s many inductive loads. Together with the C18 capacitor, the inductor forms a very useful DC voltage filter. As mentioned in the datasheet: „If adequate heat sinking is provided, they can deliver over 1A output current” [13]. This 1 A current limit will never be reached in normal conditions by the steering wheel circuit, but for safety reasons, the 7805 has been firmly connected to a ground plane to allow a better heat dissipation.

Figure 10 – 7805 Voltage regulator connections – section taken from the circuit schematic

3.6 Smart High-Side Power Switch

The main components responsible of supplying the external components with electrical current are the BTS50050D high side power switches. This transistor is a single channel high-side power switch providing protective functions including ReverSave and Infineon intelligent latch. The power transistor is built by N-channel vertical power MOSFET with charge pump. The design is based on Smart power chip technology. The BTS50050-1EAGA has ground referenced CMOS compatible inputs. RaverSave is a protection feature that causes the power transistor to switch on in case of reverse polarity. As a result, the power dissipation is reduced.

The transistor also includes optimized electromagnetic compatibility so that the inductive load generated by other components will not influence the correct operation.[referinta]

Table 4 – BTS50050 Operation specification

Protective functions:

Short circuit protection with latch

Thermal shutdown with latch

Inverse load current capability – Inverse operation function

Under voltage shutdown with restart

Over voltage protection (including load dump)

Loss of ground protection

Loss of Vbb protection (with external diode for charged inductive loads)

Electrostatic discharge protection (ESD)

Other functions included are those of diagnosis and reporting of power used and the capability for multiplexing of the reporting the signal for multiple devices by DEN pin shown in Figure 11. It provides analog sense signal of load current in normal operation mode and fault current signal in case of overload, over temperature and short circuit to ground. In OFF-state it provides open load and short to battery detection.

Figure 11 – BTS50050 Block Diagram

Figure 12 -– BTS50050 Pin Configuration

Taking in consideration the pin configuration shown in Figure 12 and the products datasheet, the transistor is shown in Figure 13 in the circuit design stage.

Figure 13 – BTS50050 in the Power module schematic

The pin definitions and functions are given by the products datasheet and are presented in Table 5 – BTS50050 Pin definition and functions:

Table 5 – BTS50050 Pin definition and functions

3.7 UART to USB Transceiver

The FT232RL is the device responsible with data communications between the microcontroller and the external devices responsible with data processing and telemetry. All the data provided by the AT90CAN microcontroller will be accessible for processing by using standard USB protocol.

The FT232R is the latest device to be added to FTDI's range of USB UART interface Integrated Circuit Devices. The FT232R is a USB to serial UART interface with optional clock generator output, and the new FTDIChip-ID™ security dongle feature. In addition, asynchronous and synchronous bit bang interface modes are available. USB to serial designs using the FT232R have been further simplified by fully integrating the external EEPROM, clock circuit and USB resistors onto the device.

The advantages of this chip are:

Single chip USB to asynchronous serial data transfer interface

Entire USB protocol handled on the chip – No USB-specific firmware programming required

UART interface support for 7 or 8 data bits, 1 or 2 stop bits & odd/even/mark/space/no parity

Fully assisted hardware or X-On / X-Off software handshaking

In-built support for event characters and line break condition

New USB FTDIChip-ID™ feature

New configurable CBUS I/O pins

Auto transmit buffer control for RS485 applications

Transmit and receive LED drive signals

New 48MHz, 24MHz,12MHz, and 6MHz clock output signal Options for driving external MCU or FPGA

The FT232R is fully compliant with the USB 2.0 specification and has been given the USB-IF Test-ID (TID) 40680004 (Rev B) and 40770018 (Rev C).

Figure 14 – FT232RL Schematic placement

3.8 Analog to Digital Converter

The MCP3008 is responsible of converting analog signals provided by transistors and temperature sensor into manageable data used for telemetry and logging purposes. The 8 analog inputs are connected as shown in Figure 15 which is a schematic representation.

Figure 15 – MCP3008 Schematic placement

The analog to digital converter has a huge role in the power module because it gives the main logging data of the power module. It converts the power consumption given by the transistors in analog form to digital data that can be processed and further transmitted by the microcontroller. As shown in the figure above, it communicates with the microcontroller via the SPI BUS.

3.10 Firmware Development

The final stage of the design and production process (after the completion of the physical board and the placement of all components) is taken by the development of the microcontroller’s firmware. All functions have been implemented and tested one at a time to allow a much easier debug and verification effort followed by a complete merge of all firmware components into the overall structure of the program. Any new features or custom requests can be easily implemented based on the modular constructed structure, which has been split into easily identifiable software routines. This chapter presents the basic microcontroller initialization phases, all the running functions and the main loop on which the firmware is based upon.

Firmware development has been done with the help of the CodeVisionAVR compiler which is a software tool specialized in generating, compiling and programming firmware for most of Atmel’s families of microcontrollers. The main programming language used for this project is C but some of the imported firmware libraries have routines written directly in assembly programming language. CodeVisionAVR has a vast number of libraries which allows a very fast and intuitive control of almost all the hardware features of the microcontroller, as well as a very powerful program generator that automatically sets all control registers to the value required by simply selecting the desired functionality. Figure X presents a part of this automatic code generator.

Figure 20 – CodeVisionAVR automatic code generator wizard menu

Figure 21 presents an overview of the vehicle’s electrical system with all the modules involve in the engine and drive control. As can be seen, all modules transfer data and commands on the same CAN bus, differentiating between the useful and unusual messages by the settings of the message objects ID. The engine control unit sends the values of all the important functional parameters and waits for special commands given by the power module. The power module is used to control the large shifter inductive actuator, the fans, the fuel pump, the dashboard, the lambda logger and the main logger. When an upshift or downshift request is received, the steering wheel module transmits this request on the CAN bus to the power module which makes the appropriate actions. Also the coolant temperature is sent through the can bus in order for the power module to actuate the fans. Other messages that are sent through the can bus from the ECU are those of the fuel pump in order for the power module to control their operation. All parameter data and steering wheel commands sent through the CAN bus are recorded by the data logger unit and can be analyzed thoroughly at a later moment in time.

Figure 21 – Vehicle electrical system overview

3.10.1 Initialization

Prior to starting the actual running program, the microcontroller needs to be initialized. This initialization process sets all the parameters for all the hardware functionalities of the microcontroller, which will be used by the actual firmware. The hardware features enabled in this project include two of the four Timers, the SPI and CAN communication ports, four hardware External Interrupts as well as the use of an exterior quartz oscillator. A large number of programmable input/output pins have been used to control the data transfer between the power shift registers and the microcontroller, to transfer data to the LCD display and also to power one of the on-board LEDs. The following pages present the details of each of the hardware modules register initialization.

3.10.1.1 Fuse Bits And Clock Generation

Setting the basic clock generation and start-up times is done with the help of the microcontroller’s fuse bits. In the current project, the clock source has been selected to be the external 16 MHz quartz oscillator while the start-up time has been set to be the fastest possible.

Table 6 – AT90CAN32 fuse bits table

3.10.1.2 Ports

Most of the input/output ports of the microcontroller are initialized as INPUT pins placed in a high impedance state and some will later be used with their alternate hardware function. Pin 0 from port F, all pins from port E (except pin 7) and pins 0,1 and 2 from pin B are set as output pins and will be used to control the data transfer to the power shift registers, the LCD display and the LED in the middle of the board. Their initial value will be set to 0 and will be changed when different software functions will alter it. The following lines of code present the way in which the ports are initialized.

PORTD=0x00; DDRd=0x01;

PORTE=0x00; DDRE=0xff;

PORTA=0x00; DDRA=0x01;

3.10.1.3 SPI

The SPI hardware module is used to transfer data to and from all the shift registers on the board, to collect data from the ADC transceiver and to send data to the USB transceiver. All the modules are connected serially. Initializing the SPI module has been done with the help of these registers:

SPCR=0x58;

SPSR=0x00;

SPCR is the SPI control register. In this configuration it is set to enable SPI operations, set the microcontroller as a Master SPI device and configure the clock polarity to low polarity.

SPSR is the status register of the SPI and it is initialized to a zero value. Since no interrupt operations are requested for the SPI, this register will never be interrogated.

3.10.1.4 CAN

The CAN data reception and transmission is the microcontroller’s most important task and must work flawlessly for the car to function properly. It has been set to assert the message receive interrupt so that all messages are handled as soon as they arrive. Being a message object oriented protocol, the CAN communication on this project has been configured to receive a number of three different message objects (each composed of eight data bytes containing all working parameters from the engine. All these configurations are done in the following manner:

CANGCON=0x01;

CANGCON is the CAN general control register and this first initialization is done to the reset the hardware module. It will later by properly initialized.

Reset all the Mobs (Message objects):

for (ch=0; ch<15; ch++) {

CANPAGE=ch<<4;

CANSTMOB=0;

CANIDT1=0;

CANIDT2=0;

CANIDT3=0; 


CANIDT4=0;

CANIDM1=0;

CANIDM2=0;

CANIDM3=0;

CANIDM4=0;

for (data=0; data<8; data++) CANMSG=0;}

This „for” function is used to initialize all CAN message objects (after reset their value is unknown) even if some of them will never be used. Shifting between the 16 message objects is done by modifying the most significant 4 bits of the CANPAGE register. The actual data of each of the message objects is contained in the CANMSG register which is initialized with a 0 value.

Enable the CAN controller:

CANGCON=0x02;

CANIE2=0x07;

CANIE1=0x00;

CANGIE=0xA0;

CANTCON=0x00;

CANGCON is now written a value of 0x02 which enables the CAN module. 


CANIE2 is used to enable the message receive interrupts of the first three message objects. The rest are initialized with 0.

CANI1 is the second register for initializing message interrupts. No interrupts are used from this register.

CANGIE is the general interrupt enable register and it is set to enable only receive interrupts (while ignoring other possible interrupt sources, like message transmit, errors, timer overrun etc.).

CANTCON is the CAN timer rescales control register. This feature is not used in this project, so the register is initialized with a 0 value.

Initializing the CAN hardware feature is the last part of the initialization process. Having completed this, the microcontroller is ready to start running the actual program. The structure and functionality of all the software functions that are used by the microcontroller’s operations will be presented in the following pages.

3.10.2 Functions

The following pages present all the prototypes for the functions that have been defined and used in the firmware project. Each interrupt input, CAN message or Timer/Capture interrupt that are triggered while the program is running will call a dedicated function that will generate the appropriate response for the request. The function definitions have been split into different categories to simplify their presentation.

3.10.2.1 SPI Functions

void spi_operation() { …

};

This function is based on the CodeVisionAVR SPI library function spi (), which transmits and receives one byte of data through the SPI port. When the microcontroller uses this function, eight bytes of data are sent to the shift registers, each of them receiving it’s designated byte through the daisy-chain formed between them. One byte of data is also received from the ADC converter.

The spi_operation() function is called on each run of the main loop so that the output to the operator is refreshed all the time to allow for the fastest possible response when the data from the transistor is changed and the operator needs to monitor and log the data.

3.10.2.2 CAN Functions

void Can_read_Shifter_Msg() {

}

When any of the two gear shift paddle buttons is pressed from the steering wheel, a message will be sent over the CAN network and it will trigger the Can_read_Shifter() function that will actuate the adequate transistor in order to initiate a gear shift procedure. The shift_type parameter has only two possible values for one of the two upshift or downshift possibilities. Having the highest address priority, the shift CAN message object will be sent as fast as the transmit register of the CAN module is set.

void init_rx_can_mobs () {

};

In order to generate the respective receive interrupt request, all CAN messages need to be properly initialized with the appropriate address ID. This is done by the init_rx_can_mobs() function in which the user can set the number of message objects and the address of each one of them. This allows for a very easy setup and customization of the data bytes that are expected from the different modules on the vehicle making this a very versatile CAN device that could be programmed to work in any CAN-based system. The actual parameters received in each message objects are placed in list of defines that can be found in the annexes.

3.10.2.3 Other Functions

unsigned int multiply_aem_value (unsigned int input, unsigned int aem_constant) {

return input * aem_constant;

};

The engine control unit sends it’s data in different formats and so it needs to be first decoded in order to be displayed. The decoding is done by multiplying the received data value with a special constant given for each parameter. The defines.h file contains a list of all data constants that are used to decode the desired parameter’s value.

void calculate_inputs() { …

};

This function is called on each iteration of the main program loop and is used to call the multiply_aem_value() function for each of the parameters that needs to be displayed. In this way, all program variables are updated with the decoded value of the respective data received on the CAN bus.

3.10.3 Main Program

At start-up, the microcontroller firmware begins by calling the main() function. This function is responsible for running the correct initialization sequence and then running an endless while(1) loop that contains the actual used program functions. The initialization functions have been presented earlier and are called sequentially by the main() routine. This coding style allows fast modifications to any of the hardware modules that require initialization by altering their own initialization function without modifying the basic behavior of the system.

After completing the initialization phase in which all used hardware modules have been properly setup, the program begins running the main loop function of the firmware. It is used to call all calculation and command all transistors in each loop, giving the system a very fast refresh rate. In the same fashion as for the initialization functions, any calculation or command function can be modified separately without disturbing the way the program runs. The functions in the main loop are used to collect values and make calculations based on variables that are updated only when certain CAN message objects are received.

The following list contains the basic variables received from the ECU. All these parameters require some decoding procedures prior to being used.

unsigned char engine_temp;

unsigned char battery_voltage;

unsigned char fuel_pressure;

unsigned char shifter;

unsigned char brake_light;

unsigned char ignition;

The engine_temp char variable is used to record the engine coolant temperature in order to know when the engine is running at its optimal temperature, in this case about 90-100 degrees Celsius. Battery_voltage is logged in order to see what is the real time battery voltage and thus knowing if the rectifying bridge is charging the battery and what is the battery’s voltage. Fuel_pressure holds the live pressure values of the fuel system in order to keep a constant pressure in the injector ramp. Char shifter is responsible of receiving the desired movement of the electromechanically shifter, this being an upshift or a downshift. Break_light is responsible of the actuating the break light when the break pedal is pressed and ignition knows the value of the ignition switch and thus it is responsible of all the modules on the car.

The next figure displays a schematic overview of the while() loop function used to call the calculations and the communication functions. All interrupt functions are displayed in the right side, illustrating the fact that they can occur at any time during the actual program run.

Figure 22 – Microcontroller firmware functional overview

The presented variables containing the engine working parameters are updated on the CAN RX interrupt that signal a newly received CAN message object. All three external interrupt pins are used to call their respective interrupt functions that alter the behavior of the vehicle.

4.Conclusion

The final product’s basic functionalities have been successfully tested on the vehicle and all systems proved to be working well. Small adjustments had to be made and more customization of the firmware needs to be done to enhance the Power Module’s interface with the vehicle. Along with the overall project’s evolution, the Power Module can be updated to transmit different types of data and information as well as to control a larger number of peripheral devices.

Figure 23 – Preparing for the endurance race competition

Overall, this thesis project has proven to be a much bigger challenge than it was first expected and it gave me the chance to learn, experiment and innovate with the latest electronic technologies as well as to experience all the difficult moments any industry engineer has to face. I am thrilled that the project has reached the final version, as it was intended, fulfilling all requested features. This gives me the confidence to progress and to start working on a new, more advanced and complex version of the Power Module for next year’s competitions.

Figure 24 – BlueStreamline racing team at the Silverstone racing track in United Kingdom July 2013

REFERENCE:

Similar Posts