Posts

Showing posts from May, 2014

Hello World Device Driver

hello_world.c: #include<linux/module.h> #include<linux/init.h> MODULE_LICENSE("GPL"); MODULE_AUTHOR("EMBEDDED GURUJI"); static int hello_init(void) {       printk("Hello World\n");       return 0; } static void hello_exit(void) {      printk("Bye World\n"); } module_init(hello_init); module_exit(hello_exit); Makefile: obj-m := hello_world.o KERNELDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) all :     $(MAKE) -C $(KERNEL) M=$(PWD) modules clean:    $(MAKE) -C $(KERNEL) M=$(PWD) clean Now we will understand the code line by line #include<linux/module.h> #include<linux/init.h> These header files contains the definition of the module_init() and module_exit() functions. MODULE_LICENSE("GPL"); MODULE_LICENSE() informs the kernel the license used by the source code,which will affect the functions it can access from  the kernel.MODULE_LICENSE("

How Diodes works

Image
A diode is the two-terminal semiconductor device which allows the current to flow only in one direction and blocks the current that flows in the opposite direction. Symbol of the diode:    A diode is made by connecting a part of N-type material to P-type Material,N-type material has excess of negative charged particles(electrons) whereas P-type material has excess of positive charged particles(holes). As there are more holes in P-type and more electrons in N-type whenever both  are connected,holes will move from P-type to N-type and electrons will move from N-type to P-type and the holes and electrons combine and form depletion layer.In the depletion region , semiconductor will return back to the insulating state. To remove the depletion region,you have to apply enough potential which will make the electrons will move from  N-type to P-type and holes will move P-type to N-type.To do this,connect the N-type to of the diode to the negative terminal of the bat

msp430 embedded c programming part2 - configuring DCO

Image
Introduction : MSP430 Clock system has three clocks which provides different frequencies . Need of three different clocks not only one is power consumption. That is we will use the clock with lowest frequency when we want to save the power and we will use the clock with highest frequency when we want high speed. The three clocks present in MSP430 are 1. MCLK(Master Clock) : Used by CPU and few peripherals such as ADC. It is  a high frequency clock but can be configured to provide a low frequency 2.SMCLK(Sub-Main CLock) : Distributed to Peripherals. It can be the same frequency as MCLK,or different depending on the application 3. ACLK(Auxiliary CLock) : Basically it is a low frequency clock, used for peripherals. There are four Sources for these clocks 1.LFXTCLK: As the name implies it is to use with low frequency crystal.A 32khz can be connected to msp430 for low power operation 2 XT2CLK:  This is not available in every device.it is to use with a second crystal 3.DCO

msp430 embedded c programming part 1 --- Blinking a LED

/*   Blinking a LED which is connected to port 5.5 of the MSP430F2618 */ //step1 : include the microcontroller header file #include <msp430f2618.h> int main(void) { //step2 :  stop the watchdog timer,otherwise it will reboot the system if the timer fires WDTCTL=WDTPW+WDTHOLD; //WDTCTL is  a 2 byte register in which the least 8 bits are used for controlling the watchdog timer and 8 most significant bits are for setting the password for the watchdog timer as it is password protected.Setting the 7 lsb bit will stop the watchdog timer which is the value of WDTHOLD(0x0080) and the password for the Watchdog timer is 0x5a which WDTPW(0x5a00) has in it //step3: setting up the pins /* There are basically 5 registers for each port PxSEL -> Select the functionality PxDIR -> Selecting the direction of pin whether it is input(0) or output(1) PxIN  -> Input Register of the port PxOUT -> Output Register of the port PxREN -> Selects if

Interfacing an LED to a microcontroller

Image
First identify which is the anode and cathode,the shorter leg is the cathode(negative) and longer leg is anode(positive). Now we will see how to interface  a LED to a microcontroller. We can do this in two ways. Method 1: Connect the anode to a microcontroller GPIO pin and cathode to ground with a resistor connected between anode and the microcontroller pin , to reduce current flowing into the led . The value of the resistor depends on the amount of the current that can be supported by the LED.In order to ON the LED we have to send a Logical High from the microcontroller pin. Method 2:  Connect the cathode to the microcontroller GPIO pin and anode to the 5V with a resistor i between. Now we have to send a logical LOW from the microcontroller pin for making the LED glow

What is Electric Field

Image
Forces come in two categories: Contact Forces and Non-Contact Forces. Contact Forces are quite usual and customary to us. Electric Force and Gravitational Force are examples of non-contact forces.Non-contact forces or Action-at-a-distance forces requires a more difficult explanation. Example of Non Contact force is that the Moon has a gravitational field around it,and if we get close to the moon,it will pull us down to its surface. Scientists understood why forces acted the way they did when objects touched.The idea that confused them was forces that acted at a distance without touching them.To help them explain what was happening they used the idea of "field". They imagined that there was an area around the object,and anything that entered would feel a force. An electric field describes the area near any electrically charged object. It is also called an electrostatic field.Any other charge that enters the area will feel a force. A normal field is a vector,and is re

Arduino 2 - Serial Communication between Arduino and PC

Image
This post is for serial communication between the Arduino and PC connected through the USB Cable Parts Required: 1.Arduino Uno 2. USB Cable A-B Sketch: //one-time initialization void setup() {      Serial.begin(9600); //setting the baud rate to 9600 } //infinite loop void loop() {      Serial.write("Hello World"); //writing Hello world on the console      delay(3000); //delay of 3 sec } To check the output , go to Tools and click on SerialBoard Monitor

Arduino-1 Blink LED

Image
This post consists of blinking an LED Present on the Arduino Uno Board. On the Arduino Uno Board there is an yellow LED labelled with L on the Board. Parts Required: 1.Arduino Uno 2. USB Cable A-B Sketch: const int LED=13; void setup() {       pinMode(LED,OUTPUT); //setting the pin 13 as output on which the L LED is connected } void loop() {      digitalWrite(LED,HIGH); //writing one on the pin to make the LED ON      delay(1000);//1 sec delay      digitalWrite(LED,LOW);//writing zero on the pin to make the LED OFF      delay(1000);//1 sec delay }