Thursday 11 June 2015

Wireless remote controlled rocket launcher with Atmel and Arduino/Atmel source

Summary
The focus of this blog is to redesign a circa 1999 remote controlled model rocket launcher. While updating the controller design the main capability of remote launching will be retained since this is a handy feature for those capturing rocket launches on camera or video.

Throughout the blog the steps of the design are documented with screen captures along the way.

History
A garage door style remote, two button key chain transmitter, and receiver module were used for the remote control section. The receiver unit had a dedicated decoder, AX5885, which was monitored by a Motorola microcontroller (Freescale), 68HC705J1, which had the most difficult tasks of timing a buzzer and driving a MOSFET. A sealed lead acid battery provided the amps to fire the igniters (Estes parts preferred).


Original Rocket Launcher PCB circa 1999
Original Rocket Launcher PCB circa 1999

Evolution
Knowing that a quick replacement was required, with say an Arduino, the design was to take a three step approach.
  1. Produce a new test board with an Atmel micro and code in Atmel Studio. This would mean the rocket launches could continue within weeks! PCB Zone aka Circuit Labs have a quick turnaround on boards meaning the bare circuit board usually takes a week
  2. Following on from the first design would be an update with new features and some much needed safety
  3. Lastly ensure the design is friendly enough for those starting out with devices such as Arduino. This would mean porting the existing code.
Remote Control Selection
The first redesign of the launcher was always going to be a reprint of the original 1999 board with 2015 parts to return the launcher to operation. In saying that, addition a status LED for debugging and putting an on-board connector for the receiver antenna would be the only intended additions.

Beginning with the remote control, SparkFun had an ideal unit - RF Shield however the corresponding remote was out of stock, nothing at LittleBird either. So fallback was to the garage style remotes. The local supplier, Oatley Electronics, imports a 433MHz UHF 4 channel remote and with the transmitter and receiver on special, it was worth a try. Provision can be made in a later design for other receivers such as those from SparkFun or KitStop since the Oatley parts are many times the price.

What's in a Micro
There was no preference when looking for a replacement microcontroller. As other Australian bloggers such as Dave Jones from the EEVBlog tend to suggest, picking a device or hardware, having a play and making mistakes is a excellent way to learn.

For this redesign an 8 pin Atmel micro was selected to replace the previous controller. The Atmel parts are low power (uA) devices, have a stable enough internal oscillator for this task and are small enough to setup by an enthusiast.


ATtiny pinouts

Selecting a Atmel micro can appear baffling considering the many devices available on the Atmel website, however when the requirement to have Arduino support, this narrows the field drastically. Leah Buechley of High Low Tech has a page on her site dedicated to the ATtiny45 and 85 and its use with the Arduino platform. With an online community already then this micro is a perfect choice.

Basic Circuit Design
First up is the board operating voltage and associated regulator. There are a plethora of options here from linear to buck style switching regulators which would provide the 5V DC required for the board. A lower voltage was not a option based on the receiver selected, although the Taiwanese manufacturer, AutoMicro Technology, does state the receiver operates at 3V. Since there are a number of 5V low drop out linear regulators on the shelf, surface mount, an ON Semi linear regulator will be used.

Since the micro is using the internal oscillator there is no need to select an external crystal or similar device, however the micro will be kept as a DIP package to allow for off board programming.

Switching MOSFET's
This leaves the drive devices for the buzzer and igniters. Separate MOSFET's will be used to run the buzzer and igniter. 

Searching Digikey and Element14 for a small MOSFET signal device there are plenty to choose from. Main requirements to drive the buzzer, continuous drain current 50mA and the drain source voltage better than 30V. A device that is a surface mount (SOT23 style) is chosen which will easily run the buzzer and be used in another project.

Selecting a replacement for the original IRF540 follows the same process that was used for the smaller MOSFET with the added parameter of ON resistance. That is the MOSFET's drain to source resistance, for a specified gate to source voltage. 
The original part with a 25A drain current, had an ON resistance of 26milliohms. With newer technology, surface mount and less than three dollars this device can be upgraded to a IRFR7540 which has an ON resistance of 4milliohms. This device handles 90A for a drain to source of 60V, complete overkill or is it! 

