Jump to content

Myst3ry

Members
  • Content Count

    17
  • Joined

  • Last visited

  1. I tested it on my LaunchPad by reassigning P1.1 to P1.0 and P2.2 to P1.3 (switch) and it does work as expected. Does the LED turns on the first movement and then stays on or is it always on? P2.2 should be always high except when motion is detected (it is pulled up by internal resistor,) what kind of signal does the sensor output? Is it active high or active low? Initially the LED was turned ON, it stays on, so i went to the osiloscope and check out on the signal on P2.2, it always remained high even when there is no motion detected. The sensor will give a active high when there is movement sensed. Sensor output: http://s1205.photobucket.com/albums/bb4 ... int_00.jpg
  2. Bro RobG, Seems like even if i dun connect the motion sensor to the msp, i stil remain on Even when i connect, it still remain on I guess somewhere in the program has error. as i used a osciloscope to check out the waveform, P2.2 is forever High. Maybe thats the reason why the LED is always ON
  3. @cde MSP430 eZ430-RF2500 @RobG the green led doesnt seem to off my mistake, im using p2.2 , so i edited it appears this way #include "msp430g2231.h" #define DELAY_05s 62500 unsigned char counter = 0; void main(void) { WDTCTL = WDTPW + WDTHOLD; // stop WDT // P2.2 is PIR input P2REN |= 0x04; // enable pull-up P2OUT |= 0x04; // pull-up P2IE |= 0x04; // interrupt enabled P2IES |= 0x04; // hi/lo edge but might be changed depending on your PIR P2IFG &= ~0x04; // IFG cleared P1DIR |= 0x02; // P1.1 is LED TACCR0 = 0; TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK, upmode , /8 TACCTL0 = CCIE; __bis_SR_register(LPM4_bits + GIE); // switch to LPM0 with interrupts } // Timer A interrupt service routine #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { if(counter == 10) { counter = 0; P1OUT &= ~0x02; // LED off __bis_SR_register_on_exit(LPM4_bits); // switch from LPM0 to LPM4 } else { counter++; } } // Port 1 interrupt service routine #pragma vector=PORT2_VECTOR __interrupt void Port_2(void) { P2IFG &= ~0x04; // LED on TACCR0 += DELAY_05s; counter = 0; __bic_SR_register_on_exit(LPM4_bits-LPM0_bits); // switch from LPM4 to LPM0 P1IFG &= ~0x01; // IFG cleared } erm, bro RobG the program is doing just 5 seconds later den off right? if there is motion detected within this 5 sec, will it reset the timer? please advice thanks
  4. Hi bro RogB, i am using P2.5 as the input of the motion sensor so how can i add it into the codes u added? and can i ask, #define DELAY_05s 62500 ---> 62500 is the timing to delay 0.5s? // P1.0 is PIR input --> what is PIR input?
  5. bro RobG adviced me to do this : Start timer for 5sec. Watch for interrupt on port. If there is an interrupt, reset timer or do whatever. When timer expires. Turn off. Go to deep sleep. Another port interrupt can turn on and reset the timer and the cycle continues. But didnt know how
  6. Hi guys, I am encountering some problem with my codes, I connected my motion sensor to the MSP and wants it to work this way: When there is motion detected, the LED will remain ON When there is no motion detected for 5 seconds, LED will turn OFF After the LED is off, if there is motion detected, the LED will light up again and reset the timer. this is my code: #include "msp430.h" int SensorCounter = 0; int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P2DIR |= 0xFB; // Set P2.2 to input direction P4DIR |= 0x20; // P4DIR = P4DIR | 0x20 set P4.5 output TACCTL0 = CCIE; // TACCR0 interrupt enabled TACCR0 = 37500; // set value of compare register to 37500 to achieve 1sec blinking rate TACTL = TASSEL_2 + MC_3 + ID_3; // SMCLK, Up/Down Mode, Divide8 __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt } // Timer A0 interrupt service routine #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { if ( P2IN & 0x04 ) { if ( SensorCounter == 0 ) { P4OUT &= ~0x20; SensorCounter++ ; } else if ( SensorCounter < 6 ) { P4OUT |= 0x20; // P4OUT = P4OUT ^ 0x20 Toggle P4.5 using exclusive-OR SensorCounter++ ; } else if ( SensorCounter > 7 ) { P4OUT &= ~0x20; SensorCounter == 0; } } } Please Advice thanks!
  7. Myst3ry

    timer

    okay maybe i didnt specify properly, how to do the countdown for code?
  8. Myst3ry

    timer

    yes, erm what i meant was. if it didnt detect anything for 30 secs, den it off. its like the 30 seconds delay den off. whats the code of it?
  9. Myst3ry

    timer

    Hi guys, Im a MSP430 newbie, Can i ask, is there any codes that i can do a delay? example if nothing is detected in 30 secs , den the lights will automatically turn off. when there is something detected, it will automatically turn on. Thanks in advance
  10. Thank you ! RobG && simpleavr
  11. im using msp430 ez430-rf2500 @RoBG can i ask if you've set toggle = 0, When it interupts its if( toggle = 1 ) { .... } it has never been 1 , how did it run the toggle = 1? btw thanks for the help!! =D appreciated
  12. i've tried to change it. but it seems that it is only showing 50% on the scope. the requested outcome should be shown on the scope is this :
  13. Thanks guys, btw i got it all wrong program pwm 1khz , 50% , 40% this is what is requested . Any 1 could help?
  14. I've modify it and now i have a problem geting it back to 50% #include "msp430x22x4.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P4DIR |= 0x20; // P4DIR = P4DIR | 0x20 set P4.5 output P4SEL |= 0x20; // P4.5 TBx options TACCTL0 = CCIE; // TACCR0 interrupt enabled TACCR0 = 37500; // set value of compare register to 37500 to achieve 1sec blinking rate TACTL = TASSEL_2 + MC_3 + ID_3 ; // SMCLK, Up/Down Mode for(; { TBCCR0 = 512 - 1; // PWM Period TBCCTL2 = OUTMOD_7; // TBCCR2 reset/set TBCCR2 = 16; // TBCCR2 PWM duty cycle, 2% TBCTL = TBSSEL_2 + MC_1; // SMCLK, up mode __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt } } // Timer A0 interrupt service routine #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { TBCCR0 = 512 - 1; // PWM Period TBCCTL2 = OUTMOD_7; // TBCCR2 reset/set TBCCR2 = 406; // TBCCR2 PWM duty cycle, 2% TBCTL = TBSSEL_2 + MC_1; // SMCLK, up mode }
×
×
  • Create New...