Sunday, September 30, 2012

Arduino Due

Where to buy, download the software and find the specs -

Update 7: The RC Arduino projects will be compiled and tested on a wider range of boards including Mega (now that I have one), Teensy and Due when I receive it. Expect to see a new 'Tested On' Header appearing on posts shortly and a list of tested projects here.

Update 6: If you have not seen it yet, here is the picture of the Due as posted on the homepage. That chip is an impressive size. There is also a dedicated Due section of the Arduino forum with the latest updates on hardware, software, shield compatibility and libraries.

Official Arduino Due Forum -,87.0.html

Update 5: If your interested in what your Due or Teensy is doing under the hood I can confirm that the approach to viewing the assembly code outlined here works for both of the new boards, I will update the screen shots at some point, but the process remains the same -

And here is my Teensy3.0 with headers attached -

Additional pin pads from the reverse brought around to female headers glued to the main headers. I used Gorilla Glue to attached the outside set of headers, I did this before putting them anywhere near the Teensy. The glue has some very aggressive solvents which I did not want to risk damaging the board with.

Underside view showing the pads and single strand hook up wire used to hook them up to the headers.

Update 4: I am happy to be one of the lucky ones to have ordered a Due, the Arduino Store is now showing the Due as out of stock however a number of online retailers are now showing that they have or are expecting stock so there are still units out there if your looking.

Update 3: Official hardware information, and much more here -
Pin Mapping
Due Only Libraries

The Audio library in particular should be interesting as a reference for using DMA (Direct Memory Access) for high speed access to external storage.

Update 2: Software available for download here -

Update1: Arduino Due is out and available for purchase.
Disclaimer: The following links advertise the Arduino Due for sale they are provided for information purposes only, this is not an endorsement of any product or outlet nor is it in anyway a guarantee that these stores have devices available for shipment.

It looks as if detailed information on the Arduino Due is being held back until the boards are available for retail on October 22nd. I continue to monitor online retailers for pre orders but have not seen any yet.

The following links contain a selection of the information released so far -

Quick Comparison with current Arduinos and Teensy 3.0

Arduino UNO Arduino Mega Arduino Due Teensy 3.0
MCU ATMega 328 ATMega 2560 AT91SAM3X8E MK20DX128VLH5
Architecture 8 bit AVR 8 bit AVR 32 bit ARM Cortex M3 32 bit ARM Cortex M4 *
CPU Speed 16Mhz 16Mhz 84 Mhz 48 Mhz*
Flash Memory 32K 256K 512K 128K
RAM 2K 8K 96K 16K
EEPROM 1K 4K 250K 2K
Digital Pins 14 54 54 34
PWM Pins 6 15 16 10
Analog Inputs 6 16 12 14
DAC 0 0 2  0

* Teensy 3.0 supports overclocking to 94Mhz
* Teensy 3.0 is based on ARM M4 architecture which is based on the same M3 Architecture as the Due, but with added digital signal processing instructions.

 None of the projects on the RCArduino blog use the full power of an Arduino UNO, in fact the lap timer project is the largest and still only uses 10K of the 32K available on an UNO. If your a beginner, get an UNO. All of the online examples will work with an UNO, it can also be directly connected to a wide range of external devices with no additional circuitry. This does not apply to the Due.

The Due is a 3.3 volt device where as the current Arduino's are 5volts, this is not much of a problem, but a bigger issue is that the Due is very limited in the amount of current it can accept (sink) or generate (drive/source). A large number of projects that you can find online today will need additional circuitry to be run on an Arduino Due. If you are a beginner don't give yourself the additional headache of having to converting online examples to run on the Due, but don't take my word for it, here is a quote from one of the originators of the Arduino project -

starting from zero on the Due is not recommended.
Get the starter kit and learn on the Uno then when you're an expert consider the Due.

Quote taken from -,125444.msg960996.html#msg960996

It has also been confirmed by Massimo that the Arduino Due will not be compatible with the vast number of extension shields that have been developed for the older 5V Arduino Mega - this could be a great opportunity to pick up old stock shields at a lower price, they can always be converted to run on Due once you are familiar with the platform.

