Skip to content

Hardware Design

Hampus Sandberg edited this page Jun 28, 2015 · 49 revisions

Index

Circuit Design

PCB Design


Circuit Design

The circuit can be divided into the blocks in the image below. Each block is described in the corresponding section.

Hardware Blocks
Hardware Blocks

MCU

A STM32F407VG was chosen for the project. This is an ARM Cortex-M4 microcontroller in a 100-pin LQFP package with the following important key features:

  • 1 Mbyte of Flash memory
  • 192 Kbytes of SRAM
  • Flexible static memory controller (FSMC) for interfacing with the LCD
  • 2 x CAN interfaces
  • 4 x UARTs
  • 1 x I2C
  • USB Bootloader built in
  • SDIO interface for SD card
  • Real-time Clock (RTC)
  • Available as part of the STM32F4DISCOVERY evaluation tool -> This makes it possible to test the system before sending the PCB off for manufacturing.

One good thing about the STM32 series of microcontroller (and many other ARM based ones) is the ability to map the peripherals to many different pins. This makes it easier to design, as you have more choices where to put the inputs and outputs. A pin mapping for this project can be found as a PDF here.


CAN

Isolation:
The signals coming from the MCU (CAN1_RX and CAN1_TX) are isolated using a FOD8012 dual channel optical isolator. One alternative to FOD8012 is ADUM1201 which is a bit cheaper but uses a kind of transformer type of construction instead of the optical in the FOD8012. This will isolate the communication signals but the power has to isolated as well so that everything on the right side of the FOD8012 is physically disconnected from the left side. This is done using a CME0505SC isolated DC/DC converter as can be seen in the image below.

CAN1 Power Isolation
Power Isolation for CAN1

CAN Transceiver:
The CAN controllers on the microcontroller has to be connected to CAN transceivers in order to communicate with other CAN devices on the bus. It's the transceivers job to provide an interface between the CAN controller and the physical two-wire CAN bus described here on Wikipedia. This will provide the differential signals CAN-High and CAN-Low used on the bus. There are many different CAN Transceiver available, as can be seen by doing a quick search on DigiKey for example. For this project the TJA1051 from NXP was chosen which is pin compatible with some of the other transceivers.

CAN1 Transceiver
Isolator and Transceiver for CAN1

Switching Relay:
The outputs are controlled by a relay to be able to disconnect the device completely from the CAN bus which is connected at the input. This is done using a EC2-5NU DPDT (double pole, double throw) relay. The control signal CAN1_Switch is coming directly from the MCU but because of how a relay is constructed it will be isolated from the CAN signals, so the isolation will not be broken. An image of the circuit for CAN1 can be seen below. The diode across the relay is a so called Flyback diode used to protect the rest of the circuit from possible voltage spikes.

Switching relay for CAN1
Switching relay for CAN1

Termination:
On a CAN bus there has to be a termination resistor in each end of the bus with a typical value of around 120 ohm (Wikipedia). For the Serial Monitor the user should be able to switch in and out a termination resistor depending on the setup it is used in. This is done with the relay shown in the image below. It's basically the same circuit as for the switching relay but now a resistor is switched between CAN-High and CAN-Low instead.

Termination relay for CAN1
Termination relay for CAN1


UART

Isolation:
For simplicity and also to keep the number of different components to a minimum the FOD8012 is used to isolate the UART channels as well, as can be seen in the image below.

UART1 Isolation
UART1 Isolation

Switching Relay:
The outputs are switchable using the same type of relay as with the CAN channels.

UART1 Switch
UART1 Switch

Voltage Selection Relay:
To be able to connect the UART to many different peripherals one must take care of the voltage level at which the UART is operating at. Some devices might take damage if you send a 5 V signal and it can only accept 3.3 V. Therefore a third relay is used to let the user switch between 5 V and 3.3 V, with 3.3 V being the default to be safe. Some jumper resistors are also available if this switching functionality is not needed and you want to use a fixed voltage.

UART1 Voltage Relay
UART1 Voltage Relay

Power:
The CME series DC/DC converters chosen are pin compatible with converters from other manufacturers, for example the TME series, the RO series or the PDS1-S series just to name a few. This makes it possible to replace the converters if the one you want is not in stock or for any other reason. The isolated 3.3 V and 5 V used for UART1 is shown in the schematic below:

