Embedded Programming

Reading a Datasheet

What is Datsheet?
It's a detailed document describing all the features about a specific product similarly in electronics like microcontrollers and sensors it's adviced to read a Datsheet and proceed because that gives a full idea about how the product is going to work in certain environment,
say how a sensor will behave in extreme weather conditions, or a microcontroller will work at a particular volatage or current, it contains the controller's detailed architecture etc...

Personally reading a 200-250 page documentation is kind of boring and but let's not be naive about it and get started..

AT TINY 44

So I found two Datasheet on the internet one from the official link of MicroChip and One from MIT lab they were literally same just the MIT one has more number of pages I haven't read the all datasheet I just went throug the setions that were required and coulb be understood my lil mind.
Datasheet Official Microchip -194pgs
Datasheet MIT fablab link- 229pgs Altough they both are the same

From this video I leraned How to reverse engineer and read a datasheet For our purpose
I didn't get all of them, I watced it thrice, but somehow I got to know what to search and how to search particular things in a datsheet.



Here's the keypoints from the data sheet-


						    >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  
				
It's a low power AVR 8 bit Microcontroller based on Advanced RISC architecture.
What is meant by architechture?
Computer architecture is a set of rules and methods that describe the functionality, organization, and implementation of computer systems. Some definitions of architecture define it as describing the capabilities and programming model of a computer but not a particular implementation. In other definitions computer architecture involves instruction set architecture design, microarchitecture design, logic design, and implementation.
~Wikipedia

Understanding RISC and CISC

RISC CISC
The term RISC stands for ‘’Reduced Instruction Set Computer’’. It is a CPU design plan based on simple orders and acts fast. The term CISC stands for ‘’Complex Instruction Set Computer’’. It is a CPU design plan based on single commands, which are skilled in executing multi-step operations.
This is small or reduced set of instructions. Here, every instruction is expected to attain very small jobs. In this machine, the instruction sets are modest and simple, which help in comprising more complex commands. Each instruction is of the similar length; these are wound together to get compound tasks done in a single operation. Most commands are completed in one machine cycle. This pipelining is a crucial technique used to speed up RISC machines. CISC computers have small programs. It has a huge number of compound instructions, which takes a long time to perform. Here, a single set of instruction is protected in several steps; each instruction set has additional than 300 separate instructions. Maximum instructions are finished in two to ten machine cycles. In CISC, instruction pipelining is not easily implemented.
~ Source link


The below image shows the very important pinout for the Attiny 44, in order to make sure of the connections and also the placement of the component.

Source ~ link

PIN Descriprions

The content below is mostly from Datasheet I've tried somewhere to explain it in my words.

Understanding The PULL UP and PULL DOWN Resistances

You can go to my Week 7 where I explained aboutt PULL-UP resister and how to calculate it's value from here.

Digital logic gates can be used for connection to external circuits or devices but care must be taken to ensure that their inputs or outputs function correctly and provide the expected switching condition.

Modern digital logic gates, IC’s and micro-controllers contain many inputs, called “pins” as well as one or more outputs, and these inputs and outputs need to be correctly set, either HIGH or LOW for the digital circuit to function correctly.

We know that logic gates are the most basic building block of any digital logic circuit and that by using combinations of the three basic gates, the AND gate, the OR gate and NOT gate, we can construct quite complex combinational circuits. But being digital, these circuits can only have one of two logic states, called the logic “0” state or the logic “1” state.

These logic states are represented by two different voltage levels with any voltage below one level regarded as a logic “0”, and any voltage above another level regarded as logic “1”. So for example, if the two voltage levels are 0V and +5V, then the 0V represents a logic “0” and the +5V represents a logic “1”. If the inputs to a digital logic gate or circuit are not within the range by which it can be sensed as either a logic “0” or a logic “1” input, then the digital circuit may false trigger as the gate or circuit does not recognise the correct input value, as the HIGH may not be high enough or the LOW may not be low enough.
For further info about pullup and pull down I found this amazing article on the web you can refer to that with this
Source link.


Programming PINs
						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)
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

Arduino IDE is a cross platform environment that consist of large number of inbuilt libraries and supports third party hardwares as well.
It is available on Windows store or it can be downloaded from it's official website for free.
www.arduino.cc
The first step is to add the board that we are going to use in the board manager.
For this i checked one of the students documentation and followed his instructions,
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

Now connecting he Fab Isp to the my Led board and connecting the ISP to the USB of laptop.
The first Step is 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
Burning the bootloader
  • from the tools select the proper board and processor Here I have ATTiny 44
  • Now select the external Clock we are using 20Mhz
  • Now select the programmer USBtinyISP in my case although the IDE shoild Detect it automatically in my case
  • Noe click on the Burn Bootlaoder option




ERRROR! ERROR!
I ran into error while burning the bootloader I asked my instructor quoting him my problem on whatsapp, the system was detecting my fabISP but there were some missing Drivers of the ISP so as Im a window user he adviced me to download the USBtiny Drivers from ZAdig so I followed his instructions.
I initially had zadig exe file but somehow it got deleted so I ran into documentation of Brian's from where I installed all the necessary toolchains for programming in the Electronics production week and dwonloaded zadig.
I selected the same as it was documented and voilla!!! It was done an I was able to Burn the Booltloader after that.


