RSS

Monthly Archives: October 2011

Free Art !!!!

Hey everyone,

Till my 9th std. i never believed that i could do anything worthwhile in arts.That year my dad bought me a PC and i started off with photoshop.It was not out of interest but out of boredom.But then i got addicted and have been doing something or the other with it.During my engineering course i ve used this knowledge of the wonderful software to design small stuff like T-shirts , banners, certificates,etc..A year ago my senior and a very good friend Ashwith introduced me to Fedora and with it i was introduced to a whole set of new softwares which i found first of FREE!!! and very versatile and easy to use.i ve stopped using Photoshop now.The software i use are

I have learnt Inkscape to a certain extent and it continues to  surprise me with what can be done with 150mb of software.Compare this with 1gb of Ps.the other tools are next in my list to learn.The learning materials for these are quite a lot!!!! with documents to videos theres  there is everything we need to learn.For Inkscape i refer to the SCREENCASTER.HEATHENx.Excellent video tutorials are provided on using inkscape and also combining it with the other softwares.Also CHRISdesign has some amazing designs.SO with this i hope you are kind of wanting to try those softwares too.if you do and create some designs please do send me link to the image or the model .thanks for reading..Have a nice day 🙂

 
Leave a comment

Posted by on October 23, 2011 in Flip flop, Flop, Free Art

 

Clocks and MSP430

hi there everyone,

in this tutorial let us check out the all clocks that msp has got to offer us.After studying 8051 and comparing that to controllers like msp and AVR makes me wonder how much development has taken place over the years.The 8051 controller had just one clock.It was external with maximum range of 16Mhz.If it failed then the controller would fail.So what makes msp better.It has 2 built in clocks and one external.Some have a provision for 2 external clocks and th series 5xx and 6xx have dedicated clock built in for Real time Clock facility.When i first read through i was wondered.What do you do with all these clocks?Do we really need it?

So I read through and yeah we do  need it whn we are thinking of very low power consumption.The MSP430 has usually 3 clock sources.

  1. LFTXT1      or   External low frequency oscillator (usually 32768 Hz but can have a max of 16Mhz.)
  2. DCO            or   Internal Digitally Controlled Oscillator stabilized with Frequency Locked Loop.
  3. VLO            or   Internal  Very Low Power Very Low Frequency Oscillator.

Some of the controllers have a XT2 oscillator which is a external high frequency oscillator.And as mentioned the 5xxx and 6xxx series have a REFOCLK which is stabalized 32768Hz clock internal to the chip to be used in place of the LFTXT1.It consumes lesser power than the LFTXT1.

These Clocks source 4 Clock signals.They are

  1. MCLK       or    Master Clock.
  2. SMCLK     or   Sub-Master Clock.
  3. ACLK        or   Auxiliary Clock.
  4. ACLKn      or  Auxiliary Clock divided by n.

The different registers used to modify the Clocks are shown below.These were taken from the user guide provided by ti.


The Master Clock signal is Used to source the CPU.So the speed of the CPU depends on the MCLK and this signal is switched off during LPM0.By default in the absence of External crystal the DCO sources the MCLK.

The DCOCTL,The range select bits in BCSCTL1 and BCSCTL2 are used to configure the MCLK.

Now let us see how to control the DCO frequency.The DCOx and RSELx are together used to vary the DCO frequency from about few hundreds of hertz to 16Mhz.The MODx bits are used to obtain the intermediate frequency.The SELMx and DIVMx are used to select the source for the MCLK signal and division factor.The following code encompasses the above.

#include "msp430x20x2.h"
int main (void)
{
  WDTCTL=WDTPW+WDTHOLD;               //hold watchdog
  P1DIR=BIT0+BIT6;                   
  P1IE=BIT3;                          //enable interrupts
  int i=0;
  _EINT();            
  while(1)
    {
    for(i=0;i<30000;i++);             //toggle LED1 at PIN 0
    P1OUT^=BIT0;
    }
}

