Week 9 - Embedded Programming

June 22018

Embedded Programming

Download all the files for this week from here

  • For this week’s group assginment - visit here.

  • For this week’s assignment I went through my instructor’s FabAcademy 2016 ,It was a great help.

  • This week we had to read a detailed data sheet of tiny microcontroller (MC), learn different approaches to program attorney or avr’s.

As instructed i went through this video & book Make : AVR Programming.

Attiny 45 Data-sheet Review

  • Link to the datasheet

  • High performance, Low Power AVR 8-bit micro-controller

  • Advanced RISC architecture

    • 120 powerful instructions
    • 32 x 8 general purpose working registers
  • Non-volatile Program and Data memories

    • 4K bytes of in-system programmable program memory flash
    • 256 bytes in-system programmable EEPROM
    • 256 bytes internal SRAM
  • Peripheral features

    • 8-bit Timer/Counter with prescaler and 2 PWM channels
    • USI - Universal Serial Interface with start condition detector
    • 10-bit ADC
    • Programmable Watchdog Timer
    • On-chip analog comparator
  • Operating voltage

    • 1.8 - 5.5V for ATtiny45V
    • 2.7 - 5.5V for ATtiny45
  • Speed Grade

    • ATtiny45V: 0 - 4 MHz @ 1.8 - 5.5V, 0 - 10 MHz @ 2.7 - 5.5V
    • ATtiny45: 0 - 10 MHz @ 2.7 - 5.5V, 0 - 20 MHz @ 4.5 - 5.5V
  • Pin configurations

–Port B (PB0:PB5): Its bi-directional i/o port with internal pull up resistor. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated.

–RESET: It basically reset the input. A low level of this pin with longer than minimum pulse length generates reset.

–CLK and CLR: CLK is Clock and CLR is Clear.

–VCC and GND: VCC is voltage supply and GND is ground.

week9

Programming Languages

  • C using Arduino IDE libraries.Takes most space in the MC because it loads many libraries of Arduino into the chip. Easiest to use
  • C using avr-gcc libraries. Takes very less space as compared to arduino c libraries as it loads only the essential c libraries from avr-gcc. Easier than assembly, it has a medium trade of between control and ease of use.
  • Assembly language. Lowest level language, that give maximum control. You are literally wiring the logic manually inside the chip. Takes least amount of space as there are no external libraries to load. You need to know the internal working of the chip if you want to use it to maximum extent possible and it is used in cases where you want to use the chip to its maximum potential.

source - Puneeth Raj

  • To program the board I will use the Brian’s ISP as the programmer which I created in week 6 assignment.

Using Arduino IDE to program the microcontroller.

The board i’ll be using is the same i made in Week 7

Connections :

Steps in Arduino IDE to program an Attiny.

  • First you need to install the Attiny Library. follow the instructions here.
  • Then in Tools go to and pick Board-> ATTiny , Processor-> ATtiny 45 , Programmer-> usbtinyisp , Clock -> External or Internal, upto you.

week9

  • After that you ned to burn the bootloader , Tools->Burn bootloader

  • The bootloader is the little program that runs when you turn the Arduino on, or press the reset button. Its main function is to wait for the Arduino software on your computer to send it a new program for the Arduino, which it then writes to the memory on the Arduino.

week9 * After all the steps, you are now set to write the programs to the Microcontroller on your board.

  • There are two sections in Arduino IDE Program :

    1. Setup
    2. Loop
  • Setup program is executed one time only, it’s used to declare the Pin Modes (Output/input/pwm).

    	void setup(){
    	definitions/ declaration of variables
    	setting up pin modes and internal pull-ups
    	}
    

    Every pin delivers- 5v max and 40mA current. Input- reads 0 or 5v

  • Loop- As the name suggest the statements are in loop.

    	void loop() {
    	statements;
    	}
    
  • Attiny 45 pinout for arduino.

week9 Kindly open the image in new tab as to zoom and see the image clearly.

  • In the diagram programming pins for Arduino are also given which were used to write the program.

  • In the board i’m using,

    • LED to pin PB3
    • Button is connected to pin PB4. week9
  • Schematic week7

  • Boardweek7 week9

The board is from week-7.

Programming with Arduino IDE :

* For programming i used Arduino IDE. The program are relatively easier to write and also many tutorials are viable on the internet which help a lot-while learning.

Blink LED

  • I used an example sketch from the Arduino IDE, just changed the pin number to where your LED is attached.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    
    void setup() {
    // initialize digital pin 3 as an output. default will be 13 in the arduino example.
    pinMode(3, OUTPUT); //pin3 is pba3 on attiny 45
    }
    	 
    // the loop function runs over and over again forever
     
    void loop() {
    digitalWrite(3,HIGH);// turn the LED on (HIGH is the voltage level)
    delay(1000);
    digitalWrite(3,LOW);// turn the LED off (LOW is the voltage level)
    delay(1000)
    	 }

  • File’s Name in the source folder : blink.ino

week9

  • Working video :

Button to Trigger LED

  • Now i have to connect a button which will trigger the LED.
  • Pull up the button pin internally.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
void setup() {
 	
// initialise digital pin 3 as an output.
pinMode(3, OUTPUT); pin3 is pba3 on attiny45
pinMode(4,INPUT); pin4 is pba4 on attiny 45
digitalWrite(4,HIGH); // internal pullup

}
 
// the loop function runs over and over again forever
void loop() {
 
if (digitalRead(4)){
digitalWrite(3, LOW);   // turn the LED on (HIGH is the voltage level)
 
}
else {
 
digitalWrite(3, HIGH);    // turn the LED off by making the voltage LOW

}
}
  • File’s Name in the source folder : button.ino

week9

  • Working Video :

Arduino IDE Video