Project Design Walkthrough: Airsoft Tracer Unit, Part 3

Get Started with Altium Upverter, Sign Up Now

Upverter Expert - Project Design Walkthrough_ Airsoft Tracer Unit, Part 3

We are back to work on the Airsoft Tracer Unit we started in Part 1 and continued in Part 2. We are building a unit that fits on the end of an airsoft gun and exposes the dark plastic BBs traveling through to UV light, exciting the luminescent material on the BB. This will make the BB glow brightly, making it easy to see during night games, or indoors. In previous articles, we selected our top level components, prototyped, and extensively tested the photogate for detecting the BB. We also ruled out the use of an LED lighting power supply for limiting the current on the UV emitters. In the first article, I mentioned looking at using an SR Latch to hold the state of the photogate after a BB passed through, but hoped that we would not need to do that.

In this article, we’ll be writing some code to run on an LPC11U24. We will be using the MBED online compiler platform to get the basics of our code written for the project, and see if we can do away with the SR latch. Ideally, we should be capturing the edge change of the signal quite rapidly so we can also use the LED unit as a chronograph as well as for ensuring the UV emitter array is only on when the BB is traveling past it.

Microcontroller Test Setup

In Part 2 of this series, we were able to test the photogate in real-world conditions using a 3D printed holder for the light gate components, and using that, we got some traces from the test board with the oscilloscope. We could use the same setup for testing the microcontroller code, however, it’s a little cumbersome to use such a setup for testing purposes. Therefore, I’m setting up a function generator to create a square wave that will closely simulate the timing of the live test I ran. I’m using a 30Hz square wave, which translates to a pulse width of 33.3ms. The square wave is present on two channels, the second of which has a phase of 353° relative to the first. In the airsoft world, 30 rounds per second is considered to be a moderate to high fire rate, which makes this a realistic test speed. The signal going low for 33.33 microseconds (99.9% duty cycle) matches what we measured previously quite well for the highest speed rounds, and the 353° phase of the second channel gives a 613μs gap between the first and second channel firing, simulating a BB traveling through the tracer unit.

Oscilloscope screenshot showing an active low pulse on the yellow channel and similar but delayed pulse on the cyan channel
Generated signal simulating BB entrance (yellow) and exit (cyan) with difference in time between the pulses of 613.6μs 

By using a function generator, we have a ‘best case scenario’ signal that we can use to develop firmware that will prove out the concept and give us reliable timing information to work with.

Using MBED

This code is being developed using MBED, which is an online compiler (which can also be installed on a computer) that uses an open source hardware abstraction layer for ARM Cortex M0 to M4 series devices and is developed by both ARM and the community. This means the code compiled with MBED is portable across many different devices without having to change controller-specific startup code or specific registers for each device’s peripherals. This is similar to the Arduino library, but only for ARM controllers. The online compiler provides a good user experience and makes collaborating with teams easy through built-in source control. There’s a wide range of useful functions built in, as well as many libraries for specific external devices published by the community that are easy to pull into your project.

Because it supports such a diverse range of controllers, my colleagues and I have experienced frustrating bugs that tend to be very platform-specific. For example, on one microcontroller, the timer has a 32-bit implementation, thus overflows after about 35 mins, but on another microcontroller, the timer for the same function has a 64-bit implementation and doesn’t exhibit the same failure. Also, due to the hardware abstraction layer, some portions of code can take significantly longer to execute than if you had used the register/peripheral directly with controller-specific code. The very slight delay this introduces is a common aspect of all hardware abstraction libraries (like Arduino), and is just something you need to work with for the convenience of the library. The platform-specific bugs do eventually get fixed when reported, but it can be a little frustrating when you come across one, and switching to another microcontroller can resolve the issues.

That being said, the bugs are few and far between, and code quality in MBED is generally very high. The platform allows rapid prototyping and evaluation of many microcontrollers to optimize cost, and makes development easy. Although the code for this project is going to be quite simple, timings need to be fairly tight to ensure the UV emitters turn on quickly and don’t stay on too long after the BB has exited the unit. The emitters generate a lot of heat, and we are doing away with current limiting, so to save them from premature failure we need to keep them on for the shortest period possible.

Software Requirements

In part 1, we looked at the overall specifications/requirements for the device, but didn’t go into details for the firmware. This is a very simple device, so it’s software requirements are brief.

Required Functionality:

  • Detect first photogate transition to low level signal.
  • Turn on UV LEDs while the BB transits the tracer unit.
  • Detect second photogate transition to low level signal.
  • Turn UV Emitters off when BB exits the tracer unit.
  • If the exit hasn’t been detected after 700μs, turn the UV emitters off.

Future “nice-to-have” functionality would include a Bluetooth chronograph with memory, allowing you to look back at velocity consistency at the end of the game.

Initial Test Code

We can implement this code in one of two ways:

  • Using a loop to poll the input pins to look for a state change.
  • Using interrupts to execute code when the pin experiences the changing edge we are looking for.

I’m going to go down the interrupt route, as the amount of code we need to run when the interrupt fires is very small, so implementation is going to be very easy. My main concern is whether the interrupt will be raised by the LPC11U24 microcontroller, and makes its way through MBEDs code to my user code quickly enough. If the delay is too long, it might make this infeasible.

A polling loop is an effective way to implement this functionality too, but if we have some code that will take a long time to run inside the loop, such as future Bluetooth functionality, it could block loop iteration for long enough to cause the microcontroller to completely miss the signal transition from high to low. On the other hand, with an interrupt, that long-running code will be paused while the interrupt is handled, and then execution will continue once the interrupt service routine is complete. This allows us to still perform any long-running tasks we may need in the main loop without having to worry about losing a pulse as a BB passes through the light gates.

Programming the LPC11U24

I’m starting out my code with the mbed_blinky template. This code just flashes LED1 on the dev board on and off every 200ms.

The first thing I like to do is set up some definitions for the pins I’ll be using on the microcontroller. This makes changing between dev boards easy, and makes it very clear where all the connections go if you pick the project up again at a later date, or are designing the schematic to go with the circuit board.

#define PIN_GATEONE P0_7 // p21
#define PIN_GATETWO P0_17// p22

#define PIN_LED2 p15 // for oscilloscope to watch