Programming With Arduino IDE

After burning the Bootloader I opened A new Sketch and wrote the following code it was simole iteration of the inbuilt led blink example.


										int button = 3;//Defining Button
										int led = 7;//Defining LED

										void setup()
										 {
										   pinMode(button, INPUT);//Setting Button as Input
										  pinMode(led, OUTPUT);//Setting LED as Output
										 

										}

										void loop()//loop statement 
										 {
										 int state = digitalRead(button); //reading Sate of button Pushed or Not
										                if (state == 0)
										                {
										                    digitalWrite(led, HIGH);//Led On
										                      delay(1000);//Delay of 1 sec  
										                  } 
										                  else {
										                    digitalWrite(led, LOW);
										                      delay(1000);
										                  }
										                  delay(1000);
										}

                    				


And the Satisfied output was obtained!
I never thought that Blinking of an LED could give So much immense Happiness!!

Not Pressed
Pressed


Download the code from here:


Group Assignment

Our assignment was to compare the performance and development workflows for other architectures


Fab academy's Ring Oscillators

Here they define speed as how fast information can transit from external electronics into the core where microcode is running and back out again. A good way to test this is by constructing a ring oscillator, which simply sends token back and forth, producing a waveform that can be measured with an oscilloscope.


To measure they have classified a chart based on various parameters to measure the speed

  • GPIO-

    To measure speed across a GPIO layer, they use a logic level as the token. They also enforce that the token must reach the CPU, where code is running, rather than simply be inverted by digital logic or an event system.

  • RF-

    To measure speed across a radio link, they use the smallest supported packet.

  • WILDWEST-

    Here thry test embedded platforms that stray from the Harvard Architecture ... I.E FPGAs, PSOCs etc, including event systems or digital logic configurable in other microcontrollers (i.e. the XMEGA).

Source-
https://pub.pages.cba.mit.edu/ring/

Typical Architecture of an Embedded System


Source~ https://ebrary.net/22041/computer_science/typical_architecture_embedded_system

Figure configuration diagram of a typical embedded system consisting of two main parts: embedded hardware and embedded software. The embedded hardware primarily includes the processor, memory, bus, peripheral devices, I/O ports, and various controllers. The embedded software usually contains the embedded operating system and various applications.

Input and output are characteristics of any open system, and the embedded system is no exception. In the embedded system, the hardware and software often collaborate to deal with various input signals from the outside and output the processing results through some form. The input signal may be an ergonomic device (such as a keyboard, mouse, or touch screen) or the output of a sensor circuit in another embedded system. The output may be in the form of sound, light, electricity, or another analog signal, or a record or file for a database.


Typical Hardware Architecture

The basic computer system components—microprocessor, memory, and input and output modules—are interconnected by a system bus in order for all the parts to communicate and execute a program

In embedded systems, the microprocessor's role and function are usually the same as those of the CPU in a general-purpose computer: control computer operation, execute instructions, and process data. In many cases, the microprocessor in an embedded system is also called the CPU. Memory is used to store instructions and data. I/O modules are responsible for the data exchange between the processor, memory, and external devices. External devices include secondary storage devices (such as flash and hard disk), communications equipment, and terminal equipment. The system bus provides data and controls signal communication and transmission for the processor, memory, and I/O modules.
There are basically two types of architecture that apply to embedded systems:
Von Neumann architecture and Harvard architecture.


Von Neumann architecture

Von Neumann architecture (also known as Princeton architecture) was first proposed by John von Neumann. The most important feature of this architecture is that the software and data use the same memory: that is,

“The program is data, and the data is the program”

In the Von Neumann architecture, an instruction and data share the same bus. In this architecture, the transmission of information becomes the bottleneck of computer performance and affects the speed of data processing; so, it is often called the Von Neumann bottleneck. In reality, cache and branch-prediction technology can effectively solve this issue.

Harvard Architecture

The Harvard architecture was first named after the Harvard Mark I computer. Compared with the Von Neumann architecture, a Harvard architecture processor has two outstanding features. First, instructions and data are stored in two separate memory modules; instructions and data do not coexist in the same module. Second, two independent buses are used as dedicated communication paths between the CPU and memory; there is no connection between the two buses.

Because the Harvard architecture has separate program memory and data memory, it can provide greater data-memory bandwidth, making it the ideal choice for digital signal processing. Most systems designed for digital signal processing (DSP) adopt the Harvard architecture. The Von Neumann architecture features simple hardware design and flexible program and data storage and is usually the one chosen for general-purpose and most embedded systems.
To efficiently perform memory reads/writes, the processor is not directly connected to the main memory, but to the cache. Commonly, the only difference between the Harvard architecture and the Von Neumann architecture is single or dual L1 cache. In the Harvard architecture, the L1 cache is often divided into an instruction cache (I cache) and a data cache (D cache), but the Von Neumann architecture has a single cache.

For Detailed Description visit Our Group Page

Learning Outcome


Top