9 Jul 2012

LocK Bits in detail

LOCK BITS :

          Before we discuss these bits lets take a practical example in day to day life until now we are dealing with the byke example right . we discussed fuses are like gares which are used to ride the microcontroller and in the same way you protect your byke with a Lock right to protect it from being stolen . In the same way you have your developed a project and now you burn this code to the microcontroller there are chances that someone can hack your code from it right so in order to protect your code you lock your microcontroller after all the code is written one time . so that others cannot steel your code.

You have different combination of locks over here for that You refer the data sheet MEMORY PROGRAMMING section you will mostly find this information at the beginning itself ok.

Real time scenario:
           Ya assume that you wrote a bootloader . Now your bootloader is writting your application section from bootloader section so while writting you should be careful that it never erases or never writes into the bootloader section so you need to lock that perticular section in order to disable the access to that section ok. Now By using the lock bits you can do this protection .

Ya i will explain you the lock bits in atmega8 ok......

Same way as fuse bits here also
0 --> Programmed
1 --> Unprogrammed

Lock bits are 6 in number
     ------               Reserved
     ------               Reserved
1. BLB12   --      1
2. BLB11   --      1
3. BLB02   --      1
4. BLB01   --      1
5. BL2       --      1 
6. BL1       --      1

Selecting the BL2  & BL1 is based on your requirement the below values you use
                        1          1          -->    No memory lock features
                        1          0          -->    Disable programming Flash and EEPROM
                        0          1          -->    Disable programming and verification of Flash and EEPROM in any mode.

In the same way comes
BLB02 &BLB01 (APPLICATION PART)
    1             1            -->   No restrictions for SPM or LPM for accessing APP sec.
    1             0            -->   SPM NO write to APP sec.
    0             0            -->   1. NO write to APP sec by the SPM.
                                         2. LPM executing from the bootloader section is not allowed to read from APP sec.
                                         3. If Interrupt vectors are placed in BOOT  sec interrupts are disabled while executing from the APP section.
    0             1            -->    only ( 2 ) & ( 3 ) points are enabled.   

BLB12 & BLB11  (BOOTLOADER PART):
    1             1            -->   

      



LoW FuSe bits

LOW FUSE BITS:

     As i explained what are the uses of fuses and how they are to be used now we will only discuss what LOW FUSE BITS are used for .


         FUSES            DEFAULT settings
     1. BODLEVEL   ----    1
     2. BODEN         ----    1
     3. SUT1             ----    1
     4. SUT0             ----    0
     5. CKSEL3        ----    0
     6. CKSEL2        ----    0
     7. CKSEL1        ----    0
     8. CKSEL0        ----    1

BODLEVEL  --   This fuse bit we set when we need the brown out detector. Like you have a application which should Reset when the input voltage is less than 4.5 V and another as when ever the voltage goes below 2.7 V it should get reset .