None of this is a negative, the Due is a very advanced high performance processor which has been added to the Arduino line up. However like anything high performance it needs to be treated a little more carefully. The Due will open up huge new range of applications that are simply not possible with the current generation Arduinos and one of its greatest strengths will be that you can learn the basics on a tough little Arduino UNO and then transfer exactly the same skill set to the super performance Arduino Due.

While details of the Arduino Due are being held back until the launch, the datasheet for the Atmel SAM3X8E microcontroller at the heart of the new Due is widely available.

One of the best references I have found is available in the link below however be aware that a major goal or the Arduino project is to sheild you from this level of complexity so for the vast majority of Arduino users the following document is irrelevant.

Rest assured that we will all still be using pinMode, digitalRead, digitalWrite and all of the major libraries on the new Arduino Due platform, however for anyone wanting to write performance orientated libraries for the new Arduino Due the following will be useful reading, for everyone else, please skip this link.

Some more accessible information here, I also have a Teensy 3.0 on its way to Dubai which gets a mention in this post -,88029.msg940049.html#new

Massimo Banzi of the Arduino team has been answering some questions relating to the Due on this Arduino forum thread -,113460.60.html

Update: with only four days until the Arduino Due is launched, my Teensy 3.0 has arrived in Dubai.
Like the Due, the Teensy is based on an ARM Processor core the Teensy actually uses a Cortex M4 core which has advantages for digital signal processing applications over the Cortex M3 core offered by the Arduino Due.

Teensy 3.0 ARM Cortex M4 Based Arduino Compatible.

Teensy - It really is very very small, here it is hiding in the top right of an Arduino UNO, its about the same size as the bare ATMega328 Chip on an Arduino UNO.

One thing about these new boards that will have immediate impact is the very low input and output currents compared to the current generation of boards. There are not many projects I can think of where a Teensy will be a slot in replacement for an Uno or a Mega without some additional circuitry to switch the 20ma current typically of an Arduino pin.

Over the coming days I will look at converting some of the existing RC Arduino projects to use the Teensy, it will be interesting to see how easily the software and especially the hardware conversion is.

Stay tuned

Duane B

Saturday, September 22, 2012

Algorithmic Music On Arduino

Original By Viznut Arduino Version

This is an interesting little project that can be built in minutes. It plays 13 different tunes all of which are generated from a single line of C code, the tunes are selected through four push buttons which have 16 possible combinations, including silence and two free slots for your own music.

The project also includes an 8 LED visualizer that is driven by the same line of code as the music.

About Algorithmic Music

The original tunes were produced by Viznut and by others in response to his original blog post here -

The original Arduino port was completed by Arduino Forum user Stimmer and can be found in this post -,74123.msg558213.html#msg558213

Arduino Forum user Zeni also has an interesting variation which allows the user to enter new algorithms at runtime, this can be seen in action in the forum topic above.

The RCArduino Version adds the ability to select the current algorithm and the 8 LED Visualiser.

The RCArduino Version code and schematic can be found below, if your interested in the theory behind the music or demoscene in general ( ) you can pick up the trail from Viznuts original video linked at the start of this post.

An application in Grain Synthesis ?
One area that would be interesting to apply these techniques is grain synthesis. Grain synthesis is based on repeating a simple grain of sound while adding additional grains, envelopes, oscillators or filters to make the sound more interesting. These operations can be computationally expensive and do not always produce interesting sound. The techniques used to generate the algorithmic music from a simple counter demonstrated by Viznut could also be applied to generating more interesting synthesis grains.

The best known example of an Arduino Grain Synthesizer is the Auduino, its incredible to see that all of the sound generated by an auduino is the result of overlaying just two triangle waveforms. In one of the videos linked below you will see the triangle waveforms interacting together with the rich sound that results.

Examples of built Auduino Synths can be found at the end of this post -

An interesting development of the grain synthesis would be to combine it with the realtime code upload work of Zeni, it should be possible to create grains that modulate and transform themselves to create a more interesting sound palette.

RCArduino Version - Based on original work of Viznut and original Arduino port of stimmer

// one-line algorithmic music
// see viznut's blog
// and

// ported to arduino by stimmer
// Audio out on pin 10

// Further ported to Interrupt based music generation with 4 button selection of upto 16 algorithms (or 15 + silence on no buttons pressed)
// by Duane B aka RCArduino
// Buttons are digital 8,9,10,11, music output is on digital 6
// Also added a four LED Visualiser on digital pins 2,3,4,5
// Update - LED Visalizer is now 8 bit using digital pins 2,3,4,5 and analog pins 0,1,2,3

