X-Git-Url: http://www.average.org/gitweb/?p=sensor-light.git;a=blobdiff_plain;f=msp430%2Fmain.c;h=53ee457adf1da057d276a1f2bf221a9700be1a14;hp=6b075ad91d6b9753f86cb258216d88227842d174;hb=HEAD;hpb=68eddb43a02efafa7d42778a58659313199c8228 diff --git a/msp430/main.c b/msp430/main.c index 6b075ad..53ee457 100644 --- a/msp430/main.c +++ b/msp430/main.c @@ -6,8 +6,8 @@ enum {ev_btn1 = 0, ev_btn2, ev_pir1, ev_pir2, ev_tmr, ev_adc, ev_MAX}; #define PWM_ORDER 10 #define PWM_HALF 5 -#define LIGHT_THRESHOLD 600 -#define TIME_ON 16 +#define LIGHT_THRESHOLD 900 +#define TIME_ON 320 #ifdef ADCSC /* Let us hope that this is a "new" model */ # define BIT_RL BIT0 @@ -36,8 +36,7 @@ int main(void) { int Duty_Cycle = 0; int Increment = 1; - unsigned int Time_Count = 0; - unsigned int Time_Left = 5; + unsigned int Time_Left = 50; unsigned int Time_Indicate = 2; WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer @@ -59,7 +58,7 @@ int main(void) P2DIR &= ~(BIT4|BIT5); // PIR Sensors P2OUT &= ~(BIT4|BIT5); // Pull down - P2REN |= BIT4|BIT5; // Enable pull-down + P2REN &= ~(BIT4|BIT5); // Disable pull P2IES &= ~(BIT4|BIT5); // INT on Lo->Hi edge P2IE |= BIT4|BIT5; // INT enable @@ -161,12 +160,11 @@ int main(void) if (!Time_Indicate) P1OUT &= ~(BIT_RL|BIT_GL); // LEDs off } - if (Time_Count++ > 10) { - Time_Count = 0; - if (Time_Left) - Time_Left--; - else if (Duty_Cycle > 1) - Increment = -1; + if (Time_Left) { + Time_Left--; + if (!Time_Left) + if (Duty_Cycle) + Increment = -1; } if (Increment > 0) { if (++Duty_Cycle >= (PWM_ORDER<<1)) { @@ -178,7 +176,7 @@ int main(void) Duty_Cycle = 0; Increment = 0; } - } else + } else // Increment _was_ zero - no change! continue; TA0CCR2 = expon2(Duty_Cycle);