Week 9

Embedded Programing

Objectives

Individual Assignment
1) Read the datasheet for the microcontroller you are programming.
2) Program the board you have made to do something, with as many different programming languages and programming environments as possible.

Group Assignment
Compare the performance and development workflows for different microcontroller families.
view page

Learning Outcomes
1) To identify relevant information in a microcontroller datasheet.
2) To implement programming protocols.

Individual Assignment

ATtiny 44



The ATtiny44 is a high-performance, low-power Microchip AVR RISC-based CMOS 8-bit microcontroller.It combines 4KB ISP flash memory, 256-Byte EEPROM, 256B SRAM, 12 general purpose I/O lines .The ATtiny44 consistof 32 general purpose working registers, an 8-bit timer/counter with two PWM channels, a 16-bit timer/counter with two PWM channels, internal and external interrupts, an 8-channel 10-bit A/D converter and a programmable gain stage (1x, 20x) for 12 differential ADC channel pairs. It has a programmable watchdog timer with internal oscillator.The a internal calibrated oscillator and three software selectable power saving modes makes it suitable for small embedded products . By executing powerful instructions in a single clock cycle the device achieves throughputs approaching 1 MIPS per MHz .It also balance power consumption and improve processing speed.

If you want to know more about ATtiny44 just go through the datasheet

hese are some basic details about the chip.



Block Diagram


ATtiny PINS


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). As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated.so we don't need to add a pull-up resistor externaly for button's and other purpose.

RESET : Reset input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running.a reset will just reset the programm that currently runnig .

Port A (PA7...PA0) : Port A is a 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). As inputs, Port A pins that are externally pulled low will source current if the pull-up resistors are activated.

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

MOSI (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).




Hello Echo Board



This week we need to progarmme the Hello-echo board that we designed in the Electronics Design week.

Echo board is based on the Microchip ATtiny44 . It's a 8-bit RISC based microcontroller. The Originl Design have only the UART Port and I added a Programmable Button connected to pin PA7 with a Pull-down Resistor and LED connectd to PA5 also it's have 20hz External Resonator.


Programming using Adruino
Arduino is an open source computer hardware and software company, project, and user community that designs and manufactures single-board microcontrollers and microcontroller kits for building digital devices and interactive objects that can sense and control objects in the physical and digital world.[wiki]

- Download, Install and Open Adruino.



Since the original Arduino software does not support the ATtiny44. I have to add some Board directorys for adding my ATtiny44 board to my arduino enviournment

- Go to preference by clicking
File >> Preference



- In Additional Board Manager URls add the Following URL
http://drazzy.com/package_drazzy.com_index.json



- After adding the URL open Board Manager by clicking
Tools >> Board >> Board Manager



-Search for ATtiny44 in the following Window.(Make sure you have Internet connection).and Install the latest version .



- Now you can select ATtiny44 under the ATtiny Microcontrollers in board Selection



- Select the Clock as 20MHz.



- We are using Fab ISP to programme the Hello-Echo board, so Select the Programmer as USBtinyISP.



- ATTiny44 is defaultly set to use the Internal clock .So if you are using Arduino to program it. It will not get program initially . We have to upload the Bootloader first.



- Now the board is ready to be programmed with Arduino.

- Reffer the Arduino Pin Mapping to find the Number corresoponding to the Pin Number on ATtiny44.

In my case, If have to define LED with 8 and Switch with 7 while programming on Arduino, because I connected the LED to Pin5 and Switch to Pin6 of ATtiny44

- First im going to do a simple programme to blink the LED.
              #define LED 8
              
              #define SW 7
              
              void setup() 
              {
                pinMode(LED, OUTPUT);
                pinMode(SW, INPUT);
              }
              
              void loop()
              {
                digitalWrite(LED, HIGH);
                delay(1000);
                digitalWrite(LED, LOW);
                delay(1000);
              }
              
              