#define SAMPLE_MAX (65535.0)
#define SAMPLE_FREQUENCY (8000.0)
#define TIMER1_FREQUENCY 2000000
#define UPDATE_RATE 8000

// by keeping t global we can use it to drive the visualiser as well
long t;

// iterate the grains and LFO


   case 0:
     OCR0A = 0;
   case 1:
     OCR0A = ((-t&4095)*(255&t*(t&t>>13))>>12)+(127&t*(234&t>>8&t>>3)>>(3&t>>14)); // by tejeez
   case 2:
     OCR0A = t*(t>>11&t>>8&123&t>>3); // by tejeez
   case 3:
     OCR0A = t*((t>>9|t>>13)&25&t>>6);   // by visy
   case 4:
     OCR0A = (t*(t>>5|t>>8))>>(t>>16);   // by tejeez

   case 5:
     OCR0A = ((t*(t>>8|t>>9)&46&t>>8))^(t&t>>13|t>>6); // by xpansive
   case 6:
     OCR0A = ((t&4096)?((t*(t^t%255)|(t>>4))>>1):(t>>3)|((t&8192)?t<<2:t)); // by skurk (raer's version)
   case 7:
     OCR0A = (t>>7|t|t>>6)*10+4*(t&t>>13|t>>6); // by viznut, xpansive, varjohukka
   case 8:
     OCR0A = t*5&(t>>7)|t*3&(t*4>>10); // by miiro

   case 9:
     OCR0A = (t|(t>>9|t>>7))*t&(t>>11|t>>9); // by red
   case 10:
     long v;
     OCR0A = v=(v>>1)+(v>>4)+t*(((t>>16)|(t>>6))&(69&(t>>9))); // by pyryp
   case 11:
     OCR0A = (t>>6|t|t>>(t>>16))*10+((t>>11)&7);  //by viznut
   case 12:
     OCR0A = (t*(4|7&t>>13)>>((~t>>11)&1)&128) + ((t)*(t>>11&t>>13)*((~t>>9)&3)&127); // by stimmer

   case 13:
     // free to use
   case 14:
     // free to use
   case 15:
     // free to use
     // any more and we need another bit from PORTB

void setup()
  TCCR1A=0x0;          // set the timer prescaler to 8 = 16/8 = 2MHz
  TCCR1B=0x02;          // set the timer prescaler to 8 = 16/8 = 2MHz
  TIMSK1 |= (1<<OCIE1A);   // Enable output compare match interrupt on OCR1A
  //TCCR0A=0B10110011;                                    //-8 bit audio PWM
  TCCR0A=0B10000011;                                    //-8 bit audio PWM
  //TCCR0A=0x83;          // Set timer waveform generation mode to FAST PWM, clear OC0A On match, set at bottom - OC0A = digital pin 6.
  TCCR0B=0x01;          // Set to clock frequency, no prescaler
  OCR0A=127;            // set in the middle - do we need this ? probably not.
  DDRD|=1<<6;          // Set digital pin 6 to output - channels 2 and 3

  DDRB &= (~15); // set digital pins 8,9,10,11 as inputs
  DDRD |= ((1<<2) | (1<<3) | (1<<4) | (1<<5)); // set digital pins 2,3,4,5 as outputs for the visualiser
  DDRC &= (15);

void loop()
 unsigned char output = OCR0A;

 // clear visualiser bits on portD
 PORTD &= 0B000011;

 // set the portd part of the visualiser using the top 4bits of output
 PORTD |= ((output>>4)<<2);

 // set the portc part of the visualiser using the bottom 4 bits of output
 PORTC &= 0B110000;
 PORTC |= (output & B1111);

For a simple amplifier circuit to use with Arduino projects see here -

I am currently working on an Arduino based modular synthesizer with a very different sound, stay tuned

Duane B.

Wednesday, September 19, 2012

Lap Timer Build Along Part 3 - Timer Based Transponder

This post continues the RCArduino Lap Timer Build Along Series.

Previous steps can be found here -

Initial build along and videos -

Introduction to the timer based transponder and the required parts list -