#define PIN_LEDOUT P1_8 // this is LED1
#define PIN_STATUSOUT P1_9 // this is LED2

I’ve defined my pins for both gates, a signal for my oscilloscope to watch, a status LED that will be flashed by the main loop, and another that will flash in time with the oscilloscope watch pin.

In a larger project, I’d have all the definitions in a separate header file to make it so I didn’t need to scroll through all the definitions at the start of the file. It makes it a lot easier to move pins around as you’re routing a circuit board to have all the definitions in one place with recognizable names, rather than having to hunt through multiple areas of code to change pin definitions.

Next, we need to define the IO objects. There are two interrupts for the light gates, and 3 digital outputs for the LEDs. That’s all the project requires—it’s nice and simple.

InterruptIn gateOne(PIN_GATEONE);
InterruptIn gateTwo(PIN_GATETWO);

DigitalOut led(PIN_LEDOUT);
DigitalOut led2(PIN_LED2);
DigitalOut status(PIN_STATUSOUT);

After this, we have two very simple functions to toggle led and led2 on or off depending on the interrupt that gets fired.

void triggerIn() 
{
    led = led2 = 1;
}
void triggerOut()

{
    led = led2 = 0;
}

triggerIn is for the first gate, with the BB going into the tracer, and triggerOut is for the second gate, where the BB is going out of the tracer.

Finally, we get to our main()function. This is going to turn all the LEDs off immediately on boot, and then configure the interrupts to trigger on the photogate edges.

int main() 
{
led = 0;
led2 = 0;
status = 0;


// Interrupt configuration
// Rising edge for end of BB transit through the gate
gateOne.rise(&triggerIn);

// Falling edge for start of BB transit into gate.
gateTwo.fall(&triggerOut);


while(1) {
status= !status;
wait(0.2);
}
}

The main loop is simply going to flash the status LED (LED2) on and off every 200ms.

Compiling the code is all done online, and programming is as simple as dropping the downloaded hex file onto the LPC11U24’s USB flash drive and hitting the reset button.

Oscilloscope screenshot showing the two pulses from the previous figure and the microcontroller response on the magenta channel
Introducing channel 3 (magenta) with the microcontroller response

It looks like it’s doing what it’s meant to do. There is a bit of a delay as we’d expect, but what’s most worrying to me is it seems to be jittering around a lot.

Oscilloscope screenshot showing pulse width and delay overlay on top of the previous figure
The oscilloscope provides us with pulse width data and delay data. The microsecond deviation is worrying.

Using the oscilloscope to measure this jitter, we can see from the falling edge of channel 1 (yellow) to the rising edge of channel 3 (purple) that we have an average delay of 19.73μs. However, the deviation is unacceptably high at 7.79μs. The total deviation of the pulse width is only 3.38μs, which I find interesting. The code should have highly repeatable results, so the delay and pulse width should be rock solid. The oscilloscope is in high-resolution mode, so we can detect as small as 97.14ns of deviation from the function generator pulse.

After some investigation, I removed the status LED flashing, and more importantly the 200ms wait call. Even though the code should essentially be paused during the wait call, it appears the wait state perhaps takes longer to interrupt than executing code does!

Similar to the figure above, but with more consistent delays and nanosecond deviation levels
All the delay and width measurements are now in nanoseconds!

Simply removing the wait call from the code gives us an absolutely stable pulse width and delay between the edge transitions. It’s actually significantly more repeatable than my new function generator is on average, which is quite encouraging for the code.

Improving the Code

We now have something that can switch on and off if the timing is right, but it’s fairly easy to get this code into a bad state. While the code is reading the signal reliably, messing with the function generator outputs (such as turning one off) makes it unhappy. It’s a valid proof of concept to show the interrupts are stable, however the code wrapping them is not, and it needs a few extra checks and balances in place.

bool triggeredState = 0;

I’m going to introduce a global variable to determine if the LEDs are active or not. I could check the led/led2 variable, but a global bool is going to execute a few nanoseconds faster, as well as make the code more readable and maintainable.

bool triggeredState = 0;

I’m also going to need to implement some code to ensure we don’t have the LEDs on for more than 700 microseconds, so we’ll need a Timer and a couple of timestamp objects.

Timer sysTime;
us_timestamp_t gateStartTime;

The Timer and gateStartTime are global. We’ll also add a local timeCheck variable to main(), which would also make the code more legible and maintainable even though we don’t strictly need it given the implementation.

us_timestamp_t timeCheck;

Now that we have the variables set up, we need to start the sysTime timer in the main() function, so I’ll do that right after we set the LED outputs to be off.

sysTime.start();

Next, I’ll relocate the contents of the interrupt routines into new functions so we can call them safely from other locations in the code. Because of the way MBED implements the interrupt service routine, we could call the ISR directly. Nevertheless, I feel it looks cleaner to have the ISR serve the single purpose of just handling the interrupt. If we were implementing the ISR directly with the microcontroller GPIO peripheral, it would need to be in it’s own single purpose function too.

void ledActivate()
{
led = led2 = triggeredState = 1;

gateStartTime = sysTime.read_high_resolution_us();
}

void ledDeactivate()
{
led = led2 = triggeredState = 0;
}

The ISR then gets changed to first check the triggeredState variable before calling these functions.

void triggerIn() 
{
if (!triggeredState)
ledActivate();
}

void triggerOut()
{
if (triggeredState)
ledDeactivate();
}

Finally, our main loop gets changed to be a check to see if the UV emitters have been on for longer than they are allowed.

while(1) 
{
// check for missed second gate
if (triggeredState)
{
timeCheck = sysTime.read_high_resolution_us() - gateStartTime;

if (timeCheck > LED_TIMEOUT)
{
ledDeactivate();
triggerTransitionRead = 1;
}
}
}

This will check the definition LED_TIMEOUT which is set to 700. If the LED outputs are on for longer than 700μs, the LEDs will be deactivated.

Oscilloscope screenshot showing active low pulse on the yellow channel and no pulse at all on the cyan channel and the finite response we expect on the magenta channel
Response is as we expect with the exit signal on channel 2 (cyan) removed.

With the device programmed, and the second channel on the function generator disabled (simulating the second gate missing the BB entirely), we now have a 716.8μs pulse. If we needed exactly 700μs, we could definitely optimize this further, however the code is doing exactly what it needs to at this point.

