LED lights up gradually

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 :

formatting link

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 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:

formatting link

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!

Reply to
Viet Tran
Loading thread data ...

[ ... ]

I don't know for sure, but should the line

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.

Reply to
Mel Wilson

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.

formatting link

Jon

Reply to
Jon Kirwan

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:

131

Yes, Thank you! It's useful=20

Reply to
Viet Tran

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!

Reply to
Viet Tran

dually, use microprocessor msp430f2131 My circuit: Because I can not up a p icture here, so you can see my circuit here :

formatting link
/?pbrd9452lkoh0b9 My idea to solve: I'll make a pulse, this pulse have widt h increase with time. after use this pulse to control my LED lights up grad ually i'll get pulse at P1.2 My code: #include union reg { s truct { char pin0:1; char pin1:1; char pin2:1; char pin3:1; char pin4:1; ch ar 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 = O UTMOD_7; } #pragma vector= 0x12 __interrupt void timer ( void ) { CCR1+ =1; if(CCR1==5001) CCR1=0; } void main ( void ) { WDTCTL = WDTHOL D + WDTPW; set_clk(); set_led(); set_timer(); set_pwm(); _BIS_SR( GIE ); fo r(;;) {} } Video emulated:

formatting link
ture=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 CCR

0=5000 => it takes 5000*8*10^(-6)=0.04 seconds to have an interrupt o ccurs. on the other hand, i set CCR1 run at 0 to 5001. and my OUTMOD is OUT MOD_7 => it takes 5000*0.04 = 200 seconds to have a cycle of LED so, wh y 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 light s suppling all kinds of led lights including L ED Flood ,led bulbs,LED tube ,led down lights,led ceiling lights,led spotlights,LED lights and so on.For more information,please visit http://www.ztlights. com.

Reply to
bestvickien

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.