Here are two quick demos of the system in action at the Pro RC Track in Dubai, the first shows the bread board build along lap timer and an enclosed stripboard version. The second video shows external audio enabled for lap time countdowns and fastest lap/not fastest lap indicator tones.

Transponder Overview
The transponder works by generating a simple infrared signal very similar to the one your TV Remote generates. This is an established technique which is widely used at RC Tracks, kart tracks and even automobile race tracks. If your track has an existing IR Transponder you can use the existing signal and do not need to build your own transponder. Part 4 will show you how to do this.

If you plan to build your own transponder read on.

The transponder can be powered in one of two ways -

1) Using dedicated power - If you are using the transponder in an automobile or kart, you can use a 9 Volt battery or 4 AA batteries to power the circuit directly.

2) Using buffered/shared power - The 555 Timer is a notoriously noisy component, if you intent to share power with any sensitive equipment such as an RC Receiver, you will need to buffer the shared power from the 555 timer. A cheap and effective solution is to use a 7805 voltage regulator, the final stages of this post show how to add this component.

RC Car Power
The transponder design has been extensively tested in many cars at the ProRC Track in Dubai. The transponder can easily be connected to the balance plug of a LIPO battery using a 3 pin section of PCB Header or a male balance plug if you have one. When sharing power in this way it is important to use the 7805 regulator circuit to prevent interference with the models RC Systems.

One of the test cars - The current m-chassis lap record holder at the Pro RC Track - lots of carbon, anodized aluminium and threaded oil shocks all around.

If you are not using shared power you will not need to complete the final few steps of the build (stop at step10) however if you expect to share power with any sensitive equipment at some point in the future it is worth including these steps.

How does the transponder work ?

The transponder uses the same technique and components as your TV Remote - an Infra Red light emitting diode is switched on and off 38,000 times per second, this is our carrier frequency. The carrier is generated by one of the 555 timers however in order to transmit a signal or data we need to alter the carrier in some way. The transponder uses a very simple signal - a pulse of 500 microseconds, this is generated by the second timer which simply switches the first timer on and off.

In the final part of the build series we will add the IR Detector to our Arduino circuit, the IR Detector is tuned to the 38Khz signal of the transponder. Remember we are using two timers ? One to generate the 38Khz signal and another to pulse it at 1Khz ? This provides a very simple encoding which allows us to look for pulses 500us long and know that we are receiving transponder signals rather than reflected sunlight, TV Remote signals or signals from other track side transponders.

Some Alternative Transponders

The job of the transponder is to 1) Switch the diode on and off at a frequency of 38,000 times a second. 2) To enable and disable 1) At a frequency of 1,000 times a second. 

In order to do this we use two connected 555 timers, the first generates the 38Khz signal and the second one enables and disables this signal at the much lower frequency of 1Khz. 

The transponder circuit can be replaced with any simple circuit capable of generating two fixed frequency square waves. 

Options include microcontrollers, NAND oscillators, op-amp oscillators - anything that can generate a squarewave.

Building The 555 Timer Transponder - Before and After
The transponder can be built on a piece of strip board 16 holes wide by 14 deep. To make sure that this is the final size of you board, remember that the rows and columns you cut will be unusable, you need 16*14 inside the cut area.

The copper strips should be running from left to right across your board - this is the orientation used throughout the build.
The Schematic
The circuit is reasonably simple with only 11 components required for pit wall use and an additional four if you plan to use the circuit in an RC vehicle.

Due to the angle in some of the pictures, its useful to double check your component placement against the schematic, also have a look at pictures from later stages for a cross reference.
1) Placing The 555 Timers
 Place the two timers with the notch facing the top of your circuit. Leave four rows of space above the top timer, one row between the top and the bottom and you should be left with one more empty row below the second timer.

The timers should be placed with six free columns on either side. See the picture for reference.

Important: The copper tracks on your strip board should be running from left to right confirm this before soldering.

2) Add Decoupling Capacitors
Add a 0.1uf ceramic capacitor as a decoupling capacitor across pins 1 and 8 (top left and top right) of each 555 Timer. I have soldered mine directly to pins 1 and 8 to save space.

 3) Add Positive Power
Add the connections to positive power.

When we add the 7805 regulator in a later step, the third row (counting from the top) will be our 5 volt power supply rail. Connect this to PIN 8 (top right) of both 555 Timers.