Oscilloscope screenshot showing no pulse on the yellow and magenta channels and an active low pulse on the cyan channel
It’s also as we expect with the entrance gate pulse (yellow) removed.

As we’d expect from the code, with no start pulse on channel 1, there is no reaction from the microcontroller.

Oscilloscope screenshot showing _ on the yellow channel and _ on the cyan channel and _ on the magenta channel

Finally, with both function generator channels enabled, our pulse is as we’d expect to see—switching on with the first pulse and off with the second.

Long Term Testing

I wanted to make sure we wouldn’t run into any overflows anywhere, so I left the setup running for around 9.5 hours, or 1,000,000 pulses. At the end of the period, the scope looked exactly as I left it, with everything functioning nominally. For the next 24 hours, I would switch on or off a channel on the function generator every time I walked by it, and at the end of the 24 hour period the device was still functioning well.

It appears that, for this project, MBED is going to be the perfect mix of functionality, ease of use, and speed of development. We also ended up not needing any latching of the signal, as the microcontroller is very capable of catching the pulse from the light gate, which will simplify the electronics further.

One Final Change

In the first article in this series I mentioned that I wanted to use the LPC11U12FHN33 microcontroller due to its compact size and low cost. The code I’ve compiled for the LPC11U24 *should* work on the LPC11U12 just fine, however, MBED have mentioned in several forum posts that you should really only use firmware for the exact chip configuration that is on the dev board, including the packaging, or weird things can happen. A friend of mine had this issue recently, in which he had compiled code that worked great on his dev board, but exhibited some strange behavior in his product which used a different package. I certainly can’t blame MBED for this, as most compilers would want you to select the exact part number you are compiling for. That being said, the LPC11U24 in the /401 package on the dev kit has a fairly large footprint—larger than I’d like to use on the circuit board for this.

As we’re only making a couple of these, the extra cost per unit is fairly negligible for a microcontroller upgrade when we are installing over hundreds of dollars (USD) worth of LEDs on the boards. I also have the MBED supported Embedded Artists LPC11U35 breakout board, which features a QFN package microcontroller instead of the QFP on the LPC11U24 dev board. This package change saves a significant amount of board real estate.

So after a quick change of target board in MBED and a switch of the input/output pins, the code is compiled and running on the LPC11U35 instead.

Oscilloscope image showing the response of an LPC11U35 instead of the LPC11U24
The response of the LPC11U35 instead of the LPC11U24

What I find very interesting about the code running on the LPC11U35 is that somehow, we have a much shorter period between the interrupt and the output pin state change. Both microcontrollers offer a 50MHz max speed and are running on a 12MHz crystal oscillator and, ostensibly, have the same architecture internally.

Well, whatever the cause, I’ll happily use this as an excuse to switch to the LPC11U35! A 24 hour test run with the LPC11U35 was also highly successful.

Next Time

We now have the test firmware completed and working reliably. We’ve selected our final microcontroller, and all of our electronics are tested (other than the basic linear regulator used to drive the microcontroller, which doesn’t need any prototyping). We’re finally ready to start on the PCB design in Upverter.

In the next article, we’ll be tackling the schematic capture, PCB layout, and output generation of the manufacturing files to send off to a PCB fabricator.

How to Choose ADC ICs for Your Next Project

Get Started with Altium Upverter, Sign Up Now

Upverter Expert - How to Choose ADC ICs for Your Next Project

Whether you are sensing temperature, humidity, distance, or any other input from a sensor, chances are you will need an ADC to convert the incoming analog signal to a digital signal. Digital signals are easier to process and transmit around a board. When you are designing a data acquisition system from scratch, choosing the right type of ADC is an important task as it will impact the system’s performance and budget. Here’s how to choose ADC ICs for your next PCB and what you need to know about their different operating parameters.

How to Choose ADC ICs

One might argue that platforms like Arduino have a built-in ADC, so why bother with another ADC in the system? The ADC in an Arduino is a 10-bit IC with 4.9 mV step size. For low level signals, you might need a higher/lower resolution or a different step size. In either case, your optimum solution may be to design your own board with an ADC and a microcontroller.

In today’s components market, there is a huge number of ADCs available, each with different topology, resolution, power consumption, price, and other performance aspects. The following figure should give you a good idea of the difference between bandwidth and resolution in different types of systems. This should give you a good idea of the frequencies you’ll be working with and the resolution required for accurate digital conversion in a number of applications.

ADC-1

Resolution vs bandwidth for different applications [Image source]

It is tempting to think that picking an ADC with the highest possible resolution is the best choice for your system, but this is not always the case. While it is true that you need to consider the resolution of your ADC, you also need to understand the range of frequencies it can reliably convert into a digital signal. This is your bandwidth. As an example, if you want to measure distance or proximity (shown in the teal box above), your sensors will likely produce signals in the 1 Hz to about 20 kHz range. The bandwidth of your ADC will need to cover some portion of this signal range if you want to gather accurate measurements.

Types of ADCs

There are many ADC architectures for high precision applications, including Flash, high-speed, and sigma-delta. The choice of architecture is usually determined by the resolution required and the rate at which the input signal is sampled. This actually brings up another important point regarding ADCs; the sampling rate for your ADC needs to be at least double the largest frequency you want to sample.

The most common architectures for imaging, measurement, and data acquisition systems are sigma-delta, successive-approximation register (SAR), and pipeline ADCs. A general distribution of resolution vs. sampling rate is given in the following figure, which provides an idea regarding which ADC best suits a given system.

ADC-2

Resolution vs sampling rate for various ADC architectures [Image source].

This figure tells us something important: there is always a trade-off between resolution and sampling rate. Hence, reaching high resolution is more challenging when you are trying to sample a higher frequency. Let’s look at each ADC topology to understand how this works:

Sigma-Delta ADC

These ADCs work well for high precision (16-24 bits) and sampling rates of a few hundred Hz. There are two important processes used in a sigma-delta ADC: oversampling and noise-shaping. Details on implementing each of these signal processing steps are outside the scope of this article.

SAR ADC

Successive approximation register (SAR) ADCs are by far the most popular ADC used in data acquisition systems. They have resolution of 8 to 16 bits with sampling rates up to several MHz. They also have small form factor and low power consumption.