Why the High Current MOSFET?
According to the ESTES data sheets, the resistance of the igniter is approximately 0.8 ohms (measured 0.7 ohms on Estes igniters). Since a sealed lead acid battery is being used and we can assume the battery is near 100% charged before use, this gives a voltage of about 12.6V DC. Applying Ohms law, 12.6V/0.8R gives almost 16 Amps. In reality there are additional system resistances due to cable cross section, terminals fittings, battery, MOSFET ON resistances and other factors that would reduce this value.

In addition it should be noted that the current mentioned above is steady state and this resistance does vary for other manufacturers igniters meaning the inrush current could certainly be higher. So choosing a MOSFET with the lowest ON resistance together with lowering the total system resistance presents the igniter with the ability to ignite correctly.

Schematic Drafting Package
From KiCad to Altium Designer there are CAD packages to suit the needs of most individuals. Additionally there are now web based community PCB tools from Altium such as Circuit Maker. These fill the gap between the novice and the experienced designer as well as providing valuable community support. This design will stay with the Altium flavour for that sole reason.

Schematic Drafting
This design will require a single A3 page due to its simplicity. This may be a sticklers mentality but A3 is the suggested industry page size however not a hard and fast rule.

Searching Digikey for an ATtiny85 (ATtiny45 would do the job also) throws up over fifty results. Narrowing the search to DIP reduced the results to two. At the time of checking, one device with a speed of 10MHz and the other 20MHz, the faster device was cheaper. So the ATtiny85-20PU can be added to the centre of the schematic straight from the Atmel libraries. In addition a small decoupling capacitor is added to the supply rail of the micro.

To make life a little easier for those who prefer to solder the micro directly into the board, rather than using a socket, an in-circuit programming header is included. Using the In System Programming (ISP) pinouts and then mapping these to the micro with net labels allows the programming header to be moved around the schematic easily, no fixed wiring. A pullup resistor is added to the reset line of the micro although the ATtiny can be configured to operate without this pin.


ATtiny Processor Connections
ATtiny Processor Connections

Next is the linear regulator which is protected from reverse power with a single diode. Again, for this design not too many bolts and braces. To avoid the loss in the diode a 15V, or higher voltage rated, Transorb and resettable fuse combination could have been used.
Linear Regulator Connections
Linear Regulator Connections

Additionally the V_BAT supply rail that will provide power to the MOSFET's is not reverse polarity protected. This is a must for the revised board, a few other blogs describe the reason - false ignition. Some of the usual fixes for this problem are to use a high current relay or an arming switch.

RX3302D Receiver Connections
RX3302D Receiver Connections

The receiver unit (RX3302) can be connected in a number of configurations, either using the receiver data output or the four digital outputs that correspond to the buttons on the remote control. The latter will suffice for this project.

A pushbutton and LED are connected to the Learn Acknowledge (LA) pin allowing replacement remotes to be programmed by holding down the pushbutton for a few seconds. The LED is switched OFF by the receiver itself when learning mode is completed or the active learning time expires.

The two output MOSFET sections look identical on the schematics, one device for driving the buzzer and the second for the igniter. On the updated design the output section will be modified to include protection and load monitoring. The addition of load monitoring is helpful for instances when there is no ignition and the rocket engine must be inspected.


MOSFET Output Devices
MOSFET Output Devices

Adding an LED for basic debugging and the schematic can be rule checked then annotated by the software.

Rocket Schematic
Rocket Schematic

PCB Drafting
The Printed Circuit Board (PCB) can be laid out without any size constraints although the smaller the board area, means usually lower the cost. Most PCB suppliers offer options to collate other people's boards to reduce costs. 

Rocket PCB (two layer)
Rocket PCB (two layer)


Rocket PCB in 3D
Rocket PCB in 3D

The PCB is laid out with the vertical receiver board running down one section of the launcher board, processor in the middle and connectors with high power switching on the opposite section of the board. 

On the reverse side of the board are the optional LED's, receiver learning push button and the receiver antenna connector. After a Design Rule Check (DRC) the PCB is ready to send for manufacture.

The PCB was produced with a black solder mask as shown below. In addition the design is also Open Source Hardware.

Manufactured Rocket PCB
Manufactured Rocket PCB