In this case I am using orange wire for the connections to the 5 volt power rail.

At this point we can also connect PIN 4 (bottom right) of the top 555 Timer to 5 volts. This is the reset pin, it is active low, so by connecting it to +5volts we ensure that the timer is never reset.
4.1) Add Ground Connections
4.2) Add Timing Resistors
Two steps in one here -
1) Add ground connections. Pin 1 (top left) of each 555 timer needs to be connected to the ground power rail. When we add the 7805 regulator, the second row (counting from the top) will be ground, connect this row to Pin 1 of each timer, I have used brown wire for this connection in the picture.

2) Timing resistors -
Now we add the first of our timing components. In order from top to bottom we add a 1K resistor (brown,black,red) from the 5volt power rail (third row down) to pin 7 of the top 555 Timer. Next we add a 10K resistor (brown, black, orange) from the same pin 7 to the row which we left free between the two 555 timers. The final resistor is a 1K (brown, black, red) resistor connected from pin 7 of the bottom 555 timer to the very bottom row of our board.

5) Add Timing Resistors Continued
Next we need to add two more resistors to the second timer.

Connect a 220 resistor (red, red, brown) from pin 8 to pin 7 of the lower 555 timer.

Connect a 680 resistor (blue, green, brown) from pin 7 to pin 7. Yes, thats right from pin 7 to 7, its the blue resistor in the picture and for it to have any effect we need to cut the copper track beneath the resistor. Its also a good opportunity to mention that we need to cut the tracks which would otherwise connect the 555 timer pins left to right. Refer to the picture later in the post.

6.1) Add Timing Capacitors
6.2) Add Timing Connections
Add the 1uf electrolytic capacitor (big black can) between pins 2 and 1 of the top 555 timer. Note that these capacitors are directional, there is a strip with a minus sign printed on it which indicates which side should connect to ground (pin 1) in the picture the strip is facing away from the camera. The other side is connected to pin 2.

Next we connect the 0.01uf ceramic capacitor between pins 1 and 2 of the lower timer. This capacitor is not directional.

Finally we need to add connections between pin 2 and 6 (trigger and threshold) of the timers. In the picture I have used yellow wire for this, it would have been possible to route the wire directly across the chips from pin 2 to 6 however in this case I have chosen to route two wires, one down from pin 6 to the empty row immediately below the chip and one back up from from the empty row to pin 2. Repeat this for each of the two timers.

Electrolytic Capacitor Orientation
Larger value capacitors tend to be available as electrolytic capacitors, these have an appearance something like a can. Electrolytic capacitors are directional, to ensure that they are correctly placed, the cans have a band marked with a minus sign to indicate the side/pin which should be connected to ground.

7) Connect The Timers Together
 This one is easy. We want to connect the output of the first timer (top) to the enable of the second timer (bottom).

This allows the top timer which is running at 1000hz to switch the bottom timer on and off to generate our coded 38Khz signal.

This connection is shown by the white wire connecting pin 3 (output) of the top timer to pin 4 (reset) of the bottom timer.
8) LED Current Limiting Resistor
As with any LED we need to limit the current passing through our infra red LED. As we are pulsing the LED it is only on for very short durations and so we have the option of passing more current through it. In this case I am using a 100 Ohm resistor (brown, black, brown) to limit the current to 50 milli amps, you could use a lower resistor for more power which would give a greater lap detection distance however on a narrow RC Track which loops back on itself a 100 Ohm resistor is perfect.

The 100 Ohm resistor is connected from pin 3 (output) of the lower 555 timer to pin 1 (ground). In the next step we will add the LED and cut the track between pin 3 and the resistor.

9) Double Check
Its a good time to double check progress. Here is the circuit constructed so far shown from the left side, double check yours against this and the previous images.

10) Add The IR LED
Not a great picture, but its an easy step.

Like all LEDs, the infra red ones are directional. This means the LED will only light if connected the correct way. As we cannot see infra red, its worth a little extra explanation to make sure we get this part right.

