Week 9

Getting started with Embedded Programming

This weeks assignment was to read a microcontroller datasheet and program my board to do something using as many environments ..........

So before starting to program my board I have to do some background work ..... as I was on MAC so I need to install FTDI drivers to interface the board with the computer..... I followed this link to install the drivers..... So now I was all set to program the board..... I decided to program my board using Arduino IDE at first then move ahead with other platforms ....... as its community is very large and all sort of support can be found online.

ATTINY 44

To have a better understanding of the Microcontroller, best way is to go through its Data Sheet.

You can download Data Sheet from here.

Image

Image Ref : LINK

ATTINY 44 is a low power AVR 8 Bit RISC Based Microcontroller.

Overveiw from Datasheet
    >Program Memory Type      : Flash
    >Program Memory           : 4KB
    >CPU Speed                : 20 MIPS
    >RAM Bytes                : 256
    >DATA EEPROM Bytes        : 256
    >Digital Communication    : 1SPI , 1 I2C
    >Capture/ Compare / PWM Peripherals : 1 Input Capture, 1CCP, 4 PWM
    >Timers                   : 1 x 8bit, 1 x 16bit
    >Comparators              : 1
    >Temperature Range        : -40 to 85
    >Operating Voltage        : 1.8 to 5.5V
    >Pin Count                : 14  
Pin Description
    >VCC : Input Voltage
    >GND : Ground
    >RESET : Reset input. Low Level ( GND ) on this pin will reset the program.
    >Port B (PB3...PB0) : Port B is a 4-bit bi-directional I/O port with internal pull-up resistors (selected for each bit).
    >Port A (PA7...PA0) :Port A is a 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit).
    
Block Diagram
Image

Block diagram's are not as much important as understanding the pins, Block diagram is more of an internal thing, It explains how things are going on inside the Microcontroller, ATTINY 44 follow Harvard Architecture . It has seperate Buses and Memories for program and data.

Programming Pins

SCK(Serial Clock): Programming clock, generated by the In-System Programmer (Master)

(Master Out - Slave In ): Communication line from In-System Programmer (Master) to target AVR being programmed (Slave )

MISO( Master In - Slave Out ): Communication line from target AVR (Slave) to In- System Programmer (Master)

RST(Reset): To enable In-System Programming, the target AVR Reset must be kept active. To simplify this, the In-System Programmer should control the target AVR Reset

GND(Ground): Common Ground

VCC(+5V): +5V input      

Getting started with Arduino IDE

Before starting to program our board using Arduino IDE, we need to tell the software that we'll be using a thrid party hardware i.e AVR ATTINY 44/45 etc........ For this we need to go to the Board Manager and add additional boards.....

Steps to add additional boards

1. Go to Arduino Preferances and there in the text field add a link https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json then click ok

Image

2. Then go to the boards manager and install new board files as required

Image

3. Now goto tools then to Boards and select the Microcontroller which you are using, in my case it was attiny 44 with 20Mhz external clock and programmer as USBTINY.

Image

4. After this we need to burn the bootloader onto the chip, this step sets the fuses and flashes any previous configration over the chip.

Now, all set to write the program and dump it onto the chip

But before doing that we should always read the data sheet of the chip we are using ....... or atleast you should know the pin diagram of the chip you are using .....

Image

Programming

This weeks assignment was to program our board to make it do something ...... My board was having 2 Push buttons and one LED..... So I decided to program it in a way that pushing those 2 buttons would be changing the time period of the blinking of the LED.....

Image

1. It would be declaring the variables and configuring the pins as input outputs

Image
"A" Here is the initial delay of the LED Blinking.
In the Setup I have defined the nature of the Pins Pin 8 > Output Pin, Pin 2 & 3 > Input pin
                            

2. Now step 2 would be making the main code into the loop

  Image
This is the main loop of the program which would be running over and over.

In this main loop I am comparing the Digital State of the Pin 2 & 3, If Pin 2 is HIGH then the blink interval will increment with + 20ms
and maximun upto 5000ms(5seconds).

