Forums

LED lights up gradually

Started by Viet Tran July 26, 2012
Hi everybody!
I have a project as follow:

  Title:  make a LED lights up gradually, use microprocessor msp430f2131
    My circuit:
    Because I can not up a picture here, so you can see my circuit here :
    http://www.mediafire.com/view/?pbrd9452lkoh0b9

 My idea to solve:
    I'll make a pulse, this pulse have width increase with time. 
    after use this pulse to control my LED lights up gradually
    i'll get pulse at P1.2

 My code:
#include<msp430f2131.h>
union reg
{
  struct 
  {
    char pin0:1;
    char pin1:1;
    char pin2:1;
    char pin3:1;
    char pin4:1;
    char pin5:1;
    char pin6:1;
    char pin7:1;
  } port;
};
union reg* port_direct = ( union reg*)0x22;
union reg* port_sel = ( union reg*)0x26;

void set_clk( void )
{

   DCOCTL = CALDCO_1MHZ;
   BCSCTL1 = CALBC1_1MHZ;
   BCSCTL2 = SELM_0 + DIVM_3;
}

void set_led ( void )
{
  port_direct->port.pin2=1;
  port_sel->port.pin2=1;
}
void set_timer ( void )
{
   CCTL0 = CCIE;
   TACTL = MC_1 + TASSEL_2;
}
void set_pwm ( void )
{
  CCR0 = 5000;
  CCR1=0;
  CCTL1 = OUTMOD_7;
}

#pragma vector= 0x12
__interrupt void timer ( void )
{
  CCR1+=1;
  if(CCR1==5001)
  CCR1=0;
}

void main ( void )
{
  WDTCTL = WDTHOLD + WDTPW;
  set_clk();
  set_led();
  set_timer();
  set_pwm();
  _BIS_SR( GIE );
  for(;;)
  {}
}

 Video emulated:
   http://www.youtube.com/watch?v=Vl2hJyq7xk4&feature=player_embedded

 After emulated a have a question:

 My CLK is SMCLK = 1MHz/8;
   => cycle of pulse: T_clk = 8*10^(-6) seconds
   and i have CCR0=5000 => it takes 5000*8*10^(-6)=0.04 seconds to have an 
   interrupt occurs.                       
   on the other hand, i set CCR1 run at 0 to 5001.
   and my OUTMOD is OUTMOD_7
   => it takes 5000*0.04 = 200 seconds to have a cycle of LED
   so, why in the video emulated, it takes about 25 seconds to have a cycle of   
   LED.

Can you explain to me why?
Thank everybody!









Viet Tran wrote:

> Hi everybody!
[ ... ]
> My CLK is SMCLK = 1MHz/8; > => cycle of pulse: T_clk = 8*10^(-6) seconds > and i have CCR0=5000 => it takes 5000*8*10^(-6)=0.04 seconds to have an > interrupt occurs. > on the other hand, i set CCR1 run at 0 to 5001. > and my OUTMOD is OUTMOD_7 > => it takes 5000*0.04 = 200 seconds to have a cycle of LED > so, why in the video emulated, it takes about 25 seconds to have a > cycle of LED. > > Can you explain to me why? > Thank everybody!
I don't know for sure, but should the line
> BCSCTL1 = CALBC1_1MHZ;
also have a term to set the ACLK divider? Something like BCSCTL1 = CALBC1_1MHZ | DIVA_3; Just a possibility. Clearly a divisor of 8 ought to be set somewhere. Mel.
On Thu, 26 Jul 2012 03:36:19 -0700 (PDT), Viet Tran
<quocviet.dtvt@gmail.com> wrote:

