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