#pragma vector=PORT1_VECTOR           //ISR for PIN 3
__interrupt void pin3 (void)
{
static int range=0,dco=0;             
dco++;                                //increment the dco step
dco=dco%8;
range=range%3;
switch(range)                         // step up range every 8 clicks of S2 switch
  {
  case 2:BCSCTL1=RSEL0+RSEL1+RSEL2+RSEL3;
         break;
  case 1:BCSCTL1=RSEL0+RSEL1+RSEL2;
         break;
  case 0:BCSCTL1&=~(RSEL0+RSEL1+RSEL2+RSEL3);
         break;
  }

switch(dco)                         //step up speed every click
  {
  case 0:DCOCTL&=~(DCO0+DCO1+DCO2);
         break;
  case 1:DCOCTL=DCO0;
         break;
  case 2:DCOCTL=DCO1;
         break;  
  case 3:DCOCTL=DCO0+DCO1;
         break;
  case 4:DCOCTL=DCO2;
         break;
  case 5:DCOCTL=DCO0+DCO2;
         break;
  case 6:DCOCTL=DCO1+DCO2;
         break;
  case 7:DCOCTL=DCO0+DCO1+DCO2;         //increment the range
         range++;
         P1OUT^=BIT6;
         break;
  }
P1IFG&=~BIT3;
}

The above graph explains the variations in the DCO frequency.The above code also checks for the RSEL values and DCO values as in graph. Every time the RSEL value increments the green led toggles and the red led is a indicator of the speed of CPU as the LED is toggled by a delay loop f(or loop) which uses the CPU Registers to count .As i dont have a CRO I’ve limited the code to just the 3 values of the RSEL .Please do check if there are any variations for other values.There are modulation bits which allow us to further vary the frequency.I’ll be putting up separate post on it sometime later.Now let us see how to vary the source for the MCLK from DCO to  other sources and to change the division factor.

#include "msp430x20x2.h"
void main()
{
WDTCTL=WDTPW+WDTHOLD;
P1DIR=BIT0+BIT6;
P1OUT=0X00;
P1IE=BIT3;
_EINT();
int i=0;
while(1)
{
for(i=0;i<32000;i++);
P1OUT^=BIT0;
}
}
//------------------------------------------interrupt isr
#pragma vector=PORT1_VECTOR
__interrupt void pin3(void)
{
static int source=0,divide=0;
divide++;
divide=divide%4;
source=source%3;
switch(source)
{
case 0:BCSCTL2&=~(SELM0+SELM1);         //Select DCO
        break;
case 1:BCSCTL2=SELM1;                   //select XT2 else LFTXT1 or VLO
        break;
case 2:BCSCTL2=SELM0+SELM1;             //select LFTXT1 or VLO
        break;        

}
switch(divide)
{
case 0:BCSCTL2&=~(DIVM0+DIVM1);         //Divide the source / 1
        break;
case 1:BCSCTL2=DIVM0;                   //divide by 2
        break;
case 2:BCSCTL2=DIVM1;                   //divide by 4
        break;        
case 3:BCSCTL2=DIVM0+DIVM1;             //divide by 8
        source++;
        P1OUT^=BIT6;
        break;
}
P1IFG&=~BIT3;
}

So in the above code toggling of the green led is an indicator of the change of source and the red light toggle indicates the frequency due to change in the division factor.The same applies to the SMCLK and ACLK too.The SELSx and DIVx bits are used to change the source and the division factor for the SMCLK.The DIVAx bits are used for the ACLK.The default clock for ACLK in case the external oscillator is not present is VLO.To check the frequency of the ACLK ,SMCLK and MCLK the following code can be used.The ACLK and SMCLK are usually connected to the GPIO’s in case of the launchpad it being the PIN0 and PIN5.The MCLK can be checked by a delay loop.

#include "msp430x20x2.h"
void main()
{
WDTCTL=WDTPW+WDTHOLD;
P1DIR=BIT0+BIT5+BIT6;
P1SEL=BIT0+BIT5;            //Select the secondary pin funcitons i.e ACLK SCLK.

while(1)
{
P1OUT^=BIT6;
}
}

The Frequency will have to be checked on a CRO as the Flicker on the led too fast to see.Also there are default values stored in the memory of the chip which can be used to configure the controller to predefined frequencies.These are given in the library file as CALDCO_16MHZ,CALBC1_16MHZ,.. etc.These can be directly entered on the code to get the desired calibration.Please leave a comment if there is something I can help with or if there is an error.I hope this blog was useful.Thank you for reading.Have a nice day 🙂

 
Leave a comment

Posted by on October 5, 2011 in Flip, MSP430 Tutorials

 

Tags: ,

Image