>Hi everybody! >I have a project as follow: > > Title: make a LED lights up gradually, use microprocessor msp430f2131 ><snip>
Already been done (by me) on this processor. I even wrote up a series of tutorials to get you there. The following ZIP file includes a 12-project workspace project for the IAR toolset, plus a PDF file to walk you through it a bit, lots of documentation to read in the source code itself, and all the source code. Project 12 gradually increases the LED brightness and then decreases it, so that it oscillates from very very dim to full brightness with a period on the order of a second or so.. back and forth. http://www.infinitefactors.org/misc/EZLED.ZIP Jon
V=C3=A0o 03:09:48 UTC+8 Th=E1=BB=A9 s=C3=A1u, ng=C3=A0y 27 th=C3=A1ng b=E1=
=BA=A3y n=C4=83m 2012, Jon Kirwan =C4=91=C3=A3 vi=E1=BA=BFt:
> On Thu, 26 Jul 2012 03:36:19 -0700 (PDT), Viet Tran > &lt;quocviet.dtvt@gmail.com&gt; wrote: >=20 > &gt;Hi everybody! > &gt;I have a project as follow: > &gt; > &gt; Title: make a LED lights up gradually, use microprocessor msp430f2=
131
> &gt;&lt;snip&gt; >=20 > Already been done (by me) on this processor. I even wrote up > a series of tutorials to get you there. The following ZIP > file includes a 12-project workspace project for the IAR > toolset, plus a PDF file to walk you through it a bit, lots > of documentation to read in the source code itself, and all > the source code. Project 12 gradually increases the LED > brightness and then decreases it, so that it oscillates from > very very dim to full brightness with a period on the order > of a second or so.. back and forth. >=20 > http://www.infinitefactors.org/misc/EZLED.ZIP >=20 > Jon
Yes, Thank you! It's useful=20
> I don&#39;t know for sure, but should the line > &gt; BCSCTL1 = CALBC1_1MHZ; > also have a term to set the ACLK divider? Something like > BCSCTL1 = CALBC1_1MHZ | DIVA_3; > > Just a possibility. Clearly a divisor of 8 ought to be set somewhere. > > Mel.
Let see the subroutine: void set_led ( void ) { port_direct->port.pin2=1; port_sel->port.pin2=1; } Clearly, i chose p2.2 to get PWM. but when see the video emulated we can see that: both p2.2 and p2.6 can get pulse so, can you explain to me why? Thank you!
On Thursday, July 26, 2012 6:36:19 PM UTC+8, Viet Tran wrote:
> Hi everybody! I have a project as follow: Title: make a LED lights up gradually, use microprocessor msp430f2131 My circuit: Because I can not up a picture here, so you can see my circuit here : http://www.mediafire.com/view/?pbrd9452lkoh0b9 My idea to solve: I'll make a pulse, this pulse have width increase with time. after use this pulse to control my LED lights up gradually i'll get pulse at P1.2 My code: #include<msp430f2131.h> union reg { struct { char pin0:1; char pin1:1; char pin2:1; char pin3:1; char pin4:1; char pin5:1; char pin6:1; char pin7:1; } port; }; union reg* port_direct = ( union reg*)0x22; union reg* port_sel = ( union reg*)0x26; void set_clk( void ) { DCOCTL = CALDCO_1MHZ; BCSCTL1 = CALBC1_1MHZ; BCSCTL2 = SELM_0 + DIVM_3; } void set_led ( void ) { port_direct->port.pin2=1; port_sel->port.pin2=1; } void set_timer ( void ) { CCTL0 = CCIE; TACTL = MC_1 + TASSEL_2; } void set_pwm ( void ) { CCR0 = 5000; CCR1=0; CCTL1 = OUTMOD_7; } #pragma vector= 0x12 __interrupt void timer ( void ) { CCR1+=1; if(CCR1==5001) CCR1=0; } void main ( void ) { WDTCTL = WDTHOLD + WDTPW; set_clk(); set_led(); set_timer(); set_pwm(); _BIS_SR( GIE ); for(;;) {} } Video emulated: http://www.youtube.com/watch?v=Vl2hJyq7xk4&feature=player_embedded After emulated a have a question: My CLK is SMCLK = 1MHz/8; => cycle of pulse: T_clk = 8*10^(-6) seconds and i have CCR0=5000 => it takes 5000*8*10^(-6)=0.04 seconds to have an interrupt occurs. on the other hand, i set CCR1 run at 0 to 5001. and my OUTMOD is OUTMOD_7 => it takes 5000*0.04 = 200 seconds to have a cycle of LED so, why in the video emulated, it takes about 25 seconds to have a cycle of LED. Can you explain to me why? Thank everybody!
Zhongtian Lighting is a professional manufacturer and supplier of led lights suppling all kinds of led lights including <a href="www.ztlights.com">LED Flood</a> ,led bulbs,<a href="www.ztlights.com">LED tube</a> ,led down lights,led ceiling lights,led spotlights,<a href="www.ztlights.com">LED lights</a> and so on.For more information,please visit http://www.ztlights.com.