Pipelined ADC

These ADCs are more popular for sampling high frequencies, which can range from a few MHz to hundreds of MHz with resolution of 8 to 16 bits. Some applications include imaging and video systems, high precision RF measurement systems, and Ethernet or wireless transceivers. Pipelined ADCs suffer from initially low latency (i.e., response time), but afterwards they have high throughput.

Placing an ADC in Your PCB

Once you’ve decided on the type of ADC you want to use in your board, you will need to carefully place it in your layout. If you properly designed the ground plane for your board, you’ll have separated your digital and analog portions into different sections. Note that, when working with low frequencies, it is appropriate to place a notch between the two ground sections, but make sure the entire ground plane remains an unseparated copper region.

You’ll need to place the ADC so that it overlaps the split between the digital and analog ground regions. This is appropriate as modern ADCs generally separate the analog and digital pins onto different sides of an ADC. This allows you to route your analog lines to one side of the ADC and the digital output on the other side. It is best to place the ground pins on the ADC as close as possible to the connection between the digital and analog sections of the ground plane. This helps prevent transient noise from the digital side of the chip from interfering with the analog side.

Now that you understand how to choose ADC ICs, you can start with your resolution requirements. One important thing to consider at this point is power consumption. If your design will run on a battery, then you might need to consider sacrificing some resolution to conserve battery life. The output will have some delay, so latency of your ADC should be tolerable. Some applications have severe area constraints, so you might want to use a single ADC in a time-shared fashion rather than multiple ADCs. This will mean a reduction in sampling frequency, but it cuts down on area and power. Also, check the voltage compatibility of the ADC and your microcontroller.

Upverter® gives you an easy, browser-based platform for designing boards from start to finish. You can easily pick an existing template from a vast range of open-source designs and you can also choose from a vast library of verified components. These standard design features are accessible from anywhere by multiple collaborators.

You can sign up for free and get access to the best browser-based PCB editor, schematic editor, and component database. Visit Upverter today to learn more.

Ethernet PCB Layout in Your Design

Get Started with Altium Upverter, Sign Up Now

Upverter Expert - Ethernet PCB Layout in Your Design.jpg

Ethernet is the traditional technology for connecting wired local area networks (LANs), allowing devices to communicate with each other via a standardized protocol. Since it is a local area technology, it is used mostly for networks operating within a single building. You can use Ethernet to connect your new board to the internet, where you have the freedom to save, retrieve, and visualize your data in a browser.

For some designs it is essential to have some level of remote connectivity for data transfer, monitoring, and sometimes for firmware upgrades. Connecting your project to a LAN allows you to tunnel into your board via SSH and modify software when required. Adding Ethernet to your board requires following some particular routing standards and choosing the correct parts for your board.

Design Considerations for Ethernet

Low cost PLDs, like simpler FPGAs and MCUs, typically need to communicate with an external Ethernet controller via SPI. This external controller provides medium access control (MAC), which is governed in its own firmware, and it acts as the physical layer (PHY). This integrated MAC/PHY then connects to the RJ45 connector using a standardized routing scheme. This is shown in the image below.

ethernet1

Ethernet controller for connecting your device to Ethernet [Image source]

Although the MAC and PHY blocks can be integrated into an external Ethernet controller, some newer MCUs include their own integrated Ethernet controller. This means you won’t need to use an external controller IC. Make sure to check the specifications of your MCU/FPGA before searching for an Ethernet controller IC.

Some examples of Ethernet controller IC are the ENC28J60, W5100, W5500, and many others. The RJ-45 connector can also be packaged in a single device, known as Mag-Jack. Using one of these components eliminates the need to design your own magnetic termination circuit. It should be noted that the Ethernet protocol standards clearly state that you must use a transformer on the Ethernet port in order to provide isolation and to remove any DC bias on the signal.

The image below shows an example of a simple RJ-45 Mag-Jack breakout board. The connector on this board includes the magnetic termination circuit required to isolate the connector. This board can be easily soldered to a standard header on an existing MCU board or on a shield board.

ethernet2

RJ-45 Mag-Jack breakout board

When creating an Ethernet PCB layout, the designer needs to choose the maximum data rate, physical media (i.e., which type of cable), and duplex mode. In embedded systems design, one of the most common speed choices is a 100Base protocol (100 Mbps); anything faster is unnecessary as MCUs are not equipped to handle higher speeds. Going to a GBase (1 Gbps) protocol requires a faster processor and controller. Most development boards that include this level of processing power will already include Ethernet; BeagleBone Black and Raspberry Pi are great examples.

Sometimes, it makes more sense to use 10 Mbps, depending on the speed of other devices in your LAN. This will definitely bring a cost advantage, and you might not notice the difference in communication speed unless your network has heavy data traffic or you need to transmit large amounts of data to/from your device. For example, if you are implementing Ethernet external to the MCU, Microchip’s ENC28J60 10 Mbps Ethernet controller is slightly lower cost than their ENC624J600 100 Mbps controller.

Using Ethernet Shields

If you are working with development board like Arduino or Raspberry Pi, then this task becomes easier. Raspberry Pi already has an Ethernet port where you can directly connect the cable. Here is an excellent tutorial for connecting Raspberry Pi to Ethernet.

shutterstock_413359297

Connecting Raspberry Pi 3 Model B to Ethernet

Arduino doesn’t have a direct Ethernet port, but there are shields available on the market that you can connect to your Arduino board. These shields are basically Arduino-compatible boards that have similar layout and contain an Ethernet controller (either Wiznet W5100 or W5500), and an the RJ-45 Mag-Jack. If you are looking for something cheaper, you can easily find small Ethernet modules for around $10. These modules are small in size, but they have limited speed (10 Mbps). Before you buy one, make sure to check pin compatibility and voltage levels. There are a lot of libraries available that can be used and many examples to help get your design up and running.

Ethernet PCB Layout for Your Own Board or Shield

If the available boards do not suit your specification or you need to meet certain area (footprint) or power constraint, then you might want to design your own board or shield. Signal traces from the controller to the RJ45 connector should be routed as short as possible on a single layer, and traces should be routed in a straight path. Try not to bend a trace by more than 45 degrees.

