Embedded programming





    Task of the week

    What I have did

    Individual assignment :

  • Studied laser cutter.

  • Read a microcontroller data sheet.

  • Have read the data sheet of Attiny 44 microcontroller.

  • Program your board to do somthing.

  • Have programmed the board by using Arduino and have tried Embedded_C languages. Also, I have used different programming environments like Arduino IDE, linux and windows operating systems.

  • Use different programming languages and programming environments as possible.

  • Have study and compare the performance and development workflows for different architechtures.

    Group assignment :

  • Have described the observations of programming the ESP32.

  • Compare the performance and development workflows for other architechtures.


    Week 8 : -

    In this week our task was to read Datasheet of a Microcontroller. In the previous week where we have to design a programmable board, I have used Attiny44 microcontroller. So I was very much interested to know more features related to Attiny44. This week I have read the datasheet of same microcontroller.

    Individual Assignment : -

Week1-1

    Attiny44 is a High Performance, Low Power AVR 8-bit Microcontroller based on the AVR enhanced RISC architecture. RISC i.e. Reduced Instruction Set Computer is a computer instruction set that allows a computer to have fewer cycles per instruction than a complex instruction set computer(CISC). It is a 14 pin IC, it has 2 ports. 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. Port A is a 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. It has self-programmable 'Flash memory' of (4k bytes). (From the datasheet).

  • Operating Voltage : – 1.8 – 5.5V

  • Speed Grade : -
    0 – 4 MHz = 1.8 – 5.5V
    0 – 10 MHz = 2.7 – 5.5V
    0 – 20 MHz = 4.5 – 5.5V

  • Low Power Consumption : -
    Active Mode :
    • 210 μA at 1.8V and 1 MHz
    Idle Mode :
    • 33 μA at 1.8V and 1 MHz
    Power-down Mode:
    • 0.1 μA at 1.8V and 25°C

Week1-1

    Pins Discription : -

  • VCC : Supply voltage.

  • GND : Ground.

  • 'Port-A' and 'Port-B': Port-A has 8 pins and Port-B has 4 pins.

  • 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

    and provided the reset pin has not been disabled. Shorter pulses are not guaranteed to generate a reset. The reset pin can also
    be used as a (weak) I/O pin.

    Programming with Arduino IDE : -

    After reading the datasheet we have to program our board in 'Arduino' IDE. It is an ' Integrated Development Environment'. It is a cross-platform application (for Windows, macOS, Linux) that is written in functions from 'C' and 'C++'. It is used to write and upload programs to not only the Arduino board but also the various other boards with different micro-controller like Atmega328p, attiny44, 45, ESP32...etc.

Week1-1

    Functions of various key in 'Arduino IDE' : -