Most LEDs have on leg which is longer than the other, the long one should be connected to the positive (closest to the chip) and the short to negative (the path to ground is provided by the 100 Ohm resistor). However I have recently bought a batch of LEDs where the legs were cut incorrectly. To double check you LED placement, look at the inside of the LED you should see to metal plates which are roughly triangular. The smaller of the two plates is the positive side of the LED and should be connected nearest to pin 3 of the bottom timer. The other leg should be connect next to the 100 Ohm resistor where it joins the same row as pin 3. You will need to leave at least one spare hole in the board between the LED legs, you will need to bend one of the legs into an S/Z shape to do this.

As both ends of the LED are connected through the strip of copper running from the resistor to pin 3, we need to cut the copper strip to force the electricity to pass through the LED. Cut the track in the spare hole you left between the two LED Legs - refer to the underside picture for reference.

Almost Finished !
The original transponder design is finished here and if you intend to use the transponder for motor racing or kart racing, just add a positive power connection to row 3 (third row down counting from the top and linked to the orange positive power wires) and a ground connection to row 2 (second row down connected to the brown ground wires).

Add a 9 volt battery or even better 4 AA Batteries and go racing !

If you intend to use the transponder in an RC Vehicle and want to share the RC Power you will need to buffer your RC Receiver from the switching noise generated by the 555 timer. The most effective way I have found to do this is by using a 7805 regulator.

11) Adding The Regulator
The 7805 regulator prevents the switching noise in the transponder circuit from being transmitted through the power circuit and into your RC Receiver.

For the regulator to function it also needs two capacitors as supporting components which we will add in a later step.

For now place the 7805 regulator in the 10th hole counting from left to right. The regulator should be orientated so that the heat sink is on the right side of the circuit and the legs point down towards the 555 timers.

You might want to cut the heat sink off the 555 timer, this makes it easier to mount in your cars window, do this before soldering so that you do not damage the circuit while cutting.

13.1) Add The Capacitors
13.2) A Diode
13.3) Power Connection
Lets do this in the order in which power enters our circuit.

1) Solder your positive power wire ( the red wire) to the very top row of the circuit, is the top left most hole.

2) Solder your ground (black wire) connection to the second row, if we have followed the steps correctly this should also be the same row as the middle pin of the 7805 regulator.

3) Connect a 0.1uf decoupling capacitor between the positive and negative power rails, in the picture you can see that I added mine to the left of the wires, you can add yours to the right as long as its immediately next to the incoming power connections.

4) Add a diode. Diodes are directional components, they only conduct electricity in the one direction, the direction is indicated by a band printed on the diode. In the picture the silver band indicates the direction in which electricity is allowed to flow. The band is facing the 7805 regulator meaning that electricity can flow into our circuit but if electricity is connected in the reverse direction the diode will prevent it from flowing and damaging our circuit.

The diode is connected to the positive power track at the top left of our circuit, once we cut the copper track underneath the diode the electricity will have to travel through the diode to reach our circuit. If we accidentally connect power in the wrong way, the diode will prevent damage to the rest of the circuit from the reverse power.

5) Add the 7805 Supporting capacitors. In order to regulate the power to our circuit, the 7805 requires some additional external components, in this case we are using two 100uf electrolytic capacitors. Like all electrolytic capacitors these are directional components, a band on the capacitor indicates the side which should be connected to ground. The middle pin of the 7805 is the ground, it should be soldered in the second track down on our board which will be the ground rail. The outer pins are the input power supply and the 5volt regulated output, each of these should be connected to the center ground pin through one of the 100uf Capacitors - make sure that the band indicating the negative side of each capacitor is connected to the center ground pin of the 7805.

Final Steps
Our final step is to cut the copper tracks under the 555 timers so that the left and right pins are not shorted together, a 3mm drill bit will do this nicely.

Final checks and trouble shooting -
1) The copper tracks on the underside of the circuit should be cut in the following locations -

In the picture the copper tracks are running from left to right across the underneath of the board. The red marks indicate where a track should be cut, in order from top to bottom these points are -

Diode - We need to cut the track directly underneath the diode in the top left of the circuit, this will force the electricity through the diode ensuring that if we connect power the wrong way around, no electricity will flow and no damage will occur.

555 Timers - We need to cut the tracks between the left and right pins or the two timers, this means 4 cuts on the first time and four on the bottom so that the pins are not shorted by the copper tracks.

680 Ohm Resistor - This resistor is connected to pin 7 of the second (lower) 555 timer and runs horizontally along the board. As this is the same direction as the copper tracks under the board, we need to cut the track under the resistor otherwise the electricity will by pass it through the copper track.