If your MCU/FPGA does not include the PHY layer, and you are not using an integrated Ethernet controller, the MCU/FPGA will act as the MAC layer and will need to communicate with an external PHY IC to drive signals over the RJ45 connector. Routing between the MAC and PHY layers uses MII or RMII routing, depending on the speed you are working with. Once you understand how signals are triggered in each layer, it becomes rather easy to route traces between the various components.

Upverter® provides a great library of reliable components where you can easily find the parts you need for your Ethernet PCB layout. If you are looking for an Ethernet controller, you can find the ENC28J60, W5100, W5500, and other controllers in the parts database. You can find the SI-60062-F, J0011D01BNL, or JXD1-0001NL RJ45 connectors, all of which have built-in magnetics. Here is a great example of an Ethernet controller module with W5500, which you can use as a template.

As a cloud-based PCB design tool, Upverter gives users the ability to share their designs, control revisions, and store design data in a secure online repository which is accessible from any location. You can browse thousands of open-source designs in Upverter’s projects database and pick one to customize for your new design. 

You can sign up for free and get access to the best browser-based PCB editor, schematic editor, and component database. Visit Upverter today to learn more.

Choosing and Adding a Display for Arduino Projects

Get Started with Altium Upverter, Sign Up Now

Upverter Expert - Choosing and Adding a Display for Arduino Projects.jpg

Many projects that collect data of some kind can be made more user-friendly if a display is added directly to the device rather than using a serial or HDMI monitor. This can also act as an input device if a touchscreen is used. There are a variety of display options available on the market, and Arduino shields are available which provide an easy way to interface with a display for Arduino projects. Let’s take a look at what you can add to your next Arduino project. 

Liquid Crystal Display

These are the most common type of displays used in simpler projects. They are simple to operate, consume a small amount of power, and are very cheap. They usually include an array of characters, with some displays having a backlighting option for ease of reading in low light. It is possible to attach them directly to an Arduino, but they use many pins on the board. An I2C adapter can be used to control the display with only 4 pins.

These screens more desirable than a 7-segment display as they can display a large variety of characters. There is a LiquidCrystal library that you can use to control the LCD, although you will need a different adapter if you are using I2C. Here is a video tutorial on how to set up and use this type of display.

shutterstock_275962166

A 16×2 LCD display that can connect via I2C

7-Segment Display

These are simple displays with 8 LEDs (7 lines and 1 dot) that work pretty much like any LED, where a forward bias will light up the diode. Different numbers or characters can be formed by selectively lighting the segments. They are available in either common anode or common cathode configuration. A good tutorial for using these simpler displays can be found here, where you’ll learn how to interface this display with an Arduino board. These displays come in a variety of sizes ranging from single digits to an array of characters. If you just need to display numbers or a small number of letters (for example, with a door keypad or a timer), then you can give your project a cool retro feel with 7-segment displays.

shutterstock_1479846836

7-segment display (single and array)

5110 Display

These displays were used in old cell phones, where the background was grey and the font was simply a darker shade of grey. These are monochrome LCD displays with 84×48 pixel screen size. These cheaper modules can display text (even multiple lines, depending on the library being used) and images. Although the refresh rate is slow for animations, they work well for simple text display. This display usually comes with a backlight. It has a CMOS LCD controller and these displays only run at about 0.5 mA when on without backlighting. They also have a sleep mode, making them convenient for battery-operated devices.

5110-display

5110 LCD display from Adafruit

OLED Display

If you are looking for something more than a 5110 LCD display, an OLED display can be a good option. At first glance, they look like the 5110 display, but they are significantly better. While the standard screen is 0.96” in monochrome with 128×64 pixels, they are available in a variety of sizes and colors, offering a versatile display for Arduino projects. Their refresh rate is also higher than many other displays. They can communicate with Arduino using I2C, so they do not use a lot of pins. These displays are usually thinner and lighter than an LCD, and they provide higher contrast than an LCD because no backlight is required. The price for these displays is slightly higher than a typical LCD.

shutterstock_570147922

OLED display for Arduino projects

TFT LCD 

Thin-film-transistor (TFT) LCDs are a step up in quality when your project requires a sophisticated display. They are available with or without touchscreen capabilities. They provide high resolution and can display thousands of unique colors. Often they have an SPI interface that integrates naturally into Arduino boards. They consume more power than other displays, but the display quality is better and they come in a similar price range. They usually come with a shield for easy integration. Touchscreens can be especially useful for cases where projects need user feedback and input.

TFT-LCD

TFT LCD that connects to a standard header

The TFT LCD shown above connects to a standard header with pins, but more advanced TFTs can connect to an Arduino or other board with a flex cable. These boards can’t connect directly to a standard Arduino, but they can connect to a standard or custom shield board. Make sure to check how your display connects to your Arduino project as you may need to purchase or design a specific shield.

E-paper Displays

As the name suggests, an E-paper display (commonly found in E-readers) is intended to have the same look as natural paper. They differ from LCD and OLED displays in that they do not emit light, but rather reflect it, making the display very comfortable to read. Another great aspect of these displays is that they can store data for a long period of time without consuming power. This means they can display text or images after they are turned off, making them perfect for low power mobile Arduino projects. Here is a tutorial for using them with Arduino.

e-paper-display

E-paper display

Use a Shield to Add a Display for Arduino Projects

Any of these displays can be a great addition to a new Arduino project. The choice of the best display depends mostly on the display quality you desire and your intended budget. They usually have a shield or can be interfaced directly to the Arduino header pins. Many projects may require multiple components, rather than just a display. It may be better to design a custom shield that can be used to interface with more than one component.

If you’re interested in designing a custom display shield for your Arduino board, Upverter® provides an easy, browser-based platform for designing new PCBs from start to finish. You can easily pick an existing template from a vast range of open-source hardware projects, or you can import Arduino shield templates from Eagle libraries, available from Sparkfun or Adafruit. You can then proceed to lay out the design and make your own shield.

You can sign up for free and get access to the best browser-based PCB editor, schematic editor, and component database. Visit Upverter today to learn more.

Desktop PCB Design Software vs. Online PCB CAD Tools

Get Started with Altium Upverter, Sign Up Now

Upverter Expert - Desktop PCB Design Software vs. Online PCB CAD Tools.jpg

