Thursday, December 17, 2009

Microchip programming. It's a lot easier than you think ;)

Greetings all. This is my first post on Vortex Electrica and I hope it will be the first of many. Today I'm going to write about basic microchip (or microcontroller for you purists) operation and application. First of all allow me to define what a microcontroller is. A lot of you may know the terms microcontroller and microprocessor, but what exactly are the differences between these devices? They are different by the way. Both microcontrollers and microprocessors can be called microchips.

Basically, microprocessors are CPUs. They can process data. Whereas microcontrollers are a combination of CPU, memory, and peripherals in one device. Peripherals are devices that have other functions that allow for interfacing between the microcontroller and other devices, such as input/output pins, analog to digital converters, digital to analog converters, and etc. Memory can be RAM, ROM, EEPROM, and etc. In this post I'll be focusing on microcontrollers and what we can do with them. More specifically, I'll be posting about the 08M PICAXE chip which is a great chip for beginners.

Above is the PICAXE-08M package picture and pin descriptions. The first pin is always the topmost pin left of the notch. Referring to the above figure, we can see that the 08M requires a +5V power source, it has a serial input and output, 4 digital inputs, 4 digital outputs, 3 analog inputs, a PWM (pulse width modulation) output, an infrared input and output, a tune output, and a ground connection. However, not all of these functions can be used at once due to the restriction of pins. What can we do all these?

Digital inputs and outputs: Can be used for anything from turning on LEDs to controlling robots when used as outputs and can be used as switches or condition checkers as inputs. For input, a low (0) signal must be between 0-1.5V and a high (1) signal would be from 3.5-5V. The nominal voltages for output are 0V for a low signal and +5V for a high signal.

Analog inputs: These are ADCs or analog to digital converters. The range of voltage allowed for the analog signal is 0-5V. The ADCs in the 08M convert an analog signal to a digital signal with 8 bits. For example, 0V analog would be converted to 0000 0000 binary, 5V = 1111 1111 binary, and 2.5V would be approximately 1000 0000 binary. ADCs are useful to check signal strength, for example in sensors, and also for reading analog values which we may want to manipulate. For example, we could make a voltmeter using the ADC function.

PWM: PWM is pulse width modulation. A PWM signal is basically a square wave signal which can be asymmetrical, meaning it can have a longer on time than off time and vice versa. PWM signals are useful for control purposes. For example DC (direct current) motors speed can be controlled using PWM signals.

Infrared input and output: These are pretty self-explanatory. They are infrared ports which can be used for receiving and transmitting infrared signals. Using these the 08M can communicate with other devices using infrared signals. For example, we can use the 08M to create an infrared remote for TVs, DVD players and etc. Device commands for common Sony devices are even included in the 08M datasheet! On the other hand, we can use standard infrared remote controls to control the 08M. Imagine creating a remote controlled robot that can be controlled using a TV remote  ;)   Maybe I'll try building one myself in the future.

Tune output: When this pin is connected to a buzzer/piezoelectric speaker, we can make music using the 08M. Monophonic ringtone 3310 type music yet music nonetheless. The 08M datasheet has a great guide for making music and even has a musical keyboard reference for making your own tunes. The 08M also has four inbuilt tunes which are Happy Birthday, Jingle Bells, Silent Night and Rudolph the Red Nosed Reindeer.

So, how do we get started on using all these functions? First we have to construct a main board for the microcontroller as an interface for the microcontroller with sensors, leds, infrared leds, buzzers, and also to supply power to the microcontroller. Below is a typical 08M mainboard.

Shown above is the circuitry for the mainboard. You can design your own mainboard or order boards online from the PICAXE website. The website also contains excellent documentation with all the datasheets and information you need to get started. In my opinion, absolutely anyone can learn to use these PICAXE chips in a short time with diligence due to the simplicity of the systems.

Programming for the microchips: The microchips can be programmed easily using free software from the PICAXE website. The software programs the microchip using the BASIC language which is fairly straightforward and easy to learn. Most of the syntax is self-explanatory and simplified for easy use and application. Besides using the BASIC language, the microchips can also be programmed using flowcharts! You can't get more straightforward than that. All of the required information on programming can also be obtained from the PICAXE site. To show you a glimpse of how easy the programming is (some of us give up just at the thought of having to write a program) below are examples of using BASIC and a flowchart to turn a LED on and off at pin 4 with a pause (in milliseconds) of 1000ms and 500ms.

Even if you've never programmed a line of code in your life, that has to be pretty easy to understand right?

Programming the microchip: After creating the program, we need to program the microchip. The microchip has to be connected to the COM port or USB port using a COM port to serial input cable or USB to serial cable respectively. Then the programming software can be used to program the microchip. The microchip has to be turned on during programming. After programming, the microchip will instantly run the new program. It's as easy as that.

With that I conclude this post. I hope it has been as much fun reading as it has been for me writing this. More than that I hope that you have learned something and developed an interest in microcontrollers. You are all welcome to share anything you may want to here or on a forum that I am a member of for extended discussion.

helpful websites:
PICAXE website (They even have more advanced projects such as a fully functional net server!)
Student Portal Forum (Great new forum for academic engineering discussion)

Disclaimer: Some of the above material has been taken from an IEEE robotics workshop. I suggest any electric/electronics fan to look into the IEEE as the programs they conduct are extremely helpful in many ways.


  1. Alllllll right deathclaw! This is good stuff! Kite biar junior refer trus kt cni!

  2. Yeah,vortex electrica is with you once again yeah!!

  3. I need to compile a microcontroller program with microc 5.8.0 and it is giving a 'demo limit error. can anyone help? please reply to


Related Posts Plugin for WordPress, Blogger...