UART1 Isolated Power
UART1 Isolated Power


RS-232

Isolation:
As the signals coming from the MCU going to the RS-232 transceiver are basically the same as those for the UART channels the isolation is identical.

RS-232 Isolation
RS-232 Isolation

RS-232 Transceiver:
To convert the logic levels coming from the MCU through the isolator to RS-232 compatible levels the MAX3311 is used. The circuit for this is quite straightforward with only a few external capacitors which are used to generate the voltage levels for RS-232.

MAX3311 RS-232 Transceiver
MAX3311 RS-232 Transceiver

Switching Relay:
The same design is used as for the UART channels so take a look there for more details.

RS-232 Switch
RS-232 Switch


GPIO

Input/Output switching:
The two GPIO channels can as the name implies be used as either inputs or outputs and can be chosen from software. From the MCU there are two signals to each channel, one that sets the direction and one where the actual signal is. To be able to switch between the two modes a couple of single-pole double-throw (SPDT) analog switches are used, namely SN74LVC1G3157. They have a fairly low On-State resistance of around 8Ω @Vcc=3V which should be good enough as the GPIO channels are NOT meant to drive any big loads. If anyone wants to do that they can add some circuitry which takes the GPIO channel as an input signal. As for the speed the datasheet claims 300 MHz @Vcc=3V which is way beyond the limit of the MCU.

GPIO Channel 0 circuit
GPIO Channel 0 circuit

Isolation:
As can be seen in the image above a FOD8012 is used here to get the input and output functionality. There's also a FODM8071 to isolate the direction signal which is used for the SN74LVC1G3157 directly connected to the connector.

Voltage Levels:
The GPIO channels are driven by two separate 3.3V isolated DC/DC converter which means that if the channel is configured as an output a HIGH signal will be 3.3V. This should work with 5V system as the threshold for a HIGH signal is usually below 3.3V so it will register as HIGH. If on the other hand the channel is configured as an input and a 5V signal is applied there could be a problem. According to the datasheet for SN74LVC1G3157 the maximum I/O voltage range is Vcc+0.5V = 3.8V. TODO: I will perform some test to see if this is true or if it's ok to input a 5V signal.


Power

Raw Power:
To be able to power the device from as many different kinds of sources as possible there is what is called a Raw Power input. It's basically a pluggable terminal block that is feeding a wide input DC/DC converter. Because terminal blocks have zero "reverse insertion protection" there is a diode in series before the converter in case someone decide to connect it the opposite way. There is also a fuse protecting the device in case something bad would happen.
As with many other aspect of the overall design a converter was chosen which was as standard as possible so that it could be replaced if more power is needed, or if that particular model is out of stock. More specifically it's a Murata NCS6S1205C packaged in a common 24-DIP metal can. It's a 6 Watt module with an input voltage range of 9-36 VDC and a 5 VDC output. As an example it can be replaced by a Murata NCS12S1205C if 12 Watt is needed. These DC/DC converters are also isolated.

USB Power:
The USB Power input is not meant to be plugged in to a computer to get power from there, as the device will draw quite a lot of power. It is instead meant for a portable USB battery pack as for example one of the Limefuel products. The idea is to be able to have a somewhat portable device this way, as a battery pack is usually quite small and light. One important thing to note is that the USB Power is not isolated from the rest of the device, and it doesn't make much sense to do so if an external (floating) battery pack is used. A fuse is used here too in case something bad happens.

Limitations:
With this design of the power circuitry it is very important that the raw power and USB power ARE NOT connected at the same time.

Image of the circuit:

Power Circuit
Power Circuit


ADC

The ADC channel is an optional part of the device mainly implemented because it might be fun to try to do some kind of oscilloscope or digital multimeter. It should be able to handle somewhere around +-50 V, i.e. it should be possible to connect the inputs in opposite way and get a negative voltage (like a multimeter). This requires some care because most AD converters can't handle such high input voltage.

Voltage Divider:
The first stage after the input connector is a voltage divider for both the (+)-channel and (-)-channel. With the values shown below we will get a division by two so for example -24 V in will give -12 V on the output of the divider.

Voltage Divider
Voltage Divider