Muninagar : My first/last Intro trek

hey guys,

yesterday i.e, 2nd October 2011 all the machas and machis of BMSCE set out for a small trek to Muninagar .Around 170 students took part in this annual trek where the first year students get to meet the rest of the college and go together on a trip.I had been to the same place for the intro trek during my first year.So it was nostalgic to be back.The day started at 7 when everyone gathered at the Katte for breakfast.After a round of Idly vadas and the warm up exercises (my favourite) we set off in three buses.Three lecturers also accompanied us to the place and am sure they had great time too.I got to meet the group of students from the international hostel.They had come to BMS from SriLanka ,Qatar ,AbuDhabi , Bangladesh and others i cant remember.Had a great time in the bus journey too. Thanks to the juniors.

We reached the place at about 10.30 i think.We started to trek with an expectation to find elephants which according to the locals had crossed the place the previous night.We were given instructions By our dear BM (a.k.a Harsha) as to what we have to do just in case.Then we set out.All the way up we only found elephant shit but no elephants .It was really a beautiful place and i recommend all those who have not gone to go.Thank you for reading :)have a nice day

This slideshow requires JavaScript.

 
Leave a comment

Posted by on October 3, 2011 in Flop

 

msp’s watchdog

hey guys

have been  fooling around with the msp4305438 board so couldn’t post for a long time… so I’ll be posting the tutorial on watchdog timer today.This is something which bugged me a lot when i first started with msp, which i feel is really stupid considering the fact that it was really simple.So what is a watchdog timer.We can imagine it as a small hardware which will kick the controller if at all the controller hangs up.It basically resets the controller when it is activated.

Principle

The watchdog timer has a 16 bit timer which counts from 0x00 to 0xffff.When it hits the max value of oxffff the watchdog resets the controller.Our job is to prevent this from happening and we’ve to keep resetting the timer.If the code hangs then the timer is not reset and the watchdog timer overflows and resets the timer.

Timer Mode

The watchdog can also be configured to be a timer which provides interrupts instead of the reset of the controller.But the time delay can be varied to a great extent.It can be varied by varying the clock sources itself or varying the the division factors.

Registers

The watchdog can be configured by using the WDTCTL register.The Upper 8 bits of the WDTCTL has to be written with 0x5A .This is the password protect feature of the watchdog. A failure to write this or writing anything to this nibble will cause a access violation and reset the controller.The lower 8 bits are the control bits and are given as follows.

The Bit definitions are as follows:

WDTHOLD => disables the watchdog timer when the bit is 1.

WDTNMIES =>selects the triggering edge for the non maskable interrupt on RST/NMI pin. 0 indicates a rising edge and a 1 represents a falling edge.

WDTNMI  =>enables the nmi function on the RST/NMI pin.

WDTTMSEL =>selects the timer mode for the watchdog when the bit is 1.

WDTCNTCL => watchdog counter clear resets WDT counter.When the bit is set the counter is reset and the bit is reset immediately.

WDTSSEL => selects the source for the watchdog timer. 0 selects the SMCLK and 1 selects the ACLK.

WDTISx => The division factor for the clock source.

  1. 00 => clk source / 32768
  2. 01 => clk source /8192
  3. 10 => clk source /512
  4. 11 => clk source / 64

There are two other registers which are used with the watchdog.IE1 and IFG1.These have the interrupt enable bits and the interrupt flags for the corresponding sources.

Program Watchdog Mode

Now let us first learn to use the watchdog timer in watchdog mode (WDTTMSEL = 0).

Usually we begin the programs by entering the following code.

WDTCTL=WDTPW+WDTHOLD;

Here we are  first writing the password by writing WDTPW which is a macro of value 0x5A , then we are setting the WDTHOLD bit to stop the watchdog.This is usually done at the time of debugging as the watchdog feature is not required.Now let us assume that we’ve finished the debugging of a certain code and that we are adding the watchdog timer .How do we do it? The following code explains it.Please read through.

#include "io430.h"
int main( void )
 {
 // Stop watchdog timer to prevent time out reset
 WDTCTL = WDTPW + WDTHOLD;
 P1DIR=BIT0+BIT6;
 P1OUT=BIT0;
 int i=0;
 while(1)
 {
 for(i=0;i<32000;i++);
 P1OUT^=(BIT0+BIT6);
 }
 return 0;
 }