PCB Population
On complex PCB's it is common to populate the power supply section, verify its operation, then populate specific sections of the circuit. With such as small board the entire population is completed in one sitting.

After population of the components and cleaning of the solder flux the board is given a brief visual examination. Compared to the usual lighter colour green solder mask, the black makes inspection of the board a touch more difficult. 

Populated Rocket PCB
Populated Rocket PCB

With the PCB loaded there are some power up checks and voltage levels to confirm.

Power Up
Powering the populated launcher board for the first time, the power supply is set to 12V with a current limit 50mA. The current limit is deliberately set to 50mA in the event there are any problems with the board.

Power Up Test of Rocket PCB
Power Up Test of Rocket PCB

The current reading on the power supply of 12mA is acceptable and a check of the 5V linear regulator output voltage shows 5.001V, so the board looks in order and programming can begin.

As a matter of interest the power supply voltage was lowered until the regulator dropped out of regulation. The regulator drop off was at 6.3V as shown on the supply.

Atmel Studio
For the initial coding of the launcher a basic state based scheme will be used. Ideally a task based solution would be implemented, possibly in the next board iteration when some smarts are added to the board.

Using the circuit as a reference for connections to the ATtiny micro, the physical inputs and outputs can be defined with some meaningful labels in the code. Hash defines or constants are used to make the code more understandable, examples for both shown below.

Software IO Definitions in Atmel Studio
Software IO Definitions in Atmel Studio

For the ATtiny clock the internal oscillator will be used at a speed of 8Mhz divided by 8 using the internal divider. To determine the fuse configuration it's over to the datasheet or open Atmel Studio, connect to the ATtiny using a device such as a JTAGICE3. Using the Device Programming window under the Tools menu the config can be verified before adding the fuse values into the code. Hands down this is far easier than accidentally disabling the serial programming through an incorrect setting and having to resort to other methods such as high voltage programming to restore the ATtiny.

Atmel Studio Fuse Configuration
Atmel Studio Fuse Configuration

The fuses can be defined in code to make programming a little simpler. Values for the fuse settings are implemented directly as shown in the fuse configuration above.

Atmel Studio Software Fuse Setup
Atmel Studio Software Fuse Setup

Control of the outputs is made through a basic state machine of sorts. This has three states:

Software State Machine Values
Software State Machine Values

There is a single port on the ATtiny, port B 0 to 5. The appropriate bit operators are used with the logical shift to firstly set the state of outputs to zero, OFF. Next the data direction, DDRB, is configured to change default inputs to outputs.

Port Setup in Atmel Studio
Port Setup in Atmel Studio

Even though the data direction register defaults pins to inputs the launch and cancel signals to the ATiny from the remote transmitter are configured as inputs. 

Similarly the one second buzzer on startup at the end of the setup routine is not required but is a good indication the system is running.  

The state machine is a simple routine that waits for the Launch button press, turns on a buzzer for a set period, 10 seconds, and during that period checks for the Cancel button signal. At the end of the set the launch output, igniter, is activated for a set period, 2 seconds.

State Machine Routine in Atmel Studio
State Machine Routine in Atmel Studio

Improvements for the above routine in the next board revision would include mapping at least the Cancel button to an interrupt and using timers instead of a wasteful delay. [EDIT] Correction in image above, turning the buzzer off (PORTB &= ~Buzzer) moved.[EDIT]

Finally is the slim mainline that calls the port setup and then continuously executes the state control routine.

Mainline in Atmel Studio
Mainline in Atmel Studio

With the JTAGICE3 connected to the Launcher PCB, Atmel Studio code compiled and the ATtiny can be programmed.

Output Window in Atmel Studio
Output Window in Atmel Studio 

Two items of note are the program and data usage of the Atmel Studio build, 3.7% of program and 0.8% of data memory. This will be used for comparison against the Arduino build. Before proceeding with porting the Atmel Studio code to operate with Arduino some testing.


Testing
Operational testing is just confirm that the code behaves itself and when buttons are pressed the correct outputs turn ON. Everything checks out fine so it's time to perform some load test on the igniter output.

Initially with a small load of 100R and the power supply on 12V with a 3A current limit the output measures a little under 12V DC with the multimeter.