It might look a bit strange if one is used to Single-Ended signals where the (-)-channel is ground but it's possible to simulate this circuit using for example Multisim. A screen capture of a simulation is shown below where one can verify the functionality.

Voltage Divider Simulation
Voltage Divider Simulation

AD Converter:
One crucial specification for the AD converter is that the inputs should be able to handle a differential signal. Luckily there's a bunch of converters that do. The other important parameter has do to with the wide input scale the ADC-channels should be able to handle (+-50 V), as it would be bad to use the whole scale if for example only a 5 V signal is measured. By amplifying the signal it is possible to get a better resolution for low voltage signals. This can be done with a Programmable-gain amplifier (PGA) which can be a separate chip or even better included in the AD converter. MAX1301 is a 16-bit converter of that type and it also has differential inputs, perfect! As can be seen in the datasheet (figure 8 on page 19) there are three possible input voltage ranges (gain levels) when using it in differential mode:

  • +- 6.144 V
  • +- 12.288 V
  • +- 24.576 V

This means we can change the range according to the input signal to get the best possible resolution. Together with the voltage divider we can measure these input signals with the resolution in brackets:

  • +- 12.288 V (0.375 mV/bit)
  • +- 24.576 V (0.75 mV/bit)
  • +- 49.152 V (1.5 mV/bit)

Voltage Reference:
The MAX1301 has an internal 4.096 V voltage reference with an accuracy of 40 mV and temperature coefficient of +- 30 ppm/°C. It's not that important with absolute accuracy as it's possible to calibrate the device in software by applying a known signal and reading the output of the AD converter but the relative accuracy, i.e. the temperature coefficient is important. If the temperature were to increase or decrease (which it will) the reference voltage will change. In this application note from Linear Technology they have a very handy translator between different units on the first page. Because the MAX1301 is a 16-bit converter it will translate to roughly 15 ppm/bit so a 30 ppm change will likely be noticeable in the conversion process. Therefore an external reference called MAX6126A41+ was chosen which has an accuracy of +-0.06 % and a temperature coefficient 3 ppm/°C maximum. The whole circuit with the AD converter and voltage reference can be seen below. A reference design is available for this combination which is partly why it was chosen.

AD converter with voltage reference
AD converter with voltage reference

Sample Rate:
The sample rate for the MAX1301 is specified as 115 ksps maximum. A good explanation on how this relates to the highest frequency possible to measure can be found here. Basically it is limited by the so-called Nyquist Theorem which states that the sample rate has to be at least twice the highest frequency component in the signal we want to measure. That means the highest frequency this circuit will be able to measure is below 115/2 = 60 kHz.

Isolation:
To isolate the ADC channel three optocouplers are used. There's a dual channel bi-directional FOD8012 for the MISO and MOSI signals and for the clock (SCK) and chip select (CS) signal a regular optocoupler named FODM8071 is used. One alternative to using these three ICs would be an ADUM1401 digital isolator, but I've tried keeping the isolators as optocouplers to minimize any noise. The circuit is shown below.

ADC Isolation
ADC Isolation


Communication

USB:
A micro USB connector is connected to the Full-Speed USB interface of the MCU which makes it possible to have a high speed connection to a computer. The first usage though is for the built in bootloader of the MCU so that one can load new firmware into the device easily.

Bootloader:
On the MCU there's an embedded bootloader that is programmed by ST from factory (so you can't change it which is a good thing). To enter the bootloader a switch shown below has to be set to the boot position and the power has to be cycled. Once this is done and a micro USB is connected to the device a DFU (device firmware upgrade) can be performed using some software running on the computer.

Bootloader switch
Bootloader switch

Spark Core:
Wireless connectivity is an optional part of the device and to make it really simple the Spark Core was chosen. It's basically an Arduino Compatible, Wi-Fi enabled development platform with great documentation and it's open source too so there's not much else to ask for. The alternative would have been to use a CC3000 module (which the Spark Core uses) or some other wireless module and start writing code to interface with it but it didn't make any sense when it's an optional part of the device. With the Spark Core it's basically plug and play and the software that has to be written for it is probably way less, and it also off-loads the connectivity from the main microcontroller. Another good thing with using this development platform is that the header used to mount it can be used for a custom module if someone has other needs. The headers have 5 V power and a UART interface talking to the main MCU which means you could make a PCB for nRF24L01+, a Xbee or some other module. As long as the pin header has the same spacing as the Spark Core you could plug in anything you want.

