Tuesday, 5 April 2016

How different frequency requirement of various aplications are taken care by laptop/mobile ?

There is also software timer facility available at kernel level such that varying frequency could be provided not only at hardware level but also based upon requirement of individual application.

Lets assume that user is playing some high end graphic game. In such case, heavy data transfer and processing rate is needed to display all graphical contents, which make system work at high clock rate. On the contrary, if user is trying to use some simple calculation using calculator, not enough clock rate is needed.

To get varying frequency requirements of application, every individual task of application have its own soft-timer facility, which have soft timers (loaded with count value as per individual task requirement).

The soft-timer facility constitute two parts: one component lives within the timer tick ISR (ISR_function) and the other component stays in task context (called worker_task).

Assume that an application requires four soft timers.
  • The timeout values equal 50us, 100us, 150us and 200us for which the least common denominator is 50us.
  • If each hardware timer tick is 10us, then 50us translates into a count value of 5. 
  • The ISR_function keeps track of this count value and decrements it by one during each invocation. 
  • The ISR_function informs the worker_task regarding completion of count value to zero by setting the worker_task's semaphore, effectively allowing the task to be scheduled for execution. 
  • The ISR_function again initializes the count value back to 5.
  •  Worker_task must maintain an application-level, timer count table based on 50us granularity. 
  • Here, the timer table has four countdown values: 1, 2, 3, and 4 representing the 50us, 100us, 150us and 200us application-requested timers.
  • Timer-expiration function is associated with each timer during application installation.
  • When the counter value reaches zero, the application timer has expired and application function runs. 
  • Every time the worker_task runs, all the counters value is decremented by 1
  • A single ISR-level timer drives 4 application timers at the task-level, providing a good reason why these timers are called soft timers (processing is not synchronized with the hardware timer tick). 
 Happy learning :-)

How single clock frequency of laptop/mobile phone is divided as per frequency requirement of its individual component ?

In general, your laptop would be operated at 2.2--2.4GHz or your mobile phone could be operating at approx. 1.6GHz . Does every hardware of your laptop/mobile phone operate at said frequency or only portion of it? Ever wondered how your entire laptop/mobile phone hardware operate at one given frequency ?

Generally, only 2% of laptop hardware operates on the said frequency. Since many section of hardware need to interact with humans (ex: display, keyboard etc.), who are too slow compares to motherboard (screen refreshes at 60Hz, keyboard works in KHz, USB works in MHz, etc.), there performance is much limited compared to motherboard. This generates the need to different clock frequency for different hardwares due to their varying operating frequency.

To get this, actual clock originated from oscillator is fed to Programmable Interval Timer (PIT), which in turn, activates many hardware timers of PIT. With every rising/falling edge in input clock from coming from oscillator to PIT, PIT gets triggered and it caused a tick in its individual timers (associated with different hardware with varying frequency requirements). To get varying frequency, appropriate values need to be loaded in individual timer register of PIT.

Fixed block memory allocation is preferred than dynamic memory allocation during memory management of RTOS. Why?

Three top reasons:

 1) In fixed block memory allocation, size of allocated memory (number of blocks and size of each block) is known to compiler and user (ex. Array[100]). So once a process completes job, allocated memory blocks are released completely If Embedded system uses dynamic memory allocation, it may not free up all the allocated memory in specified order and some portion of memory is lost. This memory loss may add up and cause huge loss to system with small RAM memory (ex. 8051, 128 Bytes)

2) Embedded system cannot afford to run De-fragmentation tool to free fragmented memory since this may cause to shut down the system (during RAM fragmentation) which may lead to catastrophic results.

3) Dynamic memory allocation brings non-deterministic behavior of system since time taken for memory allocation cannot be decided before-hand (varies by different memory block size) and this is not accepted in Embedded systems. 

Sunday, 3 April 2016

Role of capacitor in Reset circuit of micro-controller.

Hi


Lets  understand the role of capacitor in reset circuit of power-on reset. In fig1,initially,when +5V is applied to capacitor, one plate of capacitor gets charge accumulated whereas other plate is deprived of charge. This charge imbalance generates potential across capacitor plate which makes current flow in capacitor and capacitor acts as short circuit. This state of capacitor makes micro-controller reset (since RESET in 8051 is active high) at power-on of system. After some t+ time,other plate of capacitor also gets equal amount of charge,thus potential  drop  between plates vanish which stops any current flow through capacitor and capacitor is called fully charged.At this stage, capacitor works as open circuit to the current coming from +5V supply.

But the real question is what is the role of resistor in reset circuit ?

The resistor available in this circuit is also called as pull down resistor. When the capacitor is fully charged, since it acts as open circuit, the charge accumulated on RESET pin need a discharging path, which is given by this pull down resistor. The sole purpose of pull down resistor is to pull down the RESET pin to GND when it is not connected to +5V such that state of RESET pin could be defined at any point of time.

In fig2, simply by connecting switch across capacitor, we create a bypass path for the current coming from +5V, such then when needed RESET pin can be activated as per requirement (even though capacitor acts as open circuit due to  its fully charged state) and make the micro-controller reset.

