Jump to content
43oh

light alarm clock project using msp430


Recommended Posts

After many hours of working on displays,buttons, menu systems and so on, here is my result work.

(The clock somehow lags significantly up to 5 minutes in about 6 hours) But i haven't try the new RTC library yet. Maybe that fixes this issue. I have to fix that and also i will make the PCB and external voltage supply for the launchpad etc. The system works as i want for now. I can set the clock (standalone), set the alarm time, set the light modes (i made three modes: light fades in 10 minutes earlier gradually, 20 minutes and 30 minutes earlier)

buzzer works if you set it at just at the alarm time.. i made some modes but i wish i could use some melodies :smile: (but i am too tired of working at the same project for a long time now : ))

 

it also shows current temperature and if it is out of your desires min and max. it says it is COLD or HOT on the main loop. You can set the min and max temperature values in the settings menu. It shows the alarm time as well on the main loop, if alarm is set ON.

 

I have used three buttons for this project. up/down buttons and a set button. 

One last note is that finished work will have three 1W power leds.

 

Here is the video of my work,

Sirri

 

Critics are welcomed  :smile:

 

 

edit: the setup photo is added ^_^

 

 

 

post-30056-0-70216800-1359746428_thumb.jpg

Link to post
Share on other sites
  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

After many hours of working on displays,buttons, menu systems and so on, here is my result work. (The clock somehow lags significantly up to 5 minutes in about 6 hours) But i haven't try the new RTC

@roadrunner84 tone() and notone() are standard Arduino functions. They are part of Energia. They can be seen in the Energia's library folder

That's a huge slab of code!   I have some questions (although I cannot read your comments) (((sayi%1000)%100)%10)%1) a number divisibe by 10 is also divisible by 100 or 1000 (as 100/10 is a round

Posted Images

Nice! You should have turned on the room lights just for a minute, so we could see the hardware setup too :smile:

Yeah, i have added a photo ; )

 

it looks like your multiplexing is leaking and there are shadowing segments. they became recognizable when u turn the lights (room light) down. u may want to look at the sequence when u turn port pins / directions on and off.

You are right. I am not hundred percent happy but for this project i don't have enough patience to correct that anymore.. Lagging clock is much a bigger problem for me now : /

Link to post
Share on other sites


*/

 

modified by sirri

03/01/2013

*/

 

#if defined(__MSP430G2553__)

#else

#error Platform not supported

#endif

 

#include "Thermometer_430.h"

//#include "Airtel.c"

#include "sRTC.h";

#include "legacymsp430.h";

#include "TimerSerial.h";

 

 

Thermometer_430 myThermometer;

//RealTimeClockSec myClock;

RealTimeClock myClock;

 

const int latchPin = P1_2; // Pin connected to Pin 12 of 74HC595 (Latch)

const int dataPin = P1_1; // Pin connected to Pin 14 of 74HC595 (Data)

const int clockPin = P1_0; // Pin connected to Pin 11 of 74HC595 (Clock)

 

const int speakerOut = P2_4; // BUZZER

 

 

 

int i = 0;

int time=0;

int ledbrightness=0;

long termo;

/*

long sayi;

long sayi2;

long t2;

long sayi4;

long sayi5;*/

int sayi;

int t1; // int sayi2;

int t2; // int sayi3

int sayi4;

int sayi5;

 

 

//light alarm and buzzer mode

int lightmode=0;

int buzzermode=0;

int tempermode=0;

int temp_max=26;

int temp_min=16;

int temp_setdurum=2;

int tem1;

int tem2;

 

//---------------------

//alarmlar

int alarmdurumu=0;

int alarmonoff=0;

int b1=6; // int alarm_saat=6;

int b2=0; //int alarm_dakika=0;

int alarm_setdurum=1; // setdurum =0 hour, 1: minute, 2: kay?t yap.

int a1=6; //int aktifalarmsaat=6;

int a2=0; //int aktifalarmdakika=0;

int delay1=10;