Spark Core
Spark Core


Storage

External FLASH:
To store settings data or other data relevant to the operation of the device an external FLASH memory is used. The SST25VF016B was chosen as it provides 16 Mbit (2 Mbyte) of memory at a low cost. It's pin compatible with SST25VF032B if one wants more storage, but in that case it's probably better to use the SD Card. To interface with the memory SPI is used as can be seen in the schematic below.

External FLASH
External FLASH

Micro SD Card:
The Micro SD Card slot is located on the back of the LCD as can be seen in the image below.

Micro SD Card Slot on LCD
Micro SD Card Slot on LCD


Temperature Sensor

There's a simple digital temperature sensor on the board with a decent accuracy depending on what range you want to measure. Considering it shouldn't get to hot it will be correct by ±0.25°C which should be enough for the purpose it serves. The device is a MCP9808 communicating with the MCU on the I2C-bus.

Temperature sensor
Temperature sensor

***

Thermocouple Sensor

As an extra feature there is an input for a thermocouple sensor so that external temperature measurements can be done. The main component for this channel is a MAX31855K K-type Thermocouple-to-Digital Converter seen below.

MAX31855K
MAX31855K

This is connected to the same SPI bus as the ADC converter but with it's own separate isolation so that hopefully the rest of the system will be protected. To be able to switch between this and the ADC an inverter is connected to the chip-select signal before it goes to the MAX31855K so that it will be deselected when the ADC is selected and vice versa.

Inverter for the CS signal
Inverter for the CS signal


Input Protection

For hobby projects there's usually not that much thought that goes into protection of the device designed and the biggest reason is probably cost. There might be a fuse somewhere to protect against a short circuit and those are quite cheap but ESD protection is a bit more expensive for something your device will work without. That's probably one of the main differences between a hobby device and a more commercial device and it makes sense to pay more attention to protection on a device you don't know where and how it's going to be used. For this project there's ESD protection on all input channels which can be left off if cost is a problem. NXP has an application guide on this kind of protection with some examples of protection devices for various interfaces. Most of the protection used here is following those examples.

On all inputs there is a 1 nF capacitor connected to ground. This will help in an ESD event as the energy will first go into charging this capacitor before entering the rest of the circuit. Some more explanation is given here.

CAN:
For the CAN channels a PESD1CAN TVS diode is used which supposedly is designed for CAN.

ESD Protection CAN
ESD Protection CAN

UART:
The UARTs can be considered as "normal" outputs in the sense that they don't deal with any high voltages so a regular 5V TVS diode is used, PESD5V0L2BT

ESD Protection UART
ESD Protection UART

RS232:
For the RS-232 the TVS has to handle higher voltages so a PESD12VL2BT was chosen.

ESD Protection RS-232
ESD Protection RS-232

GPIO:
The GPIOs have the same kind of protection as the UARTs.

ESD Protection GPIO
ESD Protection GPIO

ADC:
As the ADC should be able to handle quite high voltages it requires a TVS diode with a higher reverse standoff voltage. Here a PESD24VL2BT is used.

ESD Protection ADC
ESD Protection ADC

USB:
For ESD protection of the USB interface an IP4234CZ6 was chosen that is designed for USB 2.0.

ESD Protection USB
ESD Protection USB

Power: To protect the power input a SMAJ36CA TVS diode is used that is rated for 36 V so that one can use the whole input range of the DC/DC converter. Because the TVS is placed before the reverse protection diode one have to assume that the polarity can (will) be reversed so a bidirectional TVS diode has to be used, otherwise it would start conducting and basically shorting the source supplying the power.

ESD Protection Power
ESD Protection Power


PCB Design

Even thought there's a lot of signals going to and from the MCU to various interfaces, a 2 layer board was enough because of the space that was available. For simplicity the PCB is the same size as the LCD-board which makes it easy to mount them together. The routing of the board was made easier because the system was designed as blocks with signals connecting them to the MCU. By starting to place the different blocks in their own area of the board and routing them separately the complexity was reduced a lot. Some renderings from the manufacturer I use (OSH Park) can be seen below.

Top of PCB
Top of PCB

Bottom of PCB
Bottom of PCB

Clone this wiki locally