Happy learning :-)


Saturday, 2 April 2016

Accessing raspberrypi with static IP address using Ubuntu 14.04


To create static IP, edit file in Raspbain OS so that we can get an access to laptop screen by connecting the raspberry pi to projector using HDMI-to -VGA converter or TV with HDMI enabled option. 
Step 1:  Editing /etc/network/interfaces in raspbain OS to, 
===========================
auto lo
iface lo inet loopback
iface eth0 inet static
address 10.42.0.2
netmask 255.255.255.0

and at the same time, my laptop's /etc/network/interfaces looks like this
auto lo wlan0

iface lo inet loopback


Note how the IP address on the eth0 interface is  now 10.42.0.1. This implies that the Linux PC is  basically  acting as a router between the 10.42.0.0 network ( really only a point to point network ) on which the RPi  and eth0 are attached, and the 192.168.0.0 network, which is attached to the internet & PC  via the wlan0 interface. Also note that the mask for the 10.42.0.0 network is 255.255.255.0 . This means that the IP address of the RPi is somewhere between 10.42.0.2 & 10.42.0.254.  To find the exact address we can use nmap  “sudo nmap -sP 10.42.0.2-254″. In my case, nmap reported that the my RPi has an IP address of 10.42.0.33 (Figure 6). If nmap is not installed, you can easily install it with “sudo apt-get install nmap“.
abhi@linux:~$ sudo nmap -sP 10.42.0.2-254

Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-24 00:19 IST
Nmap scan report for 10.42.0.33
Host is up (0.00054s latency).
MAC Address: B8:27:EB:3E:64:DE (Raspberry Pi Foundation)
Nmap done: 253 IP addresses (1 host up) scanned in 22.15 seconds
abhi@linux:~$ ssh pi@10.42.0.33


you may need to re-start network namager: $sudo service network-manager restart
you can also use putty in ubuntu if needed.

Type command "$ssh pi@10.42.0.33" on the laptop, pi here is my username, and 10.42.0.2 here is RPi's IP address, then enter my password (raspberry, default password), and I finally have a direct connect to my RPi with my laptop(ubuntu 14.04).

$sudo raspi-config
From the raspi-config menu, first select “8 Advanced Options” -> “A5 Update” & hit enter. This will update the raspi-config tool to the latest version.
  • The Raspbian image is designed to expand into 2GB space on your SD card. This means that if you are using a larger SD Card, say 4GB or 8GB, the additional space is not part of the root file system partition.  To use all the space on your SD card  select “1 Expand Filesystem” and hit enter. This will expand the root file system partition to fill the entire SD card. The actual partition expansion will happen on reboot.

    Once at the RPi prompt shown after reboot, type “sudo apt-get updatefollowed by “sudo apt-get upgradeor alternatively we can do both at the same time “ sudo apt-get update && sudo apt-get upgrade.



     

 

How to connect raspberry pi with Ubuntu 14.04 using dynamic IP (via dhcp server) ?

Connect raspberrypi to Ubuntu 14.04. Assuming you have installed gnome-desktop.
Go to Wifi settings --> Wired connection --> look for IP address (if raspberrypi is connected to laptop with Patch cable and board is powered on)

install nmap in Ubuntu 14.04 using command $sudo apt-get install nmap

Use command on Ubuntu host $ sudo nmap -sP 10.42.0.2-255 (IP address 10.42.0.2 selected from the address retrieved from wired settings)

you may get message like


Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-24 00:19 IST
Nmap scan report for 10.42.0.33
Host is up (0.00054s latency).
MAC Address: B8:27:EB:3E:64:DE (Raspberry Pi Foundation)
Nmap done: 253 IP addresses (1 host up) scanned in 22.15 seconds

 Now, dynamic IP address which is produced by dhcp server of raspbian OS is 10.42.0.33 (in this case)

now use terminal to ssh the raspberry pi using $pi@10.42.0.33
default password is : raspberry

Now, you should be able to access shell prompt of raspberry pi

Accessing laptop screen for Graphical display using Raspbeery pi on Ubuntu host


Follow these steps for Ubuntu host:
Step 1: Install VNC

Log in to the Raspberry Pi, and setup VNC for remote access. First we need to install the VNC server:

$sudo apt-get install tightvncserver

Step 2: Start VNC server on the Raspberry Pi. Adjust the geometry parameter to your desired display size.

$vncserver :1 -geometry 1024x600 -depth 16 -pixelformat rgb565

Step 3: You will be prompted to create a password for VNC login. Once you create your password, you should see a line on terminal
New ‘X’ desktop is raspberrypi:1

Step 4: If it is already running, previous line would not appear so you must kill it using 
 
$vncserver -kill :1” and again try !!

Step 5: Back on the Ubuntu (host) machine, install the VNC viewer client:

$sudo apt-get install xtightvncviewer

Then connect to the running VNC server:

$vncviewer 10.42.0.2:5901



Step 6: To stop the VNC viewer, just close the application. To stop the VNC server, issue the following command (on the Raspberry Pi):

$vncserver -kill :1