So, the first requirement can be achieved without enabling this fuse you get the trigger level of 4.5V and for second requirement you need to enable or program the fuse to '0' so that trigger level changes to 2.7V (this is used when you need you circuit to work even you have voltage less than 5 . In some conditions it require .

BODEN        - - This fuse bit we set for enabling the Brown Out Detector .

SUT1  ,  SUT0   :
                       This by default setted to the maximum startup time. In order to change the startup time we use them. There are different levels of startups you should refer datasheet in clock source section . Based on your application you should program these bits

CKSEL3 , CKSEL2, CKSEL1, CKSEL0 :

                       These fuses are used for selecting the frequency of the clock at which it should run . For different frequencies these fuses changes same as i said garing the microcontroller before it starts working. These fuse bits are like gares if you don't gare them properly you may loose your microcontroller or it may not work as you like it to work.

Finally what i mean to tell Read these bits clearly in data before you program it because you may messed up with the fuse setting some time so before setting fuse bits make  yourself  comfortable before you decided to write them on MC . ok

At beginning it looks like it is difficult once when you are some practice you automatically program for what ever you require ok.

Learn them well .........................................

How to work with them in avrdude :   click here

After this will go  to Lock bits which are also important to be discussed  in next tutorial . Link to Lock bits

8 Jul 2012

FuSe Bits and their functionality

Hai.........
Lets discuss about the Fuse bits which are perticularly important in atmega or avr microcontrollers .

Ya i will give some example to understand clearly i know that most of us know bike or car to ride right so lets think you have a bike and you need to ride it that has gares ok so you sit on bike and start it after that in order to move you need to step into bike/car and give your first gare to move the vehicle right in the same there are some conditions to be met in order to run the avr microcontroller . Even though you write program into microcontroller you need to gare it with fuse bits . We should give the clear gares how to work . ok

Now lets come to the atmega8 here you have fuses bits which are
  1. High fuse bits  (8 bits)
  2. Low fuse bits (8 bits)
and there are some other bits named  "EXTENDED FUSE BITS " which are not present in this microcontroller for some controllers with high performance have these bits depending on their working same as having different set of gares for different capacity bikes .

By Default the fuse bits are set to some value. you can check it by using the commands listed in the below 

Here the value 1 indicates the "UNPROGRAMMED"
                         0 indicates  "PROGRAMMED"

High Fuse Bits:
I will give you the high fuse bits which are present in the atmega8
         Bits                            Default values
  • RSTDISBL     -->        1
  • WDTON         -->        1
  • SPIEN           -->         0
  • CKOPT          -->         1
  • EESAVE        -->         1
  • BOOTSZ1      -->         0
  • BOOTSZ0      -->         0
  • BOOTRST     -->          1
So , these are the fuse bits which are called HIGH FUSE BITS.
WDTON   --  This bit is programmed when we use the watch dog timer i.e the watch dog timer doesn't work perfectly if you don't enable this if you are using the predefined library functions.
                   [WATCH DOG TIMER RELATED BIT]
SPIEN     -- This fuse should be programmed when you are using the serial peripheral interconnect protocol and This must be always enabled if you want to communicate through this interface.
               note:  Never ever make this bit unprogrammed until you think you don,t need but you never come to this . I prefer not to touch this bit at all. let this be programmed.
                   [ SPI RELATED BIT]

CKOPT    --  This fuse is used to select whether you need the internal clock or external clock to your microcontroller. In order to understand this clearly you should be clear with clock concept and what bits are related to the clock.
                   [CLOCK RELATED BIT]


EESAVE  --  This is used while EEPROM programming . we think if we just used the EEPROM related registers and dump the values we needed into the eeprom it will store the values right no this concept some what different you should enable the EESAVE gare like gare of a byke and then program the eeprom values into the microcontroller eeprom. ok
So, what  you do is write program and burn the hex file and then set the fuses.

BOOTSZ0, BOOTSZ1:
                     In breif microcontroller has two sections in memory locations
                     1. Application and
                     2. Bootloader section
lets about these things in detail in next coming tutorials .
These fuses are used to configure the size of the bootloader and flash they are specified in the data sheet different microcontrollers have different locations and sizes.
            Bootloader concept is a vast subject so upto to now know this only you can write the flash to itself using it . In this section all store program memory commands are executed  and in application section load program memory instructions are executed i.e: reads the falsh that it it couldn't write to flash are.
   Bootloader section    --- write to flash area of its own
   Application section   ---  Reads the flash and execute the written program .

BOOTRST -- This fuse bit is used for selecting reset position. As i said flash will have two sections . So, Two sections means we can set the RESET position to bootloader or application section. Lets say you need when ever you reset you should activate your bootloader section then PROGRAM this bit else if you want your application itself to execute after the RESET is pressed then it jumps to the location of application section 0x0000 where your application program is written.
             Reset vector to bootloader section  ---  0   (programmed)
             Reset vector to application section  ---  1  (unprogrammed)
How to burn the fuse bits: click here

You can Read next tutorial for the Low fuse bits