Anyone who is reading this article has already designed their own PCBs in the past, or intends to in the near future. Whether you are a professional or a hobbyist, every now and then the question of which PCB design application is most suitable for your application will come up. And the answer to this question is…it depends!!!!

As far as personal choices go, everyone wants different things from their design software, and everyone has a different level of expertise with their software. Sometimes, the choice of an appropriate PCB design package is governed by your available resources and the required investment. Today, we can divide available software into two categories: desktop applications and online PCB CAD software. Let’s take a look at both categories and their advantages, difficulties, and some popular applications in each category.

What’s the Difference Between Desktop and Online PCB CAD Software

As its name implies, desktop applications must be installed on your local machine. Once you do download and install the software, there is no need for an internet connection to use this software. Online PCB CAD layout tools do not need to be installed on your local machine, although some online tools provide an optional desktop version. This allows users to access the software on-demand. Users don’t need to worry about installation, keep track of their file structure, or worry about constantly compiling and downloading component libraries. However, users must have internet access to use the software.

Who Benefits from Desktop PCB Design Software

Some of the most popular desktop design platforms are Altium Designer, CircuitMaker, Eagle, KiCad, and OrCAD. These are heavy-duty software packages that come with a ton of features; you’ll normally need a license to run a full-featured version. While most of these are Windows, Mac, and Linux compatible, some might need Wine to allow the program to run on a linux-like platform. Once installed, one doesn’t need the internet to work on projects, but usually any work will require frequent data storage, sharing, retrieval, and occasional software updates.

All design data is stored locally on your computer’s HDD or connected storage. You can use some cloud-based storage platforms like Dropbox or Google Drive to save and backup design data. There is some version control software also available, which is preferable to manually transferring data every time you make changes to your design.

Another aspect which users must consider is data sharing. Whenever you are working as part of a team on a complex project, everyone needs a way to collaborate seamlessly on multiple portions of a design. Desktop applications cannot provide these capabilities without expensive addons or third-party software.

 

shutterstock_715844959

Desktop vs. Online PCB CAD tools

Online PCB CAD software

Web-based PCB design software is popular among the open hardware community. All you need is a browser that is compatible with your software and a decent internet connection. The leading names in online PCB CAD tools are Upverter, EasyEDA, and Multisim. Users need not concern themselves with software updates, but these platforms provide different features and disparate levels of support.

All the data is stored in the cloud and can be easily accessed from anywhere in the world. This gives designers freedom to share their data easily without using a separate cloud storage platform. One doesn’t need to worry about version control either because each design version is stored on the cloud.

Perhaps the most important benefit of using online PCB CAD tools is the ability to collaborate. This is where online tools stand out from desktop software. However, not all online PCB CAD platforms provide collaboration features. If you are working on a complex project as part of a team of designers, then you’ll need to ensure that the platform you want to use provides collaboration and data sharing features your team needs to track issues in new designs and make changes to a schematic or layout.

Collaborating in Upverter’s Online PCB CAD Tools

Upverter is an online PCB CAD platform that sets itself apart from other platforms. Here’s some of what makes Upverter different:

  • Import and sharing features. You can import an existing design (Altium, OrCAD, Eagle, etc.) or choose from a great selection of open-source designs from the community. You can design your schematic, layout and choose from a vast library of reliable components.
  • Collaboration and sharing. Collaboration for remote teams is easy in Upverter. Users have access to team-management and advanced access controls, providing multi-level permissions, instant notifications, and version control. Designers do not need to trouble themselves with hitting ‘Save’ each time they change something—Upverter automatically saves design changes in a Google Docs-style interface.
  • Customizable constraints. Upverter has an easy-to-use yet powerful constraint manager that allows users to customize DRC and DFM requirements. The constraint manager also reports violations in real-time so that you can fix errors before you send your board off for production. You can also prioritize rules, enabling you to manage multiple constraints targeting the same object. These constraints can then be examined in a final design review before you move to manufacturing.
  • 3D viewer. Upverter gives you a 3D preview of your layout directly in your browser.

constraints

Constraint Manager Upverter

With the online PCB CAD features in Upverter®, anyone has the ability to create custom projects from a unique browser-based design interface. The schematic design and PCB layout tools can help you take your design from start to finish and prepare for manufacturing. These standard design and production planning features are accessible from anywhere by multiple collaborators.

You can sign up for free and get access to the best browser-based PCB editor, schematic editor, and component database. Visit Upverter today to learn more.

Building a Thermal Camera: Part 1

Get Started with Altium Upverter, Sign Up Now

Upverter Expert - Building a Thermal Camera_ Part 1.jpg

I have a couple of upcoming projects where a thermal camera would be very handy. These days, there are some amazingly feature-rich and relatively low-cost thermal cameras that can plug into your phone available on the market. Many of those utilize FLIR’s Lepton sensors, which are quite affordable for thermal sensors. Simply buying a thermal camera is a little boring. It’s considerably more fun to build one yourself. The commercial thermal cameras I’ve seen using FLIR Lepton sensors don’t appear to be using the latest revision, the Lepton 3.5, which is ratiometric and of higher resolution, thus giving better range. I don’t necessarily need the ratiometric output or the higher maximum temperature for my applications, but the high resolution is definitely welcome. In this article, I will be discussing what a thermal camera is, and how to build one instead of settling for a ready-made commercial one. As with my other projects on this blog, we will be going through the process of making the project together. I find this approach more purposeful than me finishing the project on my own, then writing just the successful steps, as it allows us to learn from mistakes together, and in turn, to understand why the final component choices and design decisions are better than their counterparts.

What is a Thermal Camera

We’ve briefly discussed thermal cameras, but what about regular ones? A typical camera, like a digital SLR or the camera in your phone, has a sensor that is sensitive to visible light and also extends a bit into near infrared and ultraviolet. These cameras process the sensor signal using bandpass filters to block the infrared and ultraviolet, and then a bayer array to allow software to determine the red, green, and blue levels of each pixel. You can therefore modify a regular camera to see just infrared—which gives some very interesting pictures. Note that because the camera is now only seeing infrared, the picture is black and white and has no colour information.

IR ImageNear Infrared photo of green foliage, Source: Mark Harris