int delay2=2;

int n2;

int n1;

int m1;

int m2;

int aktifalarmsaat2;int aktifalarmdakika2;

int aktifalarmsaat_son;int aktifalarmdakika_son2; int aktifalarmdakika_son;int aktifalarmsaat_son2;

 

int ledmode=0;

//--alarm

 

int snz=0;

 

int sayac1=0;

int sayac2=0;

int sayac3=0;

int sayac4=0;

int sayac5=0;

 

int eskisayac1=0;

int eskisayac2=0;

int eskisayac3=0;

int eskisayac4=0;

int eskisayac5=0;

 

 

// saat degiskenleri

int ayar_saat=6;

int ayar_dakika=0;

int ayar_setdurum=2; // setdurum =0 hour, 1: minute, 2: kay?t yap.

// saat degiskeni-------

 

int dig1=P1_3; //1st digit

int dig2=P1_4;

int dig3=P1_5;

int dig4=P2_0;//4th digit

//buttons

const int buttonPin1=P2_2;

const int buttonPin2=P2_3;

const int buttonPin3=P2_1;

//buttons ----

//menu func

int menuanahtar=0;

int menu_setdurum=1;

 

 

//ana loop ayar menusu

int menu_gecis=1;

//power leds

int powerled1=P1_6;

 

int counter=0;

int counter2=0;

int buttonState=0;

int old=0;

int buttonState2=0;

int old2=0;

int old3=0;

int old33=0;

int buttonState3=0;

int buttonState33=0;

//----buttons

 

//blinks

int saatlerblink=0;

int dakikalarblink=0;

 

int anahtar=1;

byte four_digits[4][4]= {

{

0,1,1,1 }

,//ilk dijit a

Link to post
Share on other sites

That's a huge slab of code!

 

I have some questions (although I cannot read your comments)

(((sayi%1000)%100)%10)%1)

a number divisibe by 10 is also divisible by 100 or 1000 (as 100/10 is a round number, so is 1000/10), so you can drop de %1000 and %100 when doing %10 also. Any integer number is divisible by 1, so %1 will alwaysd result in the value 0.

    eskisayac1=millis();
      eskisayac2=millis();
        eskisayac3=millis();
                eskisayac4=millis();
                                eskisayac5=millis();

why are you loading all variables with the result from the same function? In this case you'll execute the function five times, while one time would probably suffice

    eskisayac1=millis();
      eskisayac2=eskisayac1;
        eskisayac3=eskisayac1;
                eskisayac4=eskisayac1;
                                eskisayac5=eskisayac1;

// or even more compact
eskisayac1=eskisayac2=eskisayac3=eskisayac4=eskisayac5=millis();

You're dividing in comparison, but divisions are way more expensive than multiplications.

t2>(a2+(2*(b2-a2)/3))

// instead of dividing by 3, multiply the other side by 3
(t2*3)>(a2*3+(2*(b2-a2)))

// you're doing a certain amount of a2 minus anoter amount of a2
(t2*3) > (a2*3 + (2*b2 - 2*a2))
(t2*3) > (a2*3 + 2*b2 - 2*a2) // a2*3 - a2*2 = a2*1
(t2*3) > (a2 + 2*b2)
// these should all five result in the same outcome, but the last saves you the most code space and the mose clockcycles.

These kind of optimisations can save you a lot of code space, so you could maybe even fit it in a smaller chip or save more power.

h

Link to post
Share on other sites

thank you roadrunner. next time i will try better. right now my biggest problem is in