If Pin 3 is HIGH then the blink interval will decrement with -20ms and can reduce to minimum 100ms.

And at the end this delay paramter "A" is passed in the delay function which would be controlling the blinking with varied delay.

Note: I have used Pull down method for switches, i.e I have considered HIGH Input signal as button click. I have added a pull down resistor to
   make sure any floating voltage value does not reaches the Pin, otherwise the controller would consider it as a button click, Also it may be
   noted that while programming we need to check wether the pin state is HIGH or not, If I had used Pull Up approach then we would have been
   checking wether the pin state is LOW or not.

Now burning the code to the chip

For programming we need to connect the board using AVR ISP cable to FABISP Programmer, The connections are shown in the video below :

Here are the steps which you need to follow to program the board

Step 1 : Write the program which I have already done

Step 2 : Burn the bootloader*, which also I have done already

About Boot Loader

Boot Loader is basically OS ( Operating system ) for the micro controllers, Bootloaders are meant to enrich the capabilities of the microcontroller and provide access to the hardware features such as USB, USART, SPI, I2C etc. The first thing which is processed by the microcontroller when it is powered on is the Boot Loader, then the boot loader instructs the controller, from where to start executing instructions. Mostly the bootloader resides in the bottom most area of the ROM but there are some cases where the boot loader can be configured in the top.The starting and ending address of the bootloader in the ROM depends on the product. So it’s recommended to use the datasheet to collect the required information.

Step 3 : Go to Sketch Button over the tool bar and Click on Upload Using Programmer

Image

Points to be noted

1. We need to power the chip externally, in my case a used +5v from arduino

2. Orientation of AVR ISP header should be correct else the program wont burn

3. Setting which should be used while programming with FABISP

Image

Testing

Learning from data sheet

After going through the data sheet ...... I was able to understand the pin diagram of the controller.....well, it was a very long document ..... I got only information which would be of my use .... like, I went through some example C program along with pin description and I have also studied how to add an external oscillator.

Download Code Download All Files

Group work - Embedded Programming

This weeks assignment was to Compare different Architectures of Microcontrollers

All MCs use one of two basic design models: Harvard Architecture and von-Neumann architecture

Harvard architecture

The Harvard architecture is a computer architecture with physically separate storage and signal pathways for instructions and data. The term originated from the Harvard Mark I relay-based computer, which stored instructions on punched tape (24 bits wide) and data in electro-mechanical counters. These early machines had data storage entirely contained within the central processing unit, and provided no access to the instruction storage as data. Programs needed to be loaded by an operator; the processor could not initialize itself.

Today, most processors implement such separate signal pathways for performance reasons, but actually implement a modified Harvard architecture, so they can support tasks like loading a program from disk storage as data and then executing it.

Image

Memory
In a Harvard architecture, there is no need to make the two memories share characteristics. In particular, the word width, timing, implementation technology, and memory address structure can differ. In some systems, instructions for pre-programmed tasks can be stored in read-only memory while data memory generally requires read-write memory. In some systems, there is much more instruction memory than data memory so instruction addresses are wider than data addresses.

Applications and features of Harvard Architectures
The principal advantage of the pure Harvard architecture—simultaneous access to more than one memory system—has been reduced by modified Harvard processors using modern CPU cache systems. Relatively pure Harvard architecture machines are used mostly in applications where trade-offs, like the cost and power savings from omitting caches, outweigh the programming penalties from featuring distinct code and data address spaces. Digital signal processors (DSPs) generally execute small, highly optimized audio or video processing algorithms. They avoid caches because their behavior must be extremely reproducible. The difficulties of coping with multiple address spaces are of secondary concern to speed of execution. Consequently, some DSPs feature multiple data memories in distinct address spaces to facilitate SIMD and VLIW processing. Texas Instruments TMS320 C55x processors, for one example, feature multiple parallel data buses (two write, three read) and one instruction bus. Microcontrollers are characterized by having small amounts of program (flash memory) and data (SRAM) memory, and take advantage of the Harvard architecture to speed processing by concurrent instruction and data access. The separate storage means the program and data memories may feature different bit widths, for example using 16-bit wide instructions and 8-bit wide data. They also mean that instruction prefetch can be performed in parallel with other activities. Examples include the PIC by Microchip Technology, Inc. and the AVR by Atmel Corp (now part of Microchip Technology).