Click Upload to flash the Hello-Echo Board .




- Program to OFF the LED using Switch
              #define LED 8
              
              #define SW 7
              
              void setup() 
              {
                pinMode(LED, OUTPUT);
                pinMode(SW, INPUT_PULLUP);
              }
              
              void loop()
              {
                if(gigitalRead(SW_==0)
                {
                  digitalWrite(LED, HIGH);
                }
                else
                {  
                  digitalWrite(LED, LOW);
                }  
              }
              
              




Programming using Atmel Studio
Atmel Studio 7 is the integrated development platform (IDP) for developing and debugging all AVR® and SAM microcontroller applications. The Atmel Studio 7 IDP gives you a seamless and easy-to-use environment to write, build and debug your applications written in C/C++ or assembly code. It also connects seamlessly to the debuggers, programmers and development kits that support AVR® and SAM devices.

Additionally, Studio includes Atmel Gallery, an online app store that allows you to extend your development environment with plug-ins developed by Microchip as well as third-party tool and embedded software vendors. Studio 7 can also seamlessly import your Arduino sketches as C++ projects, providing a simple transition path from Makerspace to Marketplace.



In embedded C we need to handle the registers. Each of the AVR Digital I/O ports is associated with three (3) I/O register. A Data Direction Register (DDRx), A Pin Register (PINx) and a Port Register (PORTx). Where x is the port A, B, C, etc.

DDRx - Port X Data Direction Register
DDRx is an 8-bit register which stores configuration information for the pins of Portx. Writing a 1 in the pin location in the DDRx makes the physical pin of that port an output pin and writing a 0 makes that pin an input pin.
Note: Each physical pin of a port is configured independently and thus a port can have some of its pins configured as input an the others as output pins.


PINx - Port X Input Pins Register
PINx is an 8-bit register that stores the logic value, the current state, of the physical pins on Portx. So to read the values on the pins of Portx, you read the values that are in its PIN register.


PORTx - Port X Data Register
PORTx is an 8-bit register which stores the logic values that currently being outputted on the physical pins of Portx if the pins are configured as output pins. So to write values to a port, you write the values to the PORT register of that port.



First we need to configure the Atmel Studio for our Fab ISP

- Download and install WinAVR

- Open Atmel studio

- Select language and template
New Project >> c/c++ >> GCC C Executable Project >> OK



- Select the ATtiny44 as the Microcontroller



- Next we have to add our programmer to our enviournment.
Tools >> External Tools >>
Fill the spaces as shown below.
Title:- USBTiny
Command:- avrdude.exe
Arguments:- -c usbtiny sp -p t44 -F -v -U flash:w:$(TargetDir)$(TargetName).hex:i





Program for simply blinking the LED



To build the code just click build -> Build Solution or press "F7"



Upload to the Chip using the programmer .Choose Tools -> USBTiny -> OK






Benchmark Test
In here we are testing to determine the performance characteristics of Our board in different Lanagues .we are testing the execution speed by turn-0ff and turn-on the led without delay.

1) Arduino
Program
              
                void setup()
                {
                  pinMode(PA1,OUTPUT); 
                }

                void loop()
                {
                  digitalWrite(PA1,HIGH);
                  digitalWrite(PA1,LOW);
                }
              
            


Time period = 5.2 micro-seconds

2) GCC C
Program
              
                #define F_CPU 20000000UL

                #include 

                int main(void)
                {
                 DDRA |= (1<<1);

                 while(1)
                 {
                  PORTA |=(1<<1);
                  PORTA &=~(1<<1);
                 }
                }
              
            


Time period = 300 nano-seconds

3) Assembly
Program
              
                .org 0
                sbi DDRA,1

                main:
                sbi PORTA,1
                cbi PORTA,1

                RJMP main
              
            


Time period = 300 nano-seconds


The results from the DSO shows that the program executed by 'GCC C' and 'Assembler' are faster than program executed by 'Arduino'.