Thermal cameras can’t see visible light at all—they see infrared—but not the infrared your typical camera’s sensor can see. A thermal camera sees radiated heat, which consists of long wave infrared. If you’ve felt heat radiating from a hot surface, or sat in outdoor seating at a restaurant that has heat lamps, that heat is long wave infrared. A typical camera is sensitive to 800-900nm infrared, which is why you can see the infrared LED in your TV remote with your phone’s camera. Thermal cameras see 10,000-14,000nm wavelengths instead. This means they can’t use a regular CCD or CMOS sensor, and until recent decades, the sensors needed to be chilled to near absolute zero to have any sensitivity at all. The Microbolometer array that makes up the camera is sensitive to heat, so building a camera that can see temperatures lower than ambient was a challenge until recent decades.

Because thermal cameras, like the near-infrared camera, only see one band, or ‘color’, its output is also interpreted as black and white. That being said, the FLIR Lepton, and many other thermal cameras can apply false color to thermal images allowing a greater range of temperatures to be displayed to the user. Typically, you will see this effect as ‘cold’ colors such as blue being used for lower temperatures, and ‘warm’ colours such as orange, red, and white being used for higher temperatures.

What is a Thermal Camera Useful For?

Thermal cameras are widely used for military and security applications. Although this was their traditional market, dramatically lower costs in recent years now allow for a wider range of commercial uses. When you’re evaluating the first prototypes of your new circuit board, for example, a thermal camera can show you which components are hot, and reveal how well heat is dissipated through your board. If you’re dealing with many watts of thermal dissipation for amplifiers, radios, power supplies, or motor drivers, a thermal camera can help immensely. Furthermore, if you’re trying to reduce your circuit board size, a thermal camera will quickly show which areas are not dissipating heat, and therefore can be removed. On the other hand, if your board is running much hotter than expected, you can still use a thermal camera to quickly see which areas of the board are not removing heat as efficiently as you had planned. Even if you are not trying to optimise the thermal capabilities of your circuit board, a thermal camera can allow you to rapidly analyze which components are overheating or performing badly when stress testing a board. This can allow you to see that a MOSFET or inductor in a power supply might need to be changed out for something more efficient, for example. Ultimately, using a thermal camera can save a lot of time glueing temperature sensors or thermocouples to every component you think might get hot, and looking through graphs of the component performance under load.

Other Components for the Project

In addition to the FLIR Lepton 3.5 sensor, we’re going to need some other components so we can read and display the image. As far as projects go, building a thermal camera is quite simple if you use components that are a little expensive instead of trying to cut on costs.

Display

The FLIR Lepton 3.5 has a resolution of 160×120 pixels, which means we ideally want a display with that many pixels, and not a lot more. To make software development easier, it would be great not to have to deal with scaling the image. For my project, I want something fairly compact, so a big beautiful display that needs image scaling isn’t going to suit my requirements in any case.

A friend has been using a lot of cheap SPI displays featuring the ST7735S controller, which look really amazing in his devices. Given the price of displays using the ST7735S controller, it’s difficult to justify using anything else for a prototype.

On an online marketplace, I found a number of 1.8 inch 160×128 pixel displays, either on a breakout board or just the display. These will be perfect, as I can use the breakout board for testing, then integrate the display into a 3D printed enclosure to save space. These displays are also readily available at electronics prototyping/maker supply sites for similar prices, which are much easier to order from if you are in North America rather than the United Kingdom.

I generally don’t like buying displays and such from online marketplaces, as I’m never quite confident about what I’m getting. I’m only willing to take that risk for this project based on my friend’s good experience. The breakout board I have purchased claims to be an SPI display, but the pins are marked as SCL/SDA, which would make it I2C, yet it also has a chip select pin. During the next article in this series where we build the project on a breadboard, things could get interesting when trying to interface with the display!

Microcontroller

Now that the display and the sensor are defined, we have an idea of what sort of processor capabilities we might need. I’m only going to be building one or two of these cameras, so the cost of the microcontroller is mostly irrelevant compared to the cost of the thermal camera module. I’d really like to store the whole image frame in RAM without having to use external RAM on the microcontroller, so I’m looking for a controller that has enough RAM for a basic application, plus 128x160x24bits of memory – 491,520bits (62,440bytes) + application. This will allow me to do my own color scheme on the data if I want, or perform any transforms I want to add down the road. The x24bits is for the 8 bits per red, green and blue colour channels.

I’d like to use a microcontroller supported by both the microC Pro for ARM compiler and the online MBED compiler, as I’m not sure which I will use for this project yet. It would also be great if I already have the dev board for it, which means I’m looking at STM32 controllers, as the NXP LPC and Kinetis boards I have which are MBED compatible are not supported by microC Pro. STMicroelectronics tend to incorporate far more RAM and flash in their ARM Cortex controllers than anyone else, which is great for an application like this.

I’m using the STM32F413 as a starting point for another project on the blog, so let’s use that as the starting point for this project too. It’s got 320 kilobytes of RAM, which would allow me to double buffer the image and do all sorts of processing on it if I wanted to in the future. As the code written for the STM32F4 is compatible across the series, we can switch to a cheaper option after we have the firmware developed and have a clearer idea of the memory requirements. This is one thing I really like about STMicroelectronics ‘cheap dev boards’ philosophy: it allows very easy testing of multiple controllers for your project, typically at a lower cost than a single board from a competing vendor.

Thermal Camera Breakout

To save time making a PCB just to mount the thermal camera module on, I would really like to find a breakout board for the FLIR Lepton 3.5. A breakout board should have the multiple voltages the camera module requires taken care of, and just give me the signals I need. When the Lepton series was first released, it caused a lot of excitement and there were several breakout boards available. Sadly, it seems to be much harder to find one now.

I managed to find a breakout board in stock on Digi-Key, however it appears to be a last time buy item. Sparkfun and others, which sold breakout boards for the Lepton, no longer seem to stock them either, which is a bit disappointing. The breakout board predates the Lepton 3.5, however, after digging through the datasheets it appears that the entire Lepton series is pin compatible, just varying in the SPI command set as new capabilities and higher resolutions have been added. 

The most readily available dev board for the Lepton series at the time of writing is a very cool board that has an onboard STM32F4, which turns the thermal camera module into a USB webcam. As neat as this is, it’s not much use to me for building my own camera system using the Lepton on a breadboard!