The above code stops the watchdog timer and blinks the leds.Now lets us have the watchdog on and see the required changes

#include "io430.h"
 int main( void )
 {
 // Stop watchdog timer to prevent time out reset
 //WDTCTL = WDTPW + WDTHOLD; // doNOT DISABLE the watchdog
 P1DIR=BIT0+BIT6;
 P1OUT=BIT0;
 int i=0;
 while(1)
 {
 for(i=0;i<32000;i++)
 {
 WDTCTL = WDTPW + WDTCNTCL; //keep clearing the counter to prevent the reset
 }
 P1OUT^=(BIT0+BIT6);
 }
 return 0;
 }

In the above code we have to keep clearing the counter at approximately 32ms i.e, the time required by the counter
to count to oxffff with SMCLK as the source.So we have to keep clearing the counter based on the program written.
Since the code I’ve written has only a for loop i’ve added the clearing line in it.

Timer Mode

Now let us use the watchdog as a timer to blink an led.For this we’ve to set the WDTTMSEL bit which enables the timer mode in the WDTCTL register.Then we’ve to enable the interrupt in the IE1 register and right the required routine.The following code is an example.

#include "msp430x20x2.h"
int main( void )
{
  WDTCTL = WDTPW + WDTTMSEL;           //select the timer mode
  IE1=WDTIFG;                          //enable the interrupt
  P1DIR=BIT0+BIT6;
  P1OUT=BIT0;
  _EINT();
  while(1);
}
#pragma vector=WDT_VECTOR
__interrupt void wdttimer(void)
{
P1OUT^=BIT0+BIT6;
IFG1&=~WDTIFG;                          //clear the timer interrupt flag
}

Now lets vary the clock sources and the division factor for the watchdog.I’ll write a program to use the SMCLK and use various division factors and a program to change the clock sources.The ACLK can be used by setting the WDTSSEL bit.

// WDT with SMCLK as Source and varying the division factors.
#include "msp430x20x2.h"
#define WDTCONFIG (WDTPW+WDTCNTCL+WDTTMSEL) //configure wdt in timer mode and clear the count register

int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTTMSEL + WDTCNTCL;
  IE1=WDTIFG;
  P1DIR=BIT0+BIT6;
  P1OUT=BIT0;
  P1IE=BIT3;

  BCSCTL2=DIVS_3;       // slow down the smclk by division to make the blinking slow.details in clock
                        // module tutorial

  _EINT();
  while(1);
}
#pragma vector=PORT1_VECTOR
__interrupt void pin3(void)
{
static int i=0;
i++;
i=i%4;
switch(i)
{
case 0: WDTCTL=WDTCONFIG;   //source divided by 32768
        break;
case 1: WDTCTL=WDTCONFIG+WDTIS0;   //source divided by 8192
        break;
case 2: WDTCTL=WDTCONFIG+WDTIS1;   //source divided by 512
        break;
case 3: WDTCTL=WDTCONFIG+WDTIS0+WDTIS1;   //source divided by 64
        break;       

}
P1IFG&=~BIT3;
}
#pragma vector=WDT_VECTOR
__interrupt void wdttimer(void)
{
P1OUT^=BIT0+BIT6;
IFG1&=~WDTIFG;
}

In the above program the Switch s2 is used to change the speed of the blinking by varying the division factor for the Source of the watchdog which in this case is SMCLK. I’ve slowed down the frequency of the SMCLK by dividing the source signal to it which I’ll discuss in my next tutorial on clocks.Basically the blinking will be slow and noticeable only for the first two clicks of the switch.Later the blinking is too fast to notice.It can be seen using a CRO.

In the program i use the WDTIS0 AND WDTIS1 bits to set the division factor which is as follows.

WDTIS0            WDTIS1

WDTIS_0 =>        0                          0             SOURCE DIVIDED /32768

WDTIS_1 =>         1                           0            SOURCE DIVIDED / 8192

WDTIS_2 =>         0                          1             SOURCE DIVIDED /512

WDTIS_3=>         1                           1            SOURCE DIVIDED /64

So thats about it for now.Also check out the code examples for all the modules in the TI website.The WDT+ feature are explained.Thank you for reading.Have a nice day.

 
2 Comments

Posted by on October 3, 2011 in Flip, MSP430 Tutorials

 

Tags: , ,