//************************************************************* ALARM ANI
void buzzerbaslatma(void){

part.

 

below photos show how i have externally powered launchpad (for this project) i will let it "on" for few days to see the accuracy.

 

p.s. (i had to use the unused jumpers of my launchpad and solder it to battery holder cables :/  ( because i don't have those lovely male-male, female-female jumpers :// )

 

post-30056-0-28247600-1360148642_thumb.jpg

post-30056-0-60271700-1360148661_thumb.jpg

Link to post
Share on other sites

Let's de-goto this baby first:

And get code indentation right:

void buzzerbaslatma(void)
{
  while(1){
    buttonState33 = digitalRead(buttonPin3);
    /*if(buzzermode=!0)
    {
      tone(speakerOut, 600);
    }
    else
    {
      noTone(speakerOut);
    }*/

    if ((buttonState33 != old33) &&(buttonState33==0))
    {   
      noTone(speakerOut);
      alarmonoff=0;snz=1;
      for (int jk=0;jk<150000;jk++)
      {
        int jk2=map(jk,0,150000,255,0);
        analogWrite(powerled1,jk2);
        if(jk2==1)
        {
          break;
        }
      }  
      digitalWrite(powerled1,LOW);
      ledbrightness=0;
      return;
    }
    else
    {
      old33=buttonState33;
    }   
    ledyazdir(16,1); //N
    ledyazdir(0,2); // 0
    ledyazdir(0,3); // 0
    ledyazdir(0,4); // 0
    switch(buzzermode)
    {
      case 0:
        noTone(speakerOut);
        break;
      case 1:
        tone(speakerOut, 300,500);
        break;
      case 2:
        tone(speakerOut, 600,500);
        break;
      case 3:
        tone(speakerOut, 600,500);
        break;
    }
    //tone(speakerOut, 600);
    digitalWrite(powerled1,HIGH);
  }
}

You write "else { old33=buttonState33; }", why do you keep track of old33? If the condition is true, you will jump out of the function anyway, so you're guaranteed that old33 is 1, given that the loop is executed at least once.

 

I totally forgot to ask? What is the problem you have with this code?

Link to post
Share on other sites

i guess you are right about it. the error is probably there. i will have to wait for tomorrow evening to try it though :/

 {   
      noTone(speakerOut);
      alarmonoff=0;snz=1;
      for (int jk=0;jk<150000;jk++)
      {
        int jk2=map(jk,0,150000,255,0);
        analogWrite(powerled1,jk2);
        if(jk2==1)
        {
          break;
        }
      }  
      digitalWrite(powerled1,LOW);
      ledbrightness=0;
      return;
    }

 

Above i want to let the powerled1 to fade out and finally turn it off after some time. The buzzer and powerled1 is fully turned on, unless buttonPin3 is pressed.

Link to post
Share on other sites

But that is the behaviour as visible in your movie in the start post, what is wrong then? I can't find the definition of map( in your code, so I suppose it's somewhere else. I'm guessing it maps the range 0 -150000 to 255 - 0 (where 255 is the output when the input is 0 and the ouput is 0 when the input is 150000).

 

Now I'm looking at that, the int is mapped to the native type of the MSP430, which is 16-bit. A 16-bit unsigned integer can hold values between -32768 and 32767, so 150000 is out of that range! You could either change the type of jk to be of the type long (32-bit, so roughly -2million to 2million), or you could let it count from 255 to 0, skip the map() call and introduce a little delay.

// Old code
for (int jk=0;jk<150000;jk++)
{
  int jk2=map(jk,0,150000,255,0);
  analogWrite(powerled1,jk2);
  if(jk2==1)
  {
    break;
  }
}  
digitalWrite(powerled1,LOW);
ledbrightness=0;
return;

// New code
for (int jk=255;jk>0;jk--)
{
  analogWrite(powerled1,jk);
  delay_ms(5); // or any other value that seems to your liking.
}
digitalWrite(powerled1,LOW);
ledbrightness=0;
return;

 

Would this solve your problem?

I'm not sure which delay routines exist in Energia, maybe you should use usleep() delay() delay_cycles() or __delay_cycles()

Link to post
Share on other sites

indeed there is no problem (for me) in the movie i've put. After the second time i have set up the alarm as "ON" (in the settings part) then the buzzer sound is not continous (i will put another video for that as well) the sound is less weak and far from waking me )) (not as in the video above)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...