Connecting up 10R resistor to the igniter output and load testing shows that the MOSFET is not conducting fully. A meagre 0.25mA is measured by the power supply when the igniter output switch on whereas close to 1.2A is expected.

Connecting the CRO to the gate of the MOSFET during a load test the gate to source voltage (Vgs) is measured. The Vgs is around 3.6V which is above the minimum Vgs turn on threshold but not above the maximum of 3.7V. A quick change of the gate pull-down from 100k to 1M yields almost 5V during tests.


Capture - MOSFET Turn ON
Capture - MOSFET Turn ON

The image above shows the gate voltage on the yellow trace and the MOSFET drain to ground (GND). Note the upper horizontal cursor on the yellow trace shows the threshold Vgs(th) for the gate.

As final confirmation of output timing, the bottom image shows the MOSFET gate voltage on the yellow trace and drain to GND on the green trace, whilst the igniter output is activated.


Capture - Igniter Output Timing
 Capture - Igniter Output Timing

Operationally the launcher is working, now how about finally porting this to Arduino!

Arduino Port
First up the ATtiny must be added to the Arduino software. With the built-in Board Manager this is straightforward, see High-Low Tech page for details.

Next up the loading the boot-loader onto the ATtiny85 from Arduino can take some massaging of the USB drivers. After installing the Arduino software and following the steps on High-Low Tech there were still some issues with the AVRSIP mkII being recognised. The Arduino forums have some suggestions and following one thread that suggests a replacement driver, libusb-win32-bin-1.2.6.0.zip, from http://sourceforge.net/projects/libusb-win32 which worked perfectly.

Using the Arduino Burn Bootloader command the ATtiny is furnished with the boot-loader software.

After creating a new sketch the existing C from Atmel can be copied into Arduino. This will not compile as is so some minor changes are required. 

Starting with the includes from Atmel Studio, these are deleted from the Arduino sketch.

Arduino IO
Again here no preference for port IO naming. Arduino offers a convention which is port name then number, eg PB0, as defined in the Pins header file for the ATtiny.

Arduino IO Definitions
Arduino IO Definitions

The states machine and program variables remain unchanged.

Arduino State Machine Values
Arduino State Machine Values

In the Setup routine, same function name is kept, some of the statements are changed to use the Arduino direction and output types.

Arduino Port Setup
Arduino Port Setup

For the Atmel Studio project bit manipulation of the port and direction registers was implemented for setup, however Arduino adds another level of ease to this process using Digital writes and Pin modes, as shown above. Similarly the delay routine is renamed to simply delay.

Arduino Main Loop

The Arduino loop can be considered the equivalent of main for the Atmel Studio project. This main function only needs to be renamed to loop in this instance.

Lastly is the launch control where the bulk of the changes must be made.

Arduino State Machine
Arduino State Machine

The function name and variables remain unchanged for the state machine however the reads of the port pins use the Arduino digitalRead function and writes digitalWrite.

For comparison purposes, of memory usage, the ATtiny flash memory has been programmed with the Atmel Studio build and then downloaded as a HEX file for Atmel Studio. The Arduino software was used to burn the bootloader into the ATtiny and then the Arduino sketch was uploaded. By comparing the two HEX files it is easy to see the overhead that the Arduino platform. In the next release of the launcher a comparison without the bootloader will be made.

Up next some photos of the launcher as soon as the weather breaks...

Improvements
To improve the launcher design some of the following items will be considered for the second revision:
  1. Reverse Battery Protection: To prevent false launches when a MOSFET is used, when a engine is fitted and the battery is wired in reverse a high current diode with a low forward voltage will be added to the circuit
  2. Igniter Connected: In cases where the launch was cancelled or simply did not happen a load sense addition will be made to the circuit to show if the igniter is still connected
  3. Low Battery: A solution using a standalone comparator and LED can indicate that the battery has dropped below a defined threshold
  4. Alternative Transmitter and Receiver: Allow an alternative to the communications hardware used
  5. Improve User Interface: Allow for interfacing to an LCD to provide more information and control. Will require a new microcontroller for the additional features.
Design of the next revision in the Revision 2 post.

Downloads for the Project

Schematic
PCB Altium Viewer/Designer
Atmel Studio Project
Arduino Sketch
Atmel Studio Hex File
Arduino Hex file