The speed aspect : A lot has been discussed about the Harvard architecture, but without the speed any architecture can’t be accepted. But in case of the Havard architecture the manufacturers have designed the architecture in such a way that it will be able to process the data with a much higher speed. Yes, all care has been taken so that the architecture can process data with a high speed.

By implementing the same formula the modern days CPU are being manufactured so that the new CPU can run with a much faster sped and can also process the data effectively. The concept of the CPU cache is also being implemented while designing the Harvard architecture.

Von Neumann Architecture

The von Neumann architecture, which is also known as the von Neumann model and Princeton architecture, is a computer architecture based on the 1945 description by the mathematician and physicist John von Neumann and others in the First Draft of a Report on the EDVAC. This describes a design architecture for an electronic digital computer with parts consisting of a processing unit containing an arithmetic logic unit and processor registers; a control unit containing an instruction register and program counter; a memory to store both data and instructions; external mass storage; and input and output mechanisms. The meaning has evolved to be any stored-program computer in which an instruction fetch and a data operation cannot occur at the same time because they share a common bus. This is referred to as the von Neumann bottleneck and often limits the performance of the system.

The design of a von Neumann architecture machine is simpler than that of a Harvard architecture machine, which is also a stored-program system but has one dedicated set of address and data buses for reading data from and writing data to memory, and another set of address and data buses for instruction fetching.

Image

Applications and features of Von Neumann Architecture
The Von Neuman architecture has got extensive application in everyday life. Keeping in mind the extensive application the Von Neuman architecture has been introduced as a subject in the engendering degree. From the third semester engineering students will have the subject as their curriculum. The Von Neuman architecture consists of some important features and here we will have a detailed elaboration to the features.

Memory: We all know that the Von Neuman is nothing but a computer having the feature of data storage. In the architecture of the Von Neuman the memory plays a vital role and it is considered as one of the important feature. Mainly this is responsible for both holding and starting of data and programming data. In modern days this has been replaced by the RAM and now we are using RAM for this purpose.

Control Unit: This unit is mainly responsible for the controlling aspect. All the data stored in the memory and during the processing of data the control unit plays the role and it manages the data flow. In fact, to be more typically it is “One At A Time”. The control unit follows the principle of the One At A Time and accordingly it process all the data.

Input– output: Like all electronics devices the Von Neuman architecture also has an input/output architecture. It is the basic function is same and nothing specially has been designed for the input and output architecture. With the Input and output device on a person can communicate with the device.

ALU: ALU or the Arithmetic Logic Unit has a great importance in the Von Neuman architecture. Any sort of addition, subtraction, multiplication and division of the data will be carried out by this ALU. In addition to that any other kind of algorithmic function and activities will be carried out by the ALU. These are the basic aspect of the Von Neuman architecture which you must aware of.

Difference between Harvard and Von Neumann Architecture
Harvard Arhitecture
1. The name is originated from “Harvard Mark I” a relay based old computer.

2. It required two memories for their instruction and data.

3. Design of Harvard architecture is complicated.

4. Harvard architecture is required separate bus for instruction and data.

5. Processor can complete an instruction in one cycle

6. Easier to pipeline, so high performance can be achieve.

7. Comparatively high cost.

Von Neumann Architecture
1. It is named after the mathematician and early computer scientist John Von Neumann.

2. It required only one memory for their instruction and data.

3. Design of the von Neumann architecture is simple.

4. Von Neumann architecture is required only one bus for instruction and data.

5. Processor needs two clock cycles to complete an instruction.

6. Low performance as compared to Harvard architecture.

7. It is cheaper.

Sources : ~Wiki, Microchip, edgefxkit

Let's go invent tomorrow

Rather than worrying about what happened yesterday

~Steve Jobs

Contact Me

I am happy to talk you through any projects or run live demos to see how they look like.

Top