Week1-1

  • Compiling : It means there are not cable connected to it, and you are communicating with it through eg. an ethernet board.

  • Upload : We need to press this button after compiling the program we write in 'Arduino'.

  • New : When we press this button, a new window of 'Arduino-sketcher' is get open on the screen.

  • Open : Various examples of programs categorized in ( Basic, Digital, Analog, Communication, Controls, Sensors... are available.

  • Save : If we want to save our run program to use it again for next operation or If we want to do some editting and reuse it then we need to save that file first.

    Details of program in 'Arduino IDE' : -

  • In the following image we can see the simple Blinking code which is available in the Example section of Arduino IDE. This example programs become helpful for the beginner like me. In the previous week I have program my Hellow world board by modifying the program for Button. Because my board has the LED and Button.

  • In this week we have to study the different kinds of programming environment(IDE's). So I have started with Arduino IDE. Because in the previous week I have get the introductory information about Arduino. So I want to explore my knowledge about it. For programming I have used the Hellow world board which I have design and milled in the previous week.

Week1-1

    What I have understand : -

  • pinMode is the character which we use to define the pin number as a Output/Input pin. That is if we what to give signal to a perticular pin number then we have to desfine it in the code by using pinMode character.

  • After defining the pin number. If we want that if that pin should perform a perticular function. That is if we have define the pin number to which the LED is connected and we want that the LED should blink when the code is uploaded and supply is given to the board through VCC the we use the command digitalWrite. Digitalwrite means write the command on pin number we have selected. For example if we want to on the LED then we write digitalWrite(LEDpin, HIGH) .

  • delay is provided between the two operation perform by the same pin. For example if we want the LED pin should on for ONE second and should remain off for ONE second then we provide the delay of 1000 between this cycle.

Week1-1

  • Before uploading the program we should select the type of micro-controller we are using in our board. Here I have choose the micro-controller Atatiny44 from the list of tiny family. Eithere this process can be done before writing the program or before uploading the program.

  • ATtiny mcus are not support by the Arduino IDE by default. We need to add the library of ATtiny44 into the environment.

  • The Arduino IDE environment can be extended through the use of library, just like programming platforms. Libraries provide extra functions for using in arduino like working with hardware.

  • In this case for using the library of ATtiny44 in the arduino ide environment.

  • Go to File select Preferences.



Week1-1




Week1-1


  • Then go to Tools bring the mouse pointer near the arrow of Board. The list of various options get open select " Boards Manager "



Week1-1


  • In the " Board manager " search for David A. Mellis library and click Installed.



Week1-1


  • This is the process of including the library in Arduino IDE environment.



Week1-1


  • Once we have done all the changes and have write the program as we reuire to make changes in our board then click on the compiling button as I mensioned above. We can see the compiling process in the bottom window of IDE.

  • When the window shows Done compiling then click on the Uploading button as I mensioned above. We can see the ongoing uploading process in the dailog box at the bottom of arduino IDE window

Week1-1

  • After the uploading process of program is done it shows the message Done uploading.

Week1-1
  • In the above image I have highlighted an instruction written in comment (i.e. //). These instructions are written by the programmer. This will help to understand the command line of the program by the person who is using the program at first time.

    This is the source code for Blinking LED : -


	
	               
//modified by : Tejswini Chaudhari
//19 March 2020
// Blinking LED.

// the setup function runs once when you press reset or power the board

void setup(){
// initialize digital pin LED_BUILTIN as an output.	
pinMode(PB2, OUTPUT);

}


// the loop function runs over and over again forever
void loop() {

digitalWrite(PB2,HIGH);  // turn the LED on (HIGH is the voltage level)
delay(1000,);   // wait for a second
digitalWrite(PB2,LOW);    // turn the LED off by making the voltage LOW
delay(1000,);   // wait for a second
   
   
}
    
   

  • Before going for uploading the program on actual board I have tried it on the Arduino board with breadboard

  • After successfully uploading the program on arduino board I have uploaded the program on the main board.

    Embedded_C : -

  • After using arduino language for programming I have used embedded_c for getting a introduction of the language.

  • Embedded C is a set of languages extensions for C.

  • Embedded C use most of the syntax and semantics of standard C, such as main() function, variable defination, datatype declaration, conditional statements (if,switch,case), loops (while,for), functions, arrays and strings, structures and union, bit operations, macros, unions, etc.

  • Embedded C is an extension of C programming language that provides support for developing efficient programs for embedded devices. It is not a part of the C language.

    Discription of embedded_c : -

  • I have written C-code in the arduino IDE.

  • Where,

  • '0' represent Input

  • '1' represent Output

  • '0b' represent the binary value.

  • 'DDR' is decides whether the pin of a port are input pins or output pins.
    If the pin is input, then the voltage at that pin is undecided until an external voltage is applied.
    If the pin is output, then the voltage at that pin is fixed to a particular value (5V or 0). I have refere Introduction to Embedded systems by Electronics club IIT Kanpur to know about embedded programming language.

    The source code for Blinking LED with button in embedded_c : -


	
	               
	
	/*
 
 A simple on/off button code for Tiny44
 Button connected to PB0
 LED connected to PB2

 Program written by Andrew Kriebel to demonstrate the LED on/off by push button.

 modified by Tejswini Chaudhari for her pins.

*/

#include 

 int main(void) {

  PORTB = 0b00001000;
     // register PORTB high.  
  DDRB = 0b10000000;
    // high.

 while (1) {

       if ((PINB & 0b00001000) == 0 ) {
        PORTB = 0b10000000;
       }
       else {
        PORTB = 0b00000000;
       }
      }

    return (0);       
   }
		
	

    Programming with Windows : -

  • After programming with Arduino IDE I have tried the same blinking program with Windows operating system. For programming with Windows we require C code. To upload the C code we require make file.

  • First I have downloaded the source code i.e C code and make file from the syllabus.Make file. Then I have saved the C file and make file both in my root directory and have complied the 'C code'/C file. using the command :
    make -f LEDBLINK.c.make

Week1-1

  • For setting the clock of 20MHz using external crystal, set the fuses.
    make -f LEDBLINK.c.make program-usbtiny-fuses.

  • Then program the micro-controller using the command :
    make -f LEDBLINK.c.make program usbtiny.

Week1-1

Programming with Linux operating system : -

  • For programming through Linux use the same make command for compiling the code as mensioned above.

  • For progammming the micro-controller in linux we have to use : sudo make -f LEDBLINK.c.make program-usbtiny.

Week1-1

    My observation : -

  • For the group assignment we have studied different arcitectures. ESP32 is one of that discription is given in the Group assignment please click on the link.

  • For uploading the simple blinking code we have used the readymade board of ESP32.

Week1-1

  • Here it has one trick for uploading the code. After uploading the code on board we have to drag the slide switch. We have to do this within a particular time. I have not calculated the time but, after uploading the code we can see a certain process in the below window. Here it shows some dots when the process comes up to three dots drag the switch. Then it shows 100% writing the process.

Week1-1

    Download design files : -

    Learning outcomes : -

  • This week was quite interesting. I have tried various IDE's/environments for programming my board like Arduino, Windows, Linux.

  • Out off all programming environments I have found the Arduino IDE most userfriendly and interesting.

  • I have also mensioned my observations related to ESP32. It may be roung but I have experiances it while programming ESP32. One thing is clear that we have to drage the slide switch in the board at a perticular time.

Creative Commons License
Solar Automatic Shredder by Tejswini Chaudhari is licensed under a Creative Commons Attribution-ShareAlike 4.0
International License