Coming Up Next Time

Once the selected components are delivered, we’ll start evaluating them to ensure they are the right choice before commiting to a PCB using them. This will give us a high probability of success on the first revision of the circuit board, as well as confirm that each pin we used on the microcontroller is valid for our purposes. We’ll also get to the bottom of the interesting markings on the display board, and determine if it’s bright and clear enough for our little thermal camera.

You can sign up for free and get access to the best browser-based PCB editor, schematic editor, and component database. Visit Upverter today to learn more.

 

How to Choose a Voltage Regulator for Your PCB Design

Get Started with Altium Upverter, Sign Up Now

Upverter Expert - How to Choose a Voltage Regulator for Your PCB Design.jpg

Unless you are working with a purely AC system, your PCB will need to receive stable DC voltage to operate properly. A voltage regulator circuit provides the necessary DC voltage with fixed magnitude, even if the input voltage (line) or the output current (load) changes. Some circuits are more sensitive to voltage fluctuations than others, and some power lines are noisier than others. Any designer should understand how to choose the right voltage regulator for their board. Let’s take a look at the different types of DC regulators and go through some factors to consider when selecting a voltage regulator.

Types of Voltage Regulators

Voltage regulators are normally placed on the output from a full-wave rectifier circuit in order to remove the remaining ripple waveform. There is more than one way to classify a voltage regulator, but for the moment we will stick to linear and switching regulators. These regulators can be added to a layout relatively easily and provide reasonably stable output voltage for most applications.

Linear Regulators

Linear regulators use a BJT or FET to stabilize the supply voltage and are controlled with an amplifier. The amplifier compares the output voltage from the regulator to a precision reference and changes the transistor to maintain a constant output voltage. Linear regulators always step-down the output voltage (i.e., input voltage > output voltage). Linear regulators with low drop-out voltage are called low dropout regulators (LDO). Linear regulators provide the following advantages:

  • Low Noise: As there is no switching involved, these regulators generate low noise and are best used for powering sensitive circuits. In contrast, switching regulators are inherently noisy as they switch frequently in order to maintain the output voltage.
  • Low power: When properly designed, linear regulators can operate with quite low quiescent current. Switching regulators use complex feedback systems and end up using higher quiescent power. When operating as LDOs, these regulators can have very high efficiency (~90%).
  • Low cost: Linear regulators are less costly, and they are easy to add to a layout. They do not require too many components and filters. Usually, a capacitor is placed across the output to help regulate the output voltage.

linear-regExample linear regulator circuit

Switching Regulators

A switching regulator converts an input DC voltage to a more stable DC output with a power MOSFET or BJT switch. The output from a switching regulator is usually filtered and used to reduce switching noise on the output voltage. There are three types of switching regulators: buck (step-down), boost (step-up), and buck-boost (can provide step-up or step-down). Switching regulators provide the following advantages:

  • High efficiency: Since switching regulators work in either off or on mode, they tend to be more efficient. They can provide 90% or greater efficiency, which is very difficult in most linear regulators unless they are designed to as LDOs.
  • Step-up configuration: Linear regulators can only step down the input voltage, but a boost switching regulator can step-up the voltage. This is particularly useful in the case where a large voltage is required for a short period of time (e.g., the backlight in a camera).
  • Thermal performance: Linear regulators are less efficient, which means they tend to dissipate more heat and need a heat sink. Most switching regulators do not need heat sinks.

The buck and boost characteristics can be controlled with a PWM waveform, which makes this regulator ideal for use in applications where specific voltage levels are required. For example, you can use the PWM output from a microcontroller to power another circuit with a specific voltage level. There are many different ways to build a switching regulator IC, and we can’t possibly show every possible circuit. If you are interested in learning more about specific circuit layouts for switching regulators, take a look at the datasheets in your parts library.

Important parameters for choosing regulators

One question I often see on forums is how to choose a voltage regulator for different applications. There is no single answer to this question. You should consider the following characteristics when looking for a voltage regulator; note that these aspects apply to both linear and switching regulators:

Output voltage

If you need a step-up regulator, then you will have to use a switching regulator in boost configuration. If you are using multiple supplies in a system, typically one regulator is used for each supply. Regulators usually supply a fixed output voltage, although there are some regulators available on the market which you can use with some adjustable settings.

Efficiency vs. Noise

Switching regulators provide higher efficiency than linear regulators, but they generate more noise. Unnecessary electronic noise can interfere with other circuits when the regulator outputs high current. If you want your product to hit the market, it can be more difficult to receive EMC certification. If other circuits on your board are sensitive (e.g., purely analog components), then it’s better to choose a linear regulator.

Selecting a regulator with high power losses can make it almost impossible to meet efficiency goals. Linear regulators are less noisy, but they are very inefficient (except LDO), meaning some power gets converted to heat. If your regulator will run at high current, you should include heat sinks on the board. If you don’t have room on the board for a heat sink or if power dissipation is a concern, then a switching regulator might be a better option.

shutterstock_744239These 7805 linear voltage regulators from Fairchild include a heat sink on the back of the package.

Transient response

When output current changes quickly, there is a small spike at the output. The voltage regulator takes some time before it switches back to the same voltage. This is called a transient response. The transient response is usually a function of the output capacitance and load current. A fast transient response ensures that the regulator can deliver the required power. Check your component datasheets and look for the recommended bypass capacitor you should include on the regulator’s output.

Voltage Regulator Layout Considerations

Once you have chosen the right voltage regulator for your design, you’ll need to place it in the proper location on the board. In general, you will need one capacitor between output and ground, and one between the input and ground as close to the pins as possible. You should also carefully design traces so that they can carry the required current without overheating.

If you take a look at some of the open-source projects in Upverter’s™ project library, you’ll find some good examples of regulator layouts that you can use as a reference for your next project.

boost-reg-boardBoost converter control board from James Fotherby, created in Upverter.

A good layout tool makes it easy to design schematics for your board and capture it as an initial layout. Upverter® provides a huge library of reliable components that you can easily add to your schematic and layout, including a huge range of voltage regulators and much more. As a cloud-based tool, Upverter allows users to easily share their work, control revisions, and access their data from anywhere.

You can sign up for free and get access to the best browser-based PCB editor, schematic editor, and component database. Visit Upverter today to learn more.