9. Embedded programming¶
Assignment¶
- Read a microcontroller datasheet.
- Program our board to do something, with as many different programming languages and programming environments as possible.
Attiny¶
ATtiny (also known as TinyAVR) are a subfamily of the popular 8-bit AVR microcontrollers, which typically has fewer features, fewer I/O pins, and less memory than other AVR series chips. The first members of this family were released in 1999 by Atmel (later acquired by Microchip Technology in 2016). ATtiny microcontrollers specifically exclude various common features, such as USB peripheral, DMA controller, a crypto engine, or an external memory bus.
Datasheet¶
- The microcontroller datasheet is the Atmel 8-bit AVR (R) family, that includes the Attiny 24A, Attiny 44A and the Attiny 84A chips. They are included in the same Datasheet, as they are closely related.
- First, I got to know about the features of the chip family. Here we can find information about the performance, architecture, features, voltage of operation, speed of operation at diferent crystal/resonators frecuency and voltages, temperature of operation and power consumption, among few others.
- Then the important part was to know the pin configurations of the microcontroller.
PinOut
Pins description
VCC - Supply Voltage
GND - Ground
Port B(PB3:PB0)
Port B is a 4-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port B output buffers have symmetrical drive characteristics with both high sink and source
capability except PB3 which has the RESET capability. To use pin PB3 as an I/O pin, instead of
RESET pin, program (‘0’) RSTDISBL fuse. As inputs, Port B pins that are externally pulled low
will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a
reset condition becomes active, even if the clock is not running.
RESET
Port B is a 4-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port B output buffers have symmetrical drive characteristics with both high sink and source
capability except PB3 which has the RESET capability. To use pin PB3 as an I/O pin, instead of
RESET pin, program (‘0’) RSTDISBL fuse. As inputs, Port B pins that are externally pulled low
will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a
reset condition becomes active, even if the clock is not running.
Port A(PA7:PA0)
Port A is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port A output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port A pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port A pins are tri-stated when a reset condition becomes active,
even if the clock is not running.
What I learned from the datasheet¶
From what I have read thoroughly and what I have scanned I can highlight the following data of interest:
- The ATtiny44 is a 8 bit microcontroller with possible 2K, 4K or 8K Flash program memory and 128, 256 or 512 Bytes of In-System Programmable EEPROM
- The operating voltagle is between 1.8 to 5.5v. This means that I can use a 5v power source which always good to know.
- The table 10.3 on page 60 is important to know what are the alternate functions of each pin.
- “I/O” = Input/Output
- Connections of the capacitor with crystal oscillator
The capacitors c1 and c2 must be equal.
Group Assignment¶
Comparison of different architectures¶
Von Neumann Architecture
Between 1945 & 1951 John von Neumann set down the structure, layout, interaction, cooperation, realisation, implementation, functionality and activity for the whole computer as a system.
- The Von Neumann Architecture is characterized by: - A memory, arithmetical-logical unit (ALU), control unit, input and output devices,
- All parts of a computer are connected together by Bus,
- Memory and Devices are controlled by CPU.
- Data can pass through bus in half duplex mode to and from CPU.
- Memory holds both programs and data; this is also known as the stored program concept.
- Memory is addressed linearly; that is, there is a single sequential numeric address for each and every memory location.
- Memory is addressed by the location number without regard to the data contained within.
- Memory is split to small cells with the same size. Their ordinal numbers are called address numbers.
- Program consists of a sequence of instructions. Instructions are executed in order they are stored in memory.
- Sequence of instructions can be changed only by unconditional or conditional jump instructions.
- Instructions, characters, data and numbers are represented in binary form.
Diagramatic View of Von Neumann Architecture
Advantages of Von Neumann
- Control Unit gets data and instruction in the same way from one memory. It simplifies design and development of the Control Unit.
- Data from memory and from devices are accessed in the same way.
- Memory organization is in the hands of programmers.
Disadvantages of Von Neumann
- Serial instruction processing does not allow parallel execution of program. Parallel executions are simulated later by the Operating system.
- One bus is a bottleneck. Only one information can be accessed at the same time.
- Instruction stored in the same memory as the data can be accidentally rewritten by an error in a program.
Harvard Architecture
MARK II computer was finished at Harvard University in 1947. It wasn’t so modern as the computer from von Neumann team. But it introduced a slightly different architecture. Memory for data was separated from the memory for instruction. This concept is known as the Harvard architecture.
Advantages of Harvard
- Since it has two memories , this allows parallel access to data and instructions.
- Development of the Control Unit is expensive and needs more time.
- Data and instructions are accessed the same way.
- Both memories can use different cell sizes.
Disadvantages of Harvard
- Free data memory cant be used for instruction and viceversa.
- Production of a computer with two buses is more expensive and needs more time.
Personal assignment¶
Programming¶
Using Arduino IDE and FabISP¶
I programmed my (EchoHello Boards)[] to turn ON/OFF the LED on pressing push button.
Connections
- Connect the FabISP to the USB Port of the computer.
- Connect Echo board to FabISP using 6 pin header cable.
- Make sure that the orientation of the cable is correct, such that, corresponding pins of the ISP headers are connected.
Steps
- Download the Arduino IDE from www.arduino.cc
- Go to File –> Preferences 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
- Next, Go to Tools –> Boards-> Boards Manager and search and install the Arduino AVR Boards.
- Go to Tools –> Board –> ATtiny24/44/84, Processor –>ATtiny44, Clock –> 20MHz and Programmer –> USBtinyISP.
-
Now, Burn the bootloader into the chip (Tools –Burn Bootloader). This sets the fuses and flashes any previous configuration over the chip.
-
Corresponding pins of ATtiny44 in Arduino IDE.
Program¶
Code Breakdown
Here, I declared the Button pin and LED pin on digital pin 3 and 2 respectively. (My button and pin are connected to pin no. 9 and 10 and the corresponding pins for these in Arduino IDE are 3 and 2 respectively.)
int button = 3; int led = 2;
In the setup function, I set the button pin as input and LED pin as output.
void setup() { pinMode(button, INPUT); pinMode(led, OUTPUT); }
In loop function, first, read the state of the button and stored the value in a variable called “state”.
void loop() { int state = digitalRead(button);
if and else has been used to check the value of state variable and accordingly turn ON/OFF the LED.
if (state == 0) { digitalWrite(led, HIGH); } else { digitalWrite(led, LOW); } delay(100); }
Here, logics are inverted because I used ‘pull up’ resistor with the button.
Click here to download the sketch.
- Next, select the port and burn the program in the IC.
Learning outocomes¶
- I learned about different microcontrollers and how to check their specifications using datasheets.
- I learned how to program a microcontroller using fabisp, how to program the microcontroller using Arduino IDE.
- I learned about different architectures of embedded systems.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.