IR LED - This component is also connected horizontally across the board. In order for the electricity to pass through the LED we need to cut the track between its two legs, in the picture the cut is marked one hole to the left of where the positive leg of the LED is soldered next to pin 3 (output) of the lower 555 timer.

2) Confirm that all of the components are correctly orientated.

3) Test the circuit - in order to test the circuit we need an IR Detector, a simple test circuit is provided in the following link, if you can light the red LED with the signal from your transponder, well done you have a working transponder.

Additional References -

NE 555 Datasheet with pinout

7805 Regulator Datasheet

Next time - Adding the IR Detector to our lap timer circuit.

Bonus Step -

As an optional step you might want to consider adding the amplifier circuit shown here -

The external audio mode can be switched on and off through the lap timer menu for extra volume when you need it. The new lap time countdown mode that you can hear in the video can also be switched on and off through the system menu.

External Audio and best lap time countdown demo -

 Stay tuned ...

Duane B

Sunday, September 9, 2012

How To View Arduino and Arduino Due Assembly

It is sometimes useful to be able to view the code that your Arduino has to execute, for example the two lines of C code A++; and B++; could result in code that is upto 6 times longer when A is a global integer and B is a local byte.

This approach has been confirmed to work with Arduino Due code also - some of the file and directory names will be different, see the screen shot at the end of the post - follow these steps to easily get the assembly output.

Step By Step Guide To Viewing Arduino Assembler

Here is a simple set of steps you can use to view your source code and the corresponding assembly generated by the compiler -

1) Turn on verbose output
Start the Arduino editor and from the File menu select Preferences to display the screen shown below. Find and select the option to 'Show verbose output during;' and tick the 'compilation' check box.

With this option selected, the Editor will show a trace of each step of the compilation process, it does not change anything within the process, it just displays the commands that the IDE issues to compile and upload your sketch. This can be useful to know especially if you would like to try alternative editors or you are having problems uploading to a new target.

2) Compile your sketch
As the sketch compiles, you should see the output window at the bottom of the editor filling up with a series of commands being issued by the editor. Once the process has completed and the status bar shows 'Done Uploading' your sketch has been successfully compiled.

3) Find the ELF file
One of the last commands displayed in the output window will be avr-objcopy targetting a .elf file for your sketch. Find this command in your output window, select and copy the whole command.

The quickest way to do this is to use the mouse to highlight the line and then use the keyboard short cut for copy 'CTRL C' on windows machines.

If you are using an ARM Based Arduino (Arduino Due), the structure will be the same with some difference in the command lines - the procedure is the same so read on.

4) Open a command prompt.
Open a command prompt. In windows you can simply type cmd into start/run. With the command prompt open, paste the command we copied in 3 into the command prompt - we will edit this command in the next step so do not run it yet. If you are struggling to paste the command line, you can try the keyboard short cut 'CTRL V' or right click and access the Paste option from the context menu or you can also access Paste from the Edit section of window menu accessed through the icon in the top left of the window.

5) Replace avr-objcopy with avr-objdump
The command is formed in three parts, the command itself, one or more options and then finally the target file. The target file is correct, but we need to change the command and replace the options. To change the command, move the cursor back to the command avr-objcopy and change it to read avr-objdump, this is the program that is able to generate a file containing our original source code combined with the corresponding assembly code generated by the compiler.

6) Replace the options
Because we have changed the program we are running against our target file, we must also change the options. To do this remove everything between the end of the obj-dump command and the start of the path to our target file and replace this with -S.

In the case of my example sketch -

Change this:
C:\arduino-1.0-windows\arduino-1.0\hardware\tools\avr\bin\avr-objcopy -O ihex -R .eeprom C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build8468877697114637985.tmp\RCChannelsL293D.cpp.elf

To this: (changes in bold)
C:\arduino-1.0-windows\arduino-1.0\hardware\tools\avr\bin\avr-objdump -S C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build8468877697114637985.tmp\RCChannelsL293D.cpp.elf

On Arduino DUE

Change this:
C:\arduino-1.5.1r2/hardware/tools/g++_arm_none_eabi/bin/arm-none-eabi-objcopy -O binary C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build5072018496906827174.tmp/sketch_nov21a.cpp.elf

To This 

C:\arduino-1.5.1r2/hardware/tools/g++_arm_none_eabi/bin/arm-none-eabi-objdump -S C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build5072018496906827174.tmp/sketch_nov21a.cpp.elf

7) Add an output file
If we run the command at this point the output will go to the screen, its far more useful for us to have the output sent to a file. We can use the file to compare the effect of any future changes or just to open in an editor for easier reading. To do this we add the redirect symbol and a file name, this will redirect the output from the screen to the filename we provide. In the case of windows, the final command will appear as follows -

Additions in bold

C:\arduino-1.0-windows\arduino-1.0\hardware\tools\avr\bin\avr-objdump -S C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build8468877697114637985.tmp\RCChannelsL293D.cpp.elf > RCChannels.dmp

While it may look like a lot of steps, if we show the end result, its actually very simple -

All changes from original text supplied by the Arduino editor are highlighted in bold

C:\arduino-1.0-windows\arduino-1.0\hardware\tools\avr\bin\avr-objdump -S C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build8468877697114637985.tmp\RCChannelsL293D.cpp.elf > RCChannels.dmp

Arduino Due Example (different sketch, same process)

C:\arduino-1.5.1r2/hardware/tools/g++_arm_none_eabi/bin/arm-none-eabi-objcopy -O binary C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build5072018496906827174.tmp/sketch_nov21a.cpp.elf > MyDumpFile.txt

We can now open RCChannels.dmp in our chosen editor to view the assembly generated by each line of our source code. You should see your original source code and a line by line dump of the corresponding assembler.

A Small section of the RCChannelsL293D sketch showing C Code and resulting assembly code generated by the compiler -

void readSettingsFromEEPROM()
  unSteeringMin = readChannelSetting(EEPROM_INDEX_STEERING_MIN);
     26e:    80 e0           ldi    r24, 0x00    ; 0
     270:    0e 94 ac 00     call    0x158    ; 0x158 <_Z18readChannelSettingh>
     274:    90 93 11 01     sts    0x0111, r25
     278:    80 93 10 01     sts    0x0110, r24
  if(unSteeringMin < RC_MIN || unSteeringMin > RC_NEUTRAL)
     27c:    88 5e           subi    r24, 0xE8    ; 232
     27e:    93 40           sbci    r25, 0x03    ; 3
     280:    85 5f           subi    r24, 0xF5    ; 245
     282:    91 40           sbci    r25, 0x01    ; 1
     284:    30 f0           brcs    .+12         ; 0x292 <_Z22readSettingsFromEEPROMv+0x24>
    unSteeringMin = RC_MIN;
     286:    88 ee           ldi    r24, 0xE8    ; 232
     288:    93 e0           ldi    r25, 0x03    ; 3
     28a:    90 93 11 01     sts    0x0111, r25
     28e:    80 93 10 01     sts    0x0110, r24
     292:    60 91 10 01     lds    r22, 0x0110
     296:    70 91 11 01     lds    r23, 0x0111
     29a:    8f ed           ldi    r24, 0xDF    ; 223
     29c:    91 e0           ldi    r25, 0x01    ; 1
     29e:    4a e0           ldi    r20, 0x0A    ; 10
     2a0:    50 e0           ldi    r21, 0x00    ; 0
     2a2:    0e 94 be 0a     call    0x157c    ; 0x157c <_ZN5Print7printlnEji>


If you really want to know what each line is doing you can refer to the AVR Instruction set -

In general I find a scan through the assembly is useful when checking out what library functions are being included and what they are doing. It also interesting to see how the compiler is optimizing your C code, you will often find code within functions can be reordered, whole functions will be inlined and you may even find one or two sections of code will optimized away completely.

The end result for me is that I tend to focus on writting C code that is as readable and maintainable as possible and that I am happy to let the compiler do the optimizing.

For those rare cases where you really do need to save every last 0.0000000625 of a second ATMEL produce some guidelines on constructing your C code for best performance -

As most 8-bit micro controllers operate in a similar manner, you can also refer to any embedded system optimization techniques and general C/C++ optimization techniques.

In a later post I will cover a few of the techniques which I have used to optimize the Illutron B Synthesizer code.